i have a java application and i am developing a scenario if my application would work if my weighing scale is off. But when i turned off my weighing scale my JFrame freezes is there a code for this error? here is the code the System freezes on line 4.
serialPort.openPort();//Open serial port
serialPort.setParams(9600, 8, 1, 0);//Set params.
serialPort.writeBytes("R".getBytes());
String a = serialPort.readString(13).trim();
Well, it looks like you're doing this in the UI thread. You should basically avoid doing I/O in the UI thread, as it means that while the I/O is waiting, your UI will be unresponsive.
Instead, you should either use asynchronous I/O, or perform all the I/O in a separate thread, but remember to marshal any results back to the UI thread, as you shouldn't perform any UI work not on the UI thread. See the Swing concurrency tutorial for more details.
As an aside, I'd strongly recommend against calling getBytes()
without specifying an encoding - you really don't want to use the platform encoding. (In this case, I suspect you know the single byte you want to write, so I'd write that directly...)
See more on this question at Stackoverflow