Closed benayat closed 1 year ago
From the javadoc of SerialPort#addDataListener
:
Only one listener can be registered at a time; however, that listener can be used to detect multiple types of serial port events.
@return Whether the listener was successfully registered with the serial port.
I guess your second addDataListener()
call returned false
.
@benayat, @NorbertSandor is correct. The library only allows one listener to be registered at a time. It is up to the user to decide how to handle specific events that their listener is registered for. In the case of registering for a fixed packet size, there is really no way (even under the hood) to allow for multiple events/sizes to be registered. The library knows nothing about the data you are expecting, only that it has received a certain number of bytes, so it has no way of deciding which among a number of different listeners should be called for a given packet size. You will need to handle this differentiation within your own code. Let me know if you have any more questions.
Closing as "will not fix".
I want to add two data listeners with fixed packet size(one for each command input, of type SerialPortPacketListener) to my SerialPort object, but only the first one is working. anything other than that doesn't work. is it intentional behavior and I'm missing something? or just a feature not yet implemented?