Disable event-based line status changes on OSs for which it is unavailable
This commit is contained in:
parent
144c9928cd
commit
7778b924e5
|
@ -61,7 +61,9 @@ serialPort* pushBack(serialPortVector* vector, const char* key, const char* frie
|
|||
pthread_mutex_init(&port->eventMutex, NULL);
|
||||
pthread_condattr_t conditionVariableAttributes;
|
||||
pthread_condattr_init(&conditionVariableAttributes);
|
||||
#if !defined(__APPLE__)
|
||||
pthread_condattr_setclock(&conditionVariableAttributes, CLOCK_MONOTONIC);
|
||||
#endif
|
||||
pthread_cond_init(&port->eventReceived, &conditionVariableAttributes);
|
||||
pthread_condattr_destroy(&conditionVariableAttributes);
|
||||
|
||||
|
|
|
@ -79,6 +79,8 @@ jfieldID eventFlagsField;
|
|||
// List of available serial ports
|
||||
serialPortVector serialPorts = { NULL, 0, 0 };
|
||||
|
||||
#if defined(__linux__) && !defined(__ANDROID__)
|
||||
|
||||
// Event listening threads
|
||||
void* eventReadingThread1(void *serialPortPointer)
|
||||
{
|
||||
|
@ -180,6 +182,8 @@ void* eventReadingThread2(void *serialPortPointer)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
#endif // #if defined(__linux__)
|
||||
|
||||
JNIEXPORT jobjectArray JNICALL Java_com_fazecast_jSerialComm_SerialPort_getCommPorts(JNIEnv *env, jclass serialComm)
|
||||
{
|
||||
// Reset the enumerated flag on all non-open serial ports
|
||||
|
@ -605,10 +609,12 @@ JNIEXPORT jint JNICALL Java_com_fazecast_jSerialComm_SerialPort_waitForEvent(JNI
|
|||
{
|
||||
// Initialize the local variables
|
||||
int pollResult;
|
||||
struct serial_icounter_struct oldSerialLineInterrupts, newSerialLineInterrupts;
|
||||
short pollEventsMask = ((port->eventsMask & com_fazecast_jSerialComm_SerialPort_LISTENING_EVENT_DATA_AVAILABLE) || (port->eventsMask & com_fazecast_jSerialComm_SerialPort_LISTENING_EVENT_DATA_RECEIVED)) ? (POLLIN | POLLERR) : POLLERR;
|
||||
struct pollfd waitingSet = { port->handle, pollEventsMask, 0 };
|
||||
#if defined(__linux__)
|
||||
struct serial_icounter_struct oldSerialLineInterrupts, newSerialLineInterrupts;
|
||||
ioctl(port->handle, TIOCGICOUNT, &oldSerialLineInterrupts);
|
||||
#endif // #if defined(__linux__)
|
||||
|
||||
// Wait for a serial port event
|
||||
do
|
||||
|
@ -621,6 +627,7 @@ JNIEXPORT jint JNICALL Java_com_fazecast_jSerialComm_SerialPort_waitForEvent(JNI
|
|||
// Return the detected port events
|
||||
if (waitingSet.revents & POLLIN)
|
||||
event |= com_fazecast_jSerialComm_SerialPort_LISTENING_EVENT_DATA_AVAILABLE;
|
||||
#if defined(__linux__)
|
||||
if (waitingSet.revents & POLLERR)
|
||||
if (!ioctl(port->handle, TIOCGICOUNT, &newSerialLineInterrupts))
|
||||
{
|
||||
|
@ -635,6 +642,7 @@ JNIEXPORT jint JNICALL Java_com_fazecast_jSerialComm_SerialPort_waitForEvent(JNI
|
|||
if (oldSerialLineInterrupts.buf_overrun != newSerialLineInterrupts.buf_overrun)
|
||||
event |= com_fazecast_jSerialComm_SerialPort_LISTENING_EVENT_SOFTWARE_OVERRUN_ERROR;
|
||||
}
|
||||
#endif // #if defined(__linux__)
|
||||
}
|
||||
return event;
|
||||
}
|
||||
|
@ -790,6 +798,7 @@ JNIEXPORT void JNICALL Java_com_fazecast_jSerialComm_SerialPort_setEventListenin
|
|||
// Create or cancel a separate event listening thread if required
|
||||
serialPort *port = (serialPort*)(intptr_t)serialPortPointer;
|
||||
port->eventListenerRunning = eventListenerRunning;
|
||||
#if defined(__linux__) && !defined(__ANDROID__)
|
||||
if (eventListenerRunning && ((port->eventsMask & com_fazecast_jSerialComm_SerialPort_LISTENING_EVENT_CARRIER_DETECT) || (port->eventsMask & com_fazecast_jSerialComm_SerialPort_LISTENING_EVENT_CTS) ||
|
||||
(port->eventsMask & com_fazecast_jSerialComm_SerialPort_LISTENING_EVENT_DSR) || (port->eventsMask & com_fazecast_jSerialComm_SerialPort_LISTENING_EVENT_RING_INDICATOR)))
|
||||
{
|
||||
|
@ -818,6 +827,7 @@ JNIEXPORT void JNICALL Java_com_fazecast_jSerialComm_SerialPort_setEventListenin
|
|||
pthread_cancel(port->eventsThread2);
|
||||
port->eventsThread2 = 0;
|
||||
}
|
||||
#endif // #if defined(__linux__)
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_setBreak(JNIEnv *env, jobject obj, jlong serialPortPointer)
|
||||
|
|
Loading…
Reference in New Issue