serial thread name hack
This commit is contained in:
parent
173a9e85db
commit
4de8e682a6
|
@ -39,6 +39,8 @@ public class SerialIoStreamJSerialComm extends AbstractIoStream {
|
||||||
@Override
|
@Override
|
||||||
public void setInputListener(DataListener listener) {
|
public void setInputListener(DataListener listener) {
|
||||||
sp.addDataListener(new SerialPortDataListener() {
|
sp.addDataListener(new SerialPortDataListener() {
|
||||||
|
private boolean isFirstEvent = true;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getListeningEvents() {
|
public int getListeningEvents() {
|
||||||
return SerialPort.LISTENING_EVENT_DATA_AVAILABLE;
|
return SerialPort.LISTENING_EVENT_DATA_AVAILABLE;
|
||||||
|
@ -48,6 +50,11 @@ public class SerialIoStreamJSerialComm extends AbstractIoStream {
|
||||||
public void serialEvent(SerialPortEvent event) {
|
public void serialEvent(SerialPortEvent event) {
|
||||||
if (event.getEventType() != SerialPort.LISTENING_EVENT_DATA_AVAILABLE)
|
if (event.getEventType() != SerialPort.LISTENING_EVENT_DATA_AVAILABLE)
|
||||||
return;
|
return;
|
||||||
|
if (isFirstEvent) {
|
||||||
|
// a hack to have explicit thread name, see https://github.com/Fazecast/jSerialComm/issues/308
|
||||||
|
Thread.currentThread().setName("Serial Port Event Thread");
|
||||||
|
isFirstEvent = false;
|
||||||
|
}
|
||||||
int bytesAvailable = sp.bytesAvailable();
|
int bytesAvailable = sp.bytesAvailable();
|
||||||
if (bytesAvailable <= 0)
|
if (bytesAvailable <= 0)
|
||||||
return; // sometimes negative value is returned at least on Mac
|
return; // sometimes negative value is returned at least on Mac
|
||||||
|
|
Loading…
Reference in New Issue