I'm using jssc library for communicating with device over serial port. In standard java SerialComm library there are two methods getInputStream() and getOutputStream().
Why I need this? I want to implement Xmodem according to this example and xmodem constructor requires two params:
public Xmodem(InputStream inputStream, OutputStream outputStream)
{
this.inputStream = inputStream;
this.outputStream = outputStream;
}
Xmodem xmodem = new Xmodem(serialPort.getInputStream(),serialPort.getOutputStream());
In jssc there are are no such methods but I'm wondering is there some alternative way?
One possibility is to provide a custom
PortInputStreamclass that extendsInputStreamand implements JSSCsSerialPortEventListenerinterface. This class receives data from the serial port and stores it in a buffer. It also provides aread()method to get the data from the buffer.Similarly, you can provide a custom
PortOutputStreamclass which extendsOutputStreamand writes to the serial interface:Before you instantiate your
Xmodemobject, you have to create both streams: