mirror of
https://github.com/ole00/afterburner.git
synced 2024-06-26 00:29:26 +00:00
PC app: serial - add support for NO_CLOSE on Windows
This commit is contained in:
parent
0367a8b127
commit
eac70f6c68
|
@ -12,6 +12,10 @@ char guessedSerialDevice[512] = {0};
|
||||||
#define DEFAULT_SERIAL_DEVICE_NAME "COM1"
|
#define DEFAULT_SERIAL_DEVICE_NAME "COM1"
|
||||||
#define INVALID_HANDLE INVALID_HANDLE_VALUE
|
#define INVALID_HANDLE INVALID_HANDLE_VALUE
|
||||||
|
|
||||||
|
#ifdef NO_CLOSE
|
||||||
|
static SerialDeviceHandle serH = INVALID_HANDLE;
|
||||||
|
#endif
|
||||||
|
|
||||||
// ideas: https://stackoverflow.com/questions/1388871/how-do-i-get-a-list-of-available-serial-ports-in-win32
|
// ideas: https://stackoverflow.com/questions/1388871/how-do-i-get-a-list-of-available-serial-ports-in-win32
|
||||||
static void serialDeviceGuessName(char** deviceName) {
|
static void serialDeviceGuessName(char** deviceName) {
|
||||||
char buf[64 * 1024] = {0};
|
char buf[64 * 1024] = {0};
|
||||||
|
@ -57,6 +61,12 @@ static void serialDeviceGuessName(char** deviceName) {
|
||||||
static inline SerialDeviceHandle serialDeviceOpen(char* deviceName) {
|
static inline SerialDeviceHandle serialDeviceOpen(char* deviceName) {
|
||||||
SerialDeviceHandle h;
|
SerialDeviceHandle h;
|
||||||
|
|
||||||
|
#ifdef NO_CLOSE
|
||||||
|
if (serH != INVALID_HANDLE) {
|
||||||
|
return serH;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
h = CreateFile(
|
h = CreateFile(
|
||||||
deviceName, //port name
|
deviceName, //port name
|
||||||
GENERIC_READ | GENERIC_WRITE, //Read/Write
|
GENERIC_READ | GENERIC_WRITE, //Read/Write
|
||||||
|
@ -109,7 +119,9 @@ static inline SerialDeviceHandle serialDeviceOpen(char* deviceName) {
|
||||||
}
|
}
|
||||||
//ensure no leftover bytes exist on the serial line
|
//ensure no leftover bytes exist on the serial line
|
||||||
result = PurgeComm(h, PURGE_RXCLEAR | PURGE_TXCLEAR | PURGE_RXABORT | PURGE_TXABORT);
|
result = PurgeComm(h, PURGE_RXCLEAR | PURGE_TXCLEAR | PURGE_RXABORT | PURGE_TXABORT);
|
||||||
|
#ifdef NO_CLOSE
|
||||||
|
serH = h;
|
||||||
|
#endif
|
||||||
return h;
|
return h;
|
||||||
} else {
|
} else {
|
||||||
return INVALID_HANDLE;
|
return INVALID_HANDLE;
|
||||||
|
@ -142,7 +154,9 @@ void serialDeviceCheckName(char* name, int maxSize) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void serialDeviceClose(SerialDeviceHandle deviceHandle) {
|
static inline void serialDeviceClose(SerialDeviceHandle deviceHandle) {
|
||||||
|
#ifndef NO_CLOSE
|
||||||
CloseHandle(deviceHandle);
|
CloseHandle(deviceHandle);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int serialDeviceWrite(SerialDeviceHandle deviceHandle, char* buffer, int bytesToWrite) {
|
static inline int serialDeviceWrite(SerialDeviceHandle deviceHandle, char* buffer, int bytesToWrite) {
|
||||||
|
@ -170,7 +184,6 @@ static inline int serialDeviceRead(SerialDeviceHandle deviceHandle, char* buffer
|
||||||
#define DEFAULT_SERIAL_DEVICE_NAME "/dev/ttyUSB0"
|
#define DEFAULT_SERIAL_DEVICE_NAME "/dev/ttyUSB0"
|
||||||
|
|
||||||
#define INVALID_HANDLE -1
|
#define INVALID_HANDLE -1
|
||||||
|
|
||||||
#ifdef NO_CLOSE
|
#ifdef NO_CLOSE
|
||||||
static SerialDeviceHandle serH = INVALID_HANDLE;
|
static SerialDeviceHandle serH = INVALID_HANDLE;
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue
Block a user