Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IOPort/Windows: Fix wrong break condition handling #262

Merged
merged 4 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion PsychSourceGL/Source/Common/IOPort/IOPort.c
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ PsychError IOPORTOpenSerialPort(void)
"or on OS/X and Linux in 'Cooked' processing mode as line delimiter. A setting of -1 will try to disable the line terminator.\n\n"
"DTR=os default -- Setting for 'Data Terminal Ready' pin: 0 or 1.\n\n"
"RTS=os default -- Setting for 'Request To Send' pin: 0 or 1.\n\n"
"BreakBehaviour=Ignore -- Behaviour if a 'Break Condition' is detected on the line: Ignore, Flush, Zero. On Windows, this setting is ignored.\n\n"
"BreakBehaviour=Ignore -- Behaviour if a 'Break Condition' is detected on the line: Ignore, Flush, Zero. On Windows, only 'Ignore' is allowed.\n\n"
"OutputBufferSize=4096 -- Size of output buffer in bytes.\n\n"
"InputBufferSize=4096 -- Size of input buffer in bytes. You can't read more than that amount per read command.\n\n"
"HardwareBufferSizes=input,output -- Set size of the hardware driver internal input and output buffers in bytes. "
Expand Down
14 changes: 13 additions & 1 deletion PsychSourceGL/Source/Windows/IOPort/PsychSerialWindowsGlue.c
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,15 @@ PsychError PsychIOOSConfigureSerialPort( PsychSerialDeviceRecord* device, const
// updatetermios = TRUE;
// }

// Handling of Break condition:
if ((p = strstr(configString, "BreakBehaviour="))) {
if (p != strstr(p, "BreakBehaviour=Ignore")) {
printf("Invalid break behaviour %s not accepted (Valid on MS-Windows: Ignore)!", p);
return(PsychError_user);
}
updatetermios = TRUE;
}

// Handling of data bits:
if ((p = strstr(configString, "DataBits="))) {
// Clear all databit settings:
Expand Down Expand Up @@ -1387,8 +1396,11 @@ int PsychIOOSCheckError(PsychSerialDeviceRecord* device, char* inerrmsg)
return(0xdeadbeef);
}

// Ignore the break condition altogether, meaning no error notification and no error condition (which otherwise could result in discarding received data).
estatus &= ~CE_BREAK;

if (estatus > 0 && inerrmsg) {
if (estatus & CE_BREAK) { sprintf(errmsg, "IOPort: Break condition on receive line detected.\n"); strcat(inerrmsg, errmsg); }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can leave this line for future use.

if (estatus & CE_BREAK) { sprintf(errmsg, "IOPort: Break condition on receive line detected.\n"); strcat(inerrmsg, errmsg); } // maybe useful in the future
if (estatus & CE_FRAME) { sprintf(errmsg, "IOPort: Data packet framing error detected.\n"); strcat(inerrmsg, errmsg); }
if (estatus & CE_OVERRUN) { sprintf(errmsg, "IOPort: Character buffer overrun detected.\n"); strcat(inerrmsg, errmsg); }
if (estatus & CE_RXOVER) { sprintf(errmsg, "IOPort: Receive buffer overflow detected.\n"); strcat(inerrmsg, errmsg); }
Expand Down