You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(See also discussion in #90)
(Is similar to #95)
(Maybe relates to #89)
Expected behavior
To be discussed what the correct behavior is in this scenario. We should
somehow communicate that we reached EOF or somehow communicate the actual error
which happened.
Maybe return some (eg negative) error codes which then gets translated to an
exception in SerialPort wrapper or similar?
How to reproduce
(HINT: In this example I interact with SerialNativeInterface class directly.
But the behavior IMHO should be the same when used via SerialPort wrapper)
Setup a java class as shown in example below
Plug in our device. (I used an arduino via USB)
Launch reproducer
Send some example data from device to make sure everything works
(I wrote a primitive program on arduino so I can send a few bytes by pushing a button)
(HINT: This step is optional. It's just to verify that we connected successfully)
Take a look at CPU usage by java process. Up to now everything should be fine.
Pull plug of the device (in my case the USB cable of arduino)
Now look again at the CPU usage of our process. In my case its near 100% infinitely looping in native _readBytes() as we ignore everyting which is not the regular case from 'select', 'poll' and 'read' (Eg EOF or any other errors). See return of select ignored and error and EOF of read ignored.
Reproducer:
importjssc.SerialNativeInterface;
classInfiniteLoopOnEofInReadBytes
{
privatestaticfinalStringportName = "/dev/ttyACM0";
privatestaticfinalintbaudr = 9600;
privatestaticfinalbooleandoExclusiveLock = false;
privatelongfd;
publicstaticvoidmain( String[] args ) {
newInfiniteLoopOnEofInReadBytes().reproduce();
}
privatevoidreproduce()
{
// SetupSerialNativeInterfaceserialNativeInterface = newSerialNativeInterface();
fd = serialNativeInterface.openPort( portName, doExclusiveLock );
if( fd<0 ) thrownewIllegalStateException( "openPort( "+ portName +" ) failed with code "+ fd +". Is the device plugged in?");
serialNativeInterface.setParams( fd, baudr, 8, 1, 0, true, true, 0 );
while(true){
// Read a few bytes.// As soon we pull the plug, this method never returns and hangs in an// infinite-loop internally (HINT: Don't confuse this with our outer loop here).System.out.println( "readBytes( fd, 4 )" );
byte[] bytes = serialNativeInterface.readBytes( fd, 4 );
// Log them.System.out.print( "Got "+ bytes.length +" bytes:" );
for( byteb : bytes ){
System.out.print( String.format(" 0x%02X", b) );
}
System.out.print("\n");
}
}
}
The text was updated successfully, but these errors were encountered:
Actual Behavior
Jssc ends up in an infinite-loop when device plug gets pulled.
Affected method (source):
Tested with v2.9.2.
(See also discussion in #90)
(Is similar to #95)
(Maybe relates to #89)
Expected behavior
To be discussed what the correct behavior is in this scenario. We should
somehow communicate that we reached EOF or somehow communicate the actual error
which happened.
Maybe return some (eg negative) error codes which then gets translated to an
exception in SerialPort wrapper or similar?
How to reproduce
(HINT: In this example I interact with SerialNativeInterface class directly.
But the behavior IMHO should be the same when used via SerialPort wrapper)
(I wrote a primitive program on arduino so I can send a few bytes by pushing a button)
(HINT: This step is optional. It's just to verify that we connected successfully)
Reproducer:
The text was updated successfully, but these errors were encountered: