30 #if defined(_WIN32) || _POSIX_C_SOURCE >= 200112L
38 return io_attr_lpDCB(attr)->BaudRate;
40 switch (cfgetospeed((
const struct termios *)attr)) {
44 case B110:
return 110;
45 case B134:
return 134;
46 case B150:
return 150;
47 case B200:
return 200;
48 case B300:
return 300;
49 case B600:
return 600;
50 case B1200:
return 1200;
51 case B1800:
return 1800;
52 case B2400:
return 2400;
53 case B4800:
return 4800;
54 case B9600:
return 9600;
55 case B19200:
return 19200;
56 case B38400:
return 38400;
58 case B7200:
return 7200;
61 case B14400:
return 14400;
64 case B57600:
return 57600;
67 case B115200:
return 115200;
70 case B230400:
return 230400;
73 case B460800:
return 460800;
76 case B500000:
return 500000;
79 case B576000:
return 576000;
82 case B921600:
return 921600;
85 case B1000000:
return 1000000;
88 case B1152000:
return 1152000;
91 case B2000000:
return 2000000;
94 case B3000000:
return 3000000;
97 case B3500000:
return 3500000;
100 case B4000000:
return 4000000;
113 io_attr_lpDCB(attr)->BaudRate = speed;
119 case 0: baud = B0;
break;
120 case 50: baud = B50;
break;
121 case 75: baud = B75;
break;
122 case 110: baud = B110;
break;
123 case 134: baud = B134;
break;
124 case 150: baud = B150;
break;
125 case 200: baud = B200;
break;
126 case 300: baud = B300;
break;
127 case 600: baud = B600;
break;
128 case 1200: baud = B1200;
break;
129 case 1800: baud = B1800;
break;
130 case 2400: baud = B2400;
break;
131 case 4800: baud = B4800;
break;
132 case 9600: baud = B9600;
break;
133 case 19200: baud = B19200;
break;
134 case 38400: baud = B38400;
break;
136 case 7200: baud = B7200;
break;
139 case 14400: baud = B14400;
break;
142 case 57600: baud = B57600;
break;
145 case 115200: baud = B115200;
break;
148 case 230400: baud = B230400;
break;
151 case 460800: baud = B460800;
break;
154 case 500000: baud = B500000;
break;
157 case 576000: baud = B576000;
break;
160 case 921600: baud = B921600;
break;
163 case 1000000: baud = B1000000;
break;
166 case 1152000: baud = B1152000;
break;
169 case 2000000: baud = B2000000;
break;
172 case 3000000: baud = B3000000;
break;
175 case 3500000: baud = B3500000;
break;
178 case 4000000: baud = B4000000;
break;
183 if (cfsetispeed((
struct termios *)attr, baud) == -1)
185 if (cfsetospeed((
struct termios *)attr, baud) == -1)
198 LPDCB lpDCB = io_attr_lpDCB(attr);
199 return lpDCB->fOutX || lpDCB->fInX;
201 return !!(((
const struct termios *)attr)->c_iflag & (IXOFF | IXON));
211 LPDCB lpDCB = io_attr_lpDCB(attr);
212 lpDCB->fOutxCtsFlow = FALSE;
213 lpDCB->fOutxDsrFlow = FALSE;
214 lpDCB->fDtrControl = DTR_CONTROL_ENABLE;
215 lpDCB->fRtsControl = RTS_CONTROL_ENABLE;
220 lpDCB->fOutX = FALSE;
226 struct termios *ios = (
struct termios *)attr;
228 ios->c_iflag |= IXOFF | IXON;
230 ios->c_iflag &= ~(IXOFF | IXON);
242 switch (io_attr_lpDCB(attr)->Parity) {
248 const struct termios *ios = (
const struct termios *)attr;
249 if (ios->c_cflag & PARENB)
261 LPDCB lpDCB = io_attr_lpDCB(attr);
264 lpDCB->fParity = FALSE;
265 lpDCB->Parity = NOPARITY;
268 lpDCB->fParity = TRUE;
269 lpDCB->Parity = ODDPARITY;
272 lpDCB->fParity = TRUE;
273 lpDCB->Parity = EVENPARITY;
278 struct termios *ios = (
struct termios *)attr;
281 ios->c_iflag |= IGNPAR;
282 ios->c_cflag &= ~(PARENB | PARODD);
285 ios->c_iflag &= ~(IGNPAR | PARMRK);
286 ios->c_iflag |= INPCK;
287 ios->c_cflag |= PARENB;
288 ios->c_cflag &= ~PARODD;
291 ios->c_iflag &= ~(IGNPAR | PARMRK);
292 ios->c_iflag |= INPCK;
293 ios->c_cflag |= (PARENB | PARODD);
306 return io_attr_lpDCB(attr)->StopBits == TWOSTOPBITS;
308 return !!(((
const struct termios *)attr)->c_cflag & CSTOPB);
318 LPDCB lpDCB = io_attr_lpDCB(attr);
320 lpDCB->StopBits = TWOSTOPBITS;
322 lpDCB->StopBits = ONESTOPBIT;
326 struct termios *ios = (
struct termios *)attr;
328 ios->c_cflag |= CSTOPB;
330 ios->c_cflag &= ~CSTOPB;
342 return io_attr_lpDCB(attr)->ByteSize;
344 switch (((
const struct termios *)attr)->c_cflag & CSIZE) {
360 io_attr_lpDCB(attr)->ByteSize = char_size;
364 struct termios *ios = (
struct termios *)attr;
365 ios->c_cflag &= ~CSIZE;
367 case 5: ios->c_cflag |= CS5;
return 0;
368 case 6: ios->c_cflag |= CS6;
return 0;
369 case 7: ios->c_cflag |= CS7;
return 0;
370 case 8: ios->c_cflag |= CS8;
return 0;
int io_attr_get_char_size(const io_attr_t *attr)
Obtains the character size (in bits) from the attributes of a serial I/O device.
int io_attr_get_flow_control(const io_attr_t *attr)
Checks if flow control is enabled in the attributes of a serial I/O device.
int io_attr_set_parity(io_attr_t *attr, int parity)
Sets the parity scheme of a serial I/O device.
int io_attr_get_speed(const io_attr_t *attr)
Returns the baud rate from the attributes of a serial I/O device, or -1 on error.
int io_attr_set_flow_control(io_attr_t *attr, int flow_control)
Disables flow control for a serial I/O device if flow_control is zero, and enables it otherwise.
int io_attr_set_stop_bits(io_attr_t *attr, int stop_bits)
Sets the number of stop bits used in a serial I/O device to one if stop_bits is zero,...
int io_attr_set_speed(io_attr_t *attr, int speed)
Sets the baud rate of a serial I/O device.
int io_attr_get_parity(const io_attr_t *attr)
Obtains the parity scheme from the attributes of a serial I/O device.
int io_attr_get_stop_bits(const io_attr_t *attr)
Obtains the number of stop bits used from the attributes of a serial I/O device.
int io_attr_set_char_size(io_attr_t *attr, int char_size)
Sets the character size (in bits) of a serial I/O device.
This header file is part of the utilities library; it contains the native and platform-independent er...
@ ERRNUM_INVAL
Invalid argument.
void set_errnum(errnum_t errnum)
Sets the current (thread-specific) platform-independent error number to errnum.
@ IO_PARITY_NONE
No parity.
@ IO_PARITY_ODD
Odd parity.
@ IO_PARITY_EVEN
Even parity.
This is the internal header file of the Windows-specific I/O declarations.
This is the internal header file of the serial I/O attributes declarations.
An opaque serial I/O device attributes type.