Skip to content
Snippets Groups Projects
Commit a3a96c8a authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Add support for even/odd parity com ports

Set Parity=true in [com] section of sexpots.ini
Set ParityOdd=true if using Odd parity.
parent 869e0ebd
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
Pipeline #2679 passed
......@@ -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)
}
......
......@@ -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;
......
......@@ -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;
......
......@@ -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");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment