Make LISTENING_EVENT_PORT_DISCONNECTED functional

This commit is contained in:
Will Hedgecock 2022-01-04 22:43:29 -06:00
parent 541b76d864
commit 7e22a15abe
32 changed files with 16 additions and 6 deletions

View File

@ -158,7 +158,9 @@ void* eventReadingThread2(void *serialPortPointer)
// Return the detected port events
pthread_mutex_lock(&port->eventMutex);
if (waitingSet.revents & POLLIN)
if (waitingSet.revents & POLLHUP)
port->event |= com_fazecast_jSerialComm_SerialPort_LISTENING_EVENT_PORT_DISCONNECTED;
else if (waitingSet.revents & POLLIN)
port->event |= com_fazecast_jSerialComm_SerialPort_LISTENING_EVENT_DATA_AVAILABLE;
if (waitingSet.revents & POLLERR)
if (!ioctl(port->handle, TIOCGICOUNT, &newSerialLineInterrupts))
@ -625,7 +627,9 @@ JNIEXPORT jint JNICALL Java_com_fazecast_jSerialComm_SerialPort_waitForEvent(JNI
while ((pollResult == 0) && port->eventListenerRunning);
// Return the detected port events
if (waitingSet.revents & POLLIN)
if (waitingSet.revents & POLLHUP)
event |= com_fazecast_jSerialComm_SerialPort_LISTENING_EVENT_PORT_DISCONNECTED;
else if (waitingSet.revents & POLLIN)
event |= com_fazecast_jSerialComm_SerialPort_LISTENING_EVENT_DATA_AVAILABLE;
#if defined(__linux__)
if (waitingSet.revents & POLLERR)

View File

@ -73,6 +73,8 @@ extern "C" {
#define com_fazecast_jSerialComm_SerialPort_LISTENING_EVENT_SOFTWARE_OVERRUN_ERROR 8388608L
#undef com_fazecast_jSerialComm_SerialPort_LISTENING_EVENT_PARITY_ERROR
#define com_fazecast_jSerialComm_SerialPort_LISTENING_EVENT_PARITY_ERROR 16777216L
#undef com_fazecast_jSerialComm_SerialPort_LISTENING_EVENT_PORT_DISCONNECTED
#define com_fazecast_jSerialComm_SerialPort_LISTENING_EVENT_PORT_DISCONNECTED 268435456L
/*
* Class: com_fazecast_jSerialComm_SerialPort
* Method: getCommPorts

View File

@ -2,10 +2,10 @@
* SerialPort_Windows.c
*
* Created on: Feb 25, 2012
* Last Updated on: Dec 17, 2021
* Last Updated on: Jan 04, 2022
* Author: Will Hedgecock
*
* Copyright (C) 2012-2021 Fazecast, Inc.
* Copyright (C) 2012-2022 Fazecast, Inc.
*
* This file is part of jSerialComm.
*
@ -602,8 +602,9 @@ JNIEXPORT jint JNICALL Java_com_fazecast_jSerialComm_SerialPort_waitForEvent(JNI
}
else // Problem occurred
{
event |= com_fazecast_jSerialComm_SerialPort_LISTENING_EVENT_PORT_DISCONNECTED;
port->errorNumber = GetLastError();
port->errorLineNumber = __LINE__ - 16;
port->errorLineNumber = __LINE__ - 18;
CloseHandle(overlappedStruct.hEvent);
return event;
}

View File

@ -821,7 +821,7 @@ public final class SerialPort
* Sets the BREAK signal on the serial control line.
* @return true if successful, false if not.
*/
public final boolean setBreak() { return (portHandle > 0) && setBreak(portHandle); }
public final boolean setBreak() { return (portHandle > 0) && setBreak(portHandle); }
/**
* Clears the BREAK signal from the serial control line.
@ -1187,6 +1187,9 @@ public final class SerialPort
* It is important to note that non-Windows operating systems only allow decisecond (1/10th of a second) granularity for serial port timeouts. As such, your
* millisecond timeout value will be rounded to the nearest decisecond under Linux or Mac OS. To ensure consistent performance across multiple platforms, it is
* advisable that you set your timeout values to be multiples of 100, although this is not strictly enforced.
* <p>
* Also note that if the serial port has an event-based data listener actively registered for the event type {@link #LISTENING_EVENT_DATA_RECEIVED}, all serial port
* timeout settings are ignored.
*
* @param newTimeoutMode The new timeout mode as specified above.
* @param newReadTimeout The number of milliseconds of inactivity to tolerate before returning from a {@link #readBytes(byte[],long)} call.