There may be several errors in this code.
First, the error log does not seem to match the code: from the error log, PCMC.java:189 should be a send () call, but instead it looks empty. Is the code that you sent exactly the code that you ran to cause the error?
Having guessed the version of this code that caused the error, I think that the problem may have been related to the return to inputstream.read (). If the PCMC constructor registered through serialPort.addEventListener (this), then the following sequence may occur:
- The main PCMC.send () calls that write the message are then blocked in send inputstream.read ().
- Serial input available. RXTX wants to call PCMC.serialEvent (), but it is blocked in inputstream.read (). Bad things happen.
To successfully use RXTX, the code must either do I / O inside serialEvent (), or not be a listener, but perform normal blocking I / O. If you try to read the serial port both in its main sequence and inside serialEvent (), RXTX will most likely break.
The third thing I noticed: one version of the code that you posted may have tried to close the serial port without first registering as a listener. If you call addEventListener (), you must unregister this listener before calling the close () function on the port.
Again, all my notes are speculations about the version of your code that actually created the error log in the message. In the future, be sure to submit the same version of the code that caused the error. I apologize if I mistakenly thought that the code did not match the error log - and good luck!
source share