RS232_LIB unsigned int rs232_set_baud(struct rs232_port_t *p, enum rs232_baud_e baud) { DCB pdcb; struct rs232_windows_t *wx = p->pt; DBG("p=%p p->pt=%p baud=%d (%s bauds)\n", (void *)p, p->pt, baud, rs232_strbaud(baud)); if (!rs232_port_open(p)) return RS232_ERR_PORT_CLOSED; GET_PORT_STATE(wx->fd, &pdcb); switch (baud) { case RS232_BAUD_300: pdcb.BaudRate = CBR_300; break; case RS232_BAUD_2400: pdcb.BaudRate = CBR_2400; break; case RS232_BAUD_4800: pdcb.BaudRate = CBR_4800; break; case RS232_BAUD_9600: pdcb.BaudRate = CBR_9600; break; case RS232_BAUD_19200: pdcb.BaudRate = CBR_19200; break; case RS232_BAUD_38400: pdcb.BaudRate = CBR_38400; break; case RS232_BAUD_57600: pdcb.BaudRate = CBR_57600; break; case RS232_BAUD_115200: pdcb.BaudRate = CBR_115200; break; case RS232_BAUD_460800: pdcb.BaudRate = CBR_460800; break; default: return RS232_ERR_UNKNOWN; } SET_PORT_STATE(wx->fd, &pdcb); p->baud = baud; return RS232_ERR_NOERROR; }
RS232_LIB const char * rs232_to_string(struct rs232_port_t *p) { static char str[RS232_STRLEN+1]; DBG("p=%p\n", (void *)p); if (p == NULL) return NULL; snprintf(str, RS232_STRLEN, "device: %s, baud: %s, data bits: %s," " parity: %s, stop bits: %s," " flow control: %s", p->dev, rs232_strbaud(p->baud), rs232_strdata(p->data), rs232_strparity(p->parity), rs232_strstop(p->stop), rs232_strflow(p->flow)); return str; }