DSR and CTS callbacks are executed on the beginning to know the status of the line

pull/30/head
Felipe Herranz 2016-02-13 18:24:56 +01:00
rodzic 7a8794430e
commit 9d2562d8da
2 zmienionych plików z 41 dodań i 19 usunięć

Wyświetl plik

@ -391,11 +391,14 @@ public class CP2102SerialDevice extends UsbSerialDevice
{ {
private long time = 40; // 40ms private long time = 40; // 40ms
private boolean firstTime;
private AtomicBoolean keep; private AtomicBoolean keep;
public FlowControlThread() public FlowControlThread()
{ {
keep = new AtomicBoolean(true); keep = new AtomicBoolean(true);
firstTime = true;
} }
@Override @Override
@ -403,28 +406,40 @@ public class CP2102SerialDevice extends UsbSerialDevice
{ {
while(keep.get()) while(keep.get())
{ {
byte[] modemState = pollLines(); if(!firstTime) // Only execute the callback when the status change
// Check CTS status
if(rtsCtsEnabled)
{ {
if(ctsState != ((modemState[0] & 0x10) == 0x10)) byte[] modemState = pollLines();
{
ctsState = !ctsState;
if(ctsCallback != null)
ctsCallback.onCTSChanged(ctsState);
}
}
// Check DSR status // Check CTS status
if(dtrDsrEnabled) if(rtsCtsEnabled)
{
if(dsrState != ((modemState[0] & 0x20) == 0x20))
{ {
dsrState = !dsrState; if(ctsState != ((modemState[0] & 0x10) == 0x10))
if(dsrCallback != null) {
dsrCallback.onDSRChanged(dsrState); ctsState = !ctsState;
if (ctsCallback != null)
ctsCallback.onCTSChanged(ctsState);
}
} }
// Check DSR status
if(dtrDsrEnabled)
{
if(dsrState != ((modemState[0] & 0x20) == 0x20))
{
dsrState = !dsrState;
if (dsrCallback != null)
dsrCallback.onDSRChanged(dsrState);
}
}
}else // Execute the callback always the first time
{
if(rtsCtsEnabled && ctsCallback != null)
ctsCallback.onCTSChanged(ctsState);
if(dtrDsrEnabled && dsrCallback != null)
dsrCallback.onDSRChanged(dsrState);
firstTime = false;
} }
} }
} }

Wyświetl plik

@ -471,10 +471,17 @@ public class FTDISerialDevice extends UsbSerialDevice
boolean cts = (data[0] & 0x10) == 0x10; boolean cts = (data[0] & 0x10) == 0x10;
boolean dsr = (data[0] & 0x20) == 0x20; boolean dsr = (data[0] & 0x20) == 0x20;
if(firstTime) // First modem status received, set the flags and exit if(firstTime) // First modem status received
{ {
ctsState = cts; ctsState = cts;
dsrState = dsr; dsrState = dsr;
if(rtsCtsEnabled && ctsCallback != null)
ctsCallback.onCTSChanged(ctsState);
if(dtrDsrEnabled && dsrCallback != null)
dsrCallback.onDSRChanged(dsrState);
firstTime = false; firstTime = false;
return; return;
} }