34#if _WIN32 || _POSIX_C_SOURCE >= 200112L
42 return io_attr_lpDCB(attr)->BaudRate;
44 switch (cfgetospeed((
const struct termios *)attr)) {
48 case B110:
return 110;
49 case B134:
return 134;
50 case B150:
return 150;
51 case B200:
return 200;
52 case B300:
return 300;
53 case B600:
return 600;
54 case B1200:
return 1200;
55 case B1800:
return 1800;
56 case B2400:
return 2400;
57 case B4800:
return 4800;
58 case B9600:
return 9600;
59 case B19200:
return 19200;
60 case B38400:
return 38400;
62 case B7200:
return 7200;
65 case B14400:
return 14400;
68 case B57600:
return 57600;
71 case B115200:
return 115200;
74 case B230400:
return 230400;
77 case B460800:
return 460800;
80 case B500000:
return 500000;
83 case B576000:
return 576000;
86 case B921600:
return 921600;
89 case B1000000:
return 1000000;
92 case B1152000:
return 1152000;
95 case B2000000:
return 2000000;
98 case B3000000:
return 3000000;
101 case B3500000:
return 3500000;
104 case B4000000:
return 4000000;
117 io_attr_lpDCB(attr)->BaudRate = speed;
123 case 0: baud = B0;
break;
124 case 50: baud = B50;
break;
125 case 75: baud = B75;
break;
126 case 110: baud = B110;
break;
127 case 134: baud = B134;
break;
128 case 150: baud = B150;
break;
129 case 200: baud = B200;
break;
130 case 300: baud = B300;
break;
131 case 600: baud = B600;
break;
132 case 1200: baud = B1200;
break;
133 case 1800: baud = B1800;
break;
134 case 2400: baud = B2400;
break;
135 case 4800: baud = B4800;
break;
136 case 9600: baud = B9600;
break;
137 case 19200: baud = B19200;
break;
138 case 38400: baud = B38400;
break;
140 case 7200: baud = B7200;
break;
143 case 14400: baud = B14400;
break;
146 case 57600: baud = B57600;
break;
149 case 115200: baud = B115200;
break;
152 case 230400: baud = B230400;
break;
155 case 460800: baud = B460800;
break;
158 case 500000: baud = B500000;
break;
161 case 576000: baud = B576000;
break;
164 case 921600: baud = B921600;
break;
167 case 1000000: baud = B1000000;
break;
170 case 1152000: baud = B1152000;
break;
173 case 2000000: baud = B2000000;
break;
176 case 3000000: baud = B3000000;
break;
179 case 3500000: baud = B3500000;
break;
182 case 4000000: baud = B4000000;
break;
187 if (cfsetispeed((
struct termios *)attr, baud) == -1)
189 if (cfsetospeed((
struct termios *)attr, baud) == -1)
202 LPDCB lpDCB = io_attr_lpDCB(attr);
203 return lpDCB->fOutX || lpDCB->fInX;
205 return !!(((
const struct termios *)attr)->c_iflag & (IXOFF | IXON));
215 LPDCB lpDCB = io_attr_lpDCB(attr);
216 lpDCB->fOutxCtsFlow = FALSE;
217 lpDCB->fOutxDsrFlow = FALSE;
218 lpDCB->fDtrControl = DTR_CONTROL_ENABLE;
219 lpDCB->fRtsControl = RTS_CONTROL_ENABLE;
224 lpDCB->fOutX = FALSE;
230 struct termios *ios = (
struct termios *)attr;
232 ios->c_iflag |= IXOFF | IXON;
234 ios->c_iflag &= ~(IXOFF | IXON);
246 switch (io_attr_lpDCB(attr)->Parity) {
252 const struct termios *ios = (
const struct termios *)attr;
253 if (ios->c_cflag & PARENB)
265 LPDCB lpDCB = io_attr_lpDCB(attr);
268 lpDCB->fParity = FALSE;
269 lpDCB->Parity = NOPARITY;
272 lpDCB->fParity = TRUE;
273 lpDCB->Parity = ODDPARITY;
276 lpDCB->fParity = TRUE;
277 lpDCB->Parity = EVENPARITY;
282 struct termios *ios = (
struct termios *)attr;
285 ios->c_iflag |= IGNPAR;
286 ios->c_cflag &= ~(PARENB | PARODD);
289 ios->c_iflag &= ~(IGNPAR | PARMRK);
290 ios->c_iflag |= INPCK;
291 ios->c_cflag |= PARENB;
292 ios->c_cflag &= ~PARODD;
295 ios->c_iflag &= ~(IGNPAR | PARMRK);
296 ios->c_iflag |= INPCK;
297 ios->c_cflag |= (PARENB | PARODD);
310 return io_attr_lpDCB(attr)->StopBits == TWOSTOPBITS;
312 return !!(((
const struct termios *)attr)->c_cflag & CSTOPB);
322 LPDCB lpDCB = io_attr_lpDCB(attr);
324 lpDCB->StopBits = TWOSTOPBITS;
326 lpDCB->StopBits = ONESTOPBIT;
330 struct termios *ios = (
struct termios *)attr;
332 ios->c_cflag |= CSTOPB;
334 ios->c_cflag &= ~CSTOPB;
346 return io_attr_lpDCB(attr)->ByteSize;
348 switch (((
const struct termios *)attr)->c_cflag & CSIZE) {
364 io_attr_lpDCB(attr)->ByteSize = char_size;
368 struct termios *ios = (
struct termios *)attr;
369 ios->c_cflag &= ~CSIZE;
371 case 5: ios->c_cflag |= CS5;
return 0;
372 case 6: ios->c_cflag |= CS6;
return 0;
373 case 7: ios->c_cflag |= CS7;
return 0;
374 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.