Skip to content

Commit bbcb586

Browse files
Copilotjyong15
andcommitted
Fix race condition: move eventDeviceConnected after serial port reader setup
Co-authored-by: jyong15 <26561407+jyong15@users.noreply.github.com>
1 parent ae3aefc commit bbcb586

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

ShimmerDriverPC/src/main/java/com/shimmerresearch/pcSerialPort/SerialPortCommJssc.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public void connect() throws ShimmerException {
9090
// true,
9191
// false);//Set params.
9292
mSerialPort.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);
93-
eventDeviceConnected();
93+
// Don't call eventDeviceConnected() yet - wait until serial port reader is set up
9494
}
9595
catch (SerialPortException e) {
9696
eventDeviceDisconnected();
@@ -106,6 +106,10 @@ public void connect() throws ShimmerException {
106106
}
107107

108108
startSerialPortReader();
109+
110+
// Fire connected event only after serial port reader is fully set up
111+
// This prevents race conditions where callbacks try to read before setup is complete
112+
eventDeviceConnected();
109113

110114
}
111115

0 commit comments

Comments
 (0)