Merge pull request #62 from Awarepoint/break
Add support for set/clear BREAK/RTS/DTR signals in Windows.
This commit is contained in:
commit
b55107047a
|
@ -629,4 +629,52 @@ JNIEXPORT jint JNICALL Java_com_fazecast_jSerialComm_SerialPort_writeBytes(JNIEn
|
|||
return (result == TRUE) ? numBytesWritten : -1;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_com_fazecast_jSerialComm_SerialPort_setBreak(JNIEnv *env, jobject obj, jlong serialPortFD)
|
||||
{
|
||||
HANDLE serialPortHandle = (HANDLE)serialPortFD;
|
||||
if (serialPortHandle == INVALID_HANDLE_VALUE)
|
||||
return;
|
||||
SetCommBreak(serialPortHandle);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_com_fazecast_jSerialComm_SerialPort_clearBreak(JNIEnv *env, jobject obj, jlong serialPortFD)
|
||||
{
|
||||
HANDLE serialPortHandle = (HANDLE)serialPortFD;
|
||||
if (serialPortHandle == INVALID_HANDLE_VALUE)
|
||||
return;
|
||||
ClearCommBreak(serialPortHandle);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_com_fazecast_jSerialComm_SerialPort_setRTS(JNIEnv *env, jobject obj, jlong serialPortFD)
|
||||
{
|
||||
HANDLE serialPortHandle = (HANDLE)serialPortFD;
|
||||
if (serialPortHandle == INVALID_HANDLE_VALUE)
|
||||
return;
|
||||
EscapeCommFunction(serialPortHandle, SETRTS);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_com_fazecast_jSerialComm_SerialPort_clearRTS(JNIEnv *env, jobject obj, jlong serialPortFD)
|
||||
{
|
||||
HANDLE serialPortHandle = (HANDLE)serialPortFD;
|
||||
if (serialPortHandle == INVALID_HANDLE_VALUE)
|
||||
return;
|
||||
EscapeCommFunction(serialPortHandle, CLRRTS);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_com_fazecast_jSerialComm_SerialPort_setDTR(JNIEnv *env, jobject obj, jlong serialPortFD)
|
||||
{
|
||||
HANDLE serialPortHandle = (HANDLE)serialPortFD;
|
||||
if (serialPortHandle == INVALID_HANDLE_VALUE)
|
||||
return;
|
||||
EscapeCommFunction(serialPortHandle, SETDTR);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_com_fazecast_jSerialComm_SerialPort_clearDTR(JNIEnv *env, jobject obj, jlong serialPortFD)
|
||||
{
|
||||
HANDLE serialPortHandle = (HANDLE)serialPortFD;
|
||||
if (serialPortHandle == INVALID_HANDLE_VALUE)
|
||||
return;
|
||||
EscapeCommFunction(serialPortHandle, CLRDTR);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -448,6 +448,12 @@ public final class SerialPort
|
|||
private final native int bytesAwaitingWrite(long portHandle); // Returns number of bytes still waiting to be written
|
||||
private final native int readBytes(long portHandle, byte[] buffer, long bytesToRead); // Reads bytes from serial port
|
||||
private final native int writeBytes(long portHandle, byte[] buffer, long bytesToWrite); // Write bytes to serial port
|
||||
private final native void setBreak(long portHandle);
|
||||
private final native void clearBreak(long portHandle);
|
||||
private final native void setRTS(long portHandle);
|
||||
private final native void clearRTS(long portHandle);
|
||||
private final native void setDTR(long portHandle);
|
||||
private final native void clearDTR(long portHandle);
|
||||
|
||||
/**
|
||||
* Returns the number of bytes available without blocking if {@link #readBytes} were to be called immediately
|
||||
|
@ -496,6 +502,15 @@ public final class SerialPort
|
|||
*/
|
||||
public final int writeBytes(byte[] buffer, long bytesToWrite) { return writeBytes(portHandle, buffer, bytesToWrite); }
|
||||
|
||||
public final void setBreak() { setBreak(portHandle); }
|
||||
public final void clearBreak() { clearBreak(portHandle); }
|
||||
|
||||
public final void setRTS() { setRTS(portHandle); }
|
||||
public final void clearRTS() { clearRTS(portHandle); }
|
||||
|
||||
public final void setDTR() { setDTR(portHandle); }
|
||||
public final void clearDTR() { clearDTR(portHandle); }
|
||||
|
||||
// Default Constructor
|
||||
private SerialPort() {}
|
||||
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue