diff --git a/src/comio/comio.h b/src/comio/comio.h index 09cfc860cb0ad6292a9de1e39d4ae338d683caa6..47a650302cc0a17fac5f55e363f2a8a7f47fc005 100644 --- a/src/comio/comio.h +++ b/src/comio/comio.h @@ -135,6 +135,7 @@ COMIOEXPORT size_t comReadLine(COM_HANDLE, char* buf, size_t buflen ,int timeout /* in milliseconds */); COMIOEXPORT BOOL comPurgeInput(COM_HANDLE); COMIOEXPORT BOOL comPurgeOutput(COM_HANDLE); +COMIOEXPORT BOOL comSetParity(COM_HANDLE, BOOL enable, BOOL odd); #if defined(__cplusplus) } diff --git a/src/comio/comio_nix.c b/src/comio/comio_nix.c index 03f33d498d5423eb61dfc9823e2303261a57fa67..eb96c7ce90c9c0fe322a541030a7a72de57ba010 100644 --- a/src/comio/comio_nix.c +++ b/src/comio/comio_nix.c @@ -338,6 +338,28 @@ BOOL comSetFlowControl(COM_HANDLE handle, int modes) return TRUE; } +BOOL comSetParity(COM_HANDLE handle, BOOL enable, BOOL odd) +{ + struct termios t; + + if(tcgetattr(handle, &t)==-1) + return FALSE; + + if (enable) { + t.c_cflag |= PARENB; + if (odd) + t.c_cflag |= PARODD; + else + t.c_cflag &= ~PARODD; + } else + t.c_cflag &= ~(PARENB | PARODD); + + if(tcsetattr(handle, TCSANOW, &t)==-1) + return FALSE; + + return TRUE; +} + int comGetModemStatus(COM_HANDLE handle) { int status; diff --git a/src/comio/comio_win32.c b/src/comio/comio_win32.c index b539dd7d29655f10df289c384e825ae25da47c98..0b171157ec5d525a99fc56607ca1c4a18c49e474 100644 --- a/src/comio/comio_win32.c +++ b/src/comio/comio_win32.c @@ -79,6 +79,7 @@ COM_HANDLE comOpen(const char* device) dcb.ByteSize = 8; dcb.Parity = NOPARITY; dcb.StopBits = ONESTOPBIT; + dcb.fParity = FALSE; SetCommState(handle, &dcb); } @@ -157,6 +158,18 @@ BOOL comSetFlowControl(COM_HANDLE handle, int type) return SetCommState(handle, &dcb); } +BOOL comSetParity(COM_HANDLE handle, BOOL enable, BOOL odd) +{ + DCB dcb; + + if(GetCommState(handle, &dcb) != TRUE) + return FALSE; + + dcb.fParity = enable; + dcb.Parity = enable ? (odd ? ODDPARITY : EVENPARITY) : NOPARITY; + return SetCommState(handle, &dcb); +} + int comGetModemStatus(COM_HANDLE handle) { DWORD status=0; diff --git a/src/sexpots/sexpots.c b/src/sexpots/sexpots.c index 983c020c80c665f0b0e9e53db9a4bb35a54abf31..3db74442c24378f72d752d81f585f303d125afe1 100644 --- a/src/sexpots/sexpots.c +++ b/src/sexpots/sexpots.c @@ -75,6 +75,8 @@ BOOL com_handle_passed=FALSE; BOOL com_alreadyconnected=FALSE; BOOL com_hangup=TRUE; ulong com_baudrate=0; +BOOL com_parity=FALSE; +BOOL com_parity_odd=FALSE; BOOL dcd_ignore=FALSE; int dcd_timeout=10; /* seconds */ ulong dtr_delay=100; /* milliseconds */ @@ -1414,6 +1416,8 @@ void parse_ini_file(const char* ini_fname) section="COM"; iniGetExistingWord(ini, section, "Device", NULL, com_dev); com_baudrate = iniGetLongInt(ini, section, "BaudRate", com_baudrate); + com_parity = iniGetBool(ini, section, "Parity", com_parity); + com_parity_odd = iniGetBool(ini, section, "ParityOdd", com_parity_odd); com_hangup = iniGetBool(ini, section, "Hangup", com_hangup); hangup_attempts = iniGetInteger(ini, section, "HangupAttempts", hangup_attempts); dcd_timeout = iniGetInteger(ini, section, "DCDTimeout", dcd_timeout); @@ -1571,6 +1575,9 @@ service_loop(int argc, char** argv) if(!comSetBaudRate(com_handle,com_baudrate)) lprintf(LOG_ERR,"ERROR %u setting DTE rate to %lu bps" ,COM_ERROR_VALUE, com_baudrate); + if(!comSetParity(com_handle, com_parity, com_parity_odd)) + lprintf(LOG_ERR,"ERROR %u setting parity type" + ,COM_ERROR_VALUE); } lprintf(LOG_INFO,"COM Port DTE rate: %ld bps", comGetBaudRate(com_handle)); @@ -1622,6 +1629,7 @@ service_loop(int argc, char** argv) } } else lprintf(LOG_NOTICE, "Timeout (%d seconds) waiting for response to prompt", prompt_timeout); + comSetParity(com_handle, com_parity, com_parity_odd); } if((sock=connect_socket(host, port)) == INVALID_SOCKET) { comWriteString(com_handle,"\7\r\n!ERROR connecting to TCP port\r\n");