Add calls to fetch modem line status
This commit is contained in:
parent
c75e8d731b
commit
12855926d9
|
@ -575,4 +575,20 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_clearDTR(JNI
|
||||||
return (ioctl(serialPortFD, TIOCMBIC, &modemBits) == 0);
|
return (ioctl(serialPortFD, TIOCMBIC, &modemBits) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_getCTS(JNIEnv *env, jobject obj, jlong serialPortFD)
|
||||||
|
{
|
||||||
|
if (serialPortFD <= 0)
|
||||||
|
return JNI_FALSE;
|
||||||
|
int modemBits = 0;
|
||||||
|
return (ioctl(serialPortFD, TIOCMGET, &modemBits) == 0) && (modemBits & TIOCM_CTS);
|
||||||
|
}
|
||||||
|
|
||||||
|
JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_getDSR(JNIEnv *env, jobject obj, jlong serialPortFD)
|
||||||
|
{
|
||||||
|
if (serialPortFD <= 0)
|
||||||
|
return JNI_FALSE;
|
||||||
|
int modemBits = 0;
|
||||||
|
return (ioctl(serialPortFD, TIOCMGET, &modemBits) == 0) && (modemBits & TIOCM_LE);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -534,4 +534,20 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_clearDTR(JNI
|
||||||
return (ioctl(serialPortFD, TIOCMBIC, &modemBits) == 0);
|
return (ioctl(serialPortFD, TIOCMBIC, &modemBits) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_getCTS(JNIEnv *env, jobject obj, jlong serialPortFD)
|
||||||
|
{
|
||||||
|
if (serialPortFD <= 0)
|
||||||
|
return JNI_FALSE;
|
||||||
|
int modemBits = 0;
|
||||||
|
return (ioctl(serialPortFD, TIOCMGET, &modemBits) == 0) && (modemBits & TIOCM_CTS);
|
||||||
|
}
|
||||||
|
|
||||||
|
JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_getDSR(JNIEnv *env, jobject obj, jlong serialPortFD)
|
||||||
|
{
|
||||||
|
if (serialPortFD <= 0)
|
||||||
|
return JNI_FALSE;
|
||||||
|
int modemBits = 0;
|
||||||
|
return (ioctl(serialPortFD, TIOCMGET, &modemBits) == 0) && (modemBits & TIOCM_LE);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -553,4 +553,20 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_clearDTR(JNI
|
||||||
return (ioctl(serialPortFD, TIOCMBIC, &modemBits) == 0);
|
return (ioctl(serialPortFD, TIOCMBIC, &modemBits) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_getCTS(JNIEnv *env, jobject obj, jlong serialPortFD)
|
||||||
|
{
|
||||||
|
if (serialPortFD <= 0)
|
||||||
|
return JNI_FALSE;
|
||||||
|
int modemBits = 0;
|
||||||
|
return (ioctl(serialPortFD, TIOCMGET, &modemBits) == 0) && (modemBits & TIOCM_CTS);
|
||||||
|
}
|
||||||
|
|
||||||
|
JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_getDSR(JNIEnv *env, jobject obj, jlong serialPortFD)
|
||||||
|
{
|
||||||
|
if (serialPortFD <= 0)
|
||||||
|
return JNI_FALSE;
|
||||||
|
int modemBits = 0;
|
||||||
|
return (ioctl(serialPortFD, TIOCMGET, &modemBits) == 0) && (modemBits & TIOCM_LE);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -682,4 +682,22 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_clearDTR(JNI
|
||||||
return EscapeCommFunction(serialPortHandle, CLRDTR);
|
return EscapeCommFunction(serialPortHandle, CLRDTR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_getCTS(JNIEnv *env, jobject obj, jlong serialPortFD)
|
||||||
|
{
|
||||||
|
HANDLE serialPortHandle = (HANDLE)serialPortFD;
|
||||||
|
if (serialPortHandle == INVALID_HANDLE_VALUE)
|
||||||
|
return JNI_FALSE;
|
||||||
|
DWORD modemStatus = 0;
|
||||||
|
return GetCommModemStatus(serialPortHandle, &modemStatus) && (modemStatus & MS_CTS_ON);
|
||||||
|
}
|
||||||
|
|
||||||
|
JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_getDSR(JNIEnv *env, jobject obj, jlong serialPortFD)
|
||||||
|
{
|
||||||
|
HANDLE serialPortHandle = (HANDLE)serialPortFD;
|
||||||
|
if (serialPortHandle == INVALID_HANDLE_VALUE)
|
||||||
|
return JNI_FALSE;
|
||||||
|
DWORD modemStatus = 0;
|
||||||
|
return GetCommModemStatus(serialPortHandle, &modemStatus) && (modemStatus & MS_DSR_ON);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -456,6 +456,8 @@ public final class SerialPort
|
||||||
private final native boolean clearRTS(long portHandle); // Clear RTS line to 0
|
private final native boolean clearRTS(long portHandle); // Clear RTS line to 0
|
||||||
private final native boolean setDTR(long portHandle); // Set DTR line to 1
|
private final native boolean setDTR(long portHandle); // Set DTR line to 1
|
||||||
private final native boolean clearDTR(long portHandle); // Clear DTR line to 0
|
private final native boolean clearDTR(long portHandle); // Clear DTR line to 0
|
||||||
|
private final native boolean getCTS(long portHandle); // Returns whether the CTS signal is 1
|
||||||
|
private final native boolean getDSR(long portHandle); // Returns whether the DSR signal is 1
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of bytes available without blocking if {@link #readBytes} were to be called immediately
|
* Returns the number of bytes available without blocking if {@link #readBytes} were to be called immediately
|
||||||
|
@ -540,6 +542,16 @@ public final class SerialPort
|
||||||
*/
|
*/
|
||||||
public final boolean clearDTR() { return clearDTR(portHandle); }
|
public final boolean clearDTR() { return clearDTR(portHandle); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Whether or not the CTS line is asserted.
|
||||||
|
*/
|
||||||
|
public final boolean getCTS() { return getCTS(portHandle); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Whether or not the DSR line is asserted.
|
||||||
|
*/
|
||||||
|
public final boolean getDSR() { return getDSR(portHandle); }
|
||||||
|
|
||||||
// Default Constructor
|
// Default Constructor
|
||||||
private SerialPort() {}
|
private SerialPort() {}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue