RS232_LIB unsigned int rs232_open(struct rs232_port_t *p) { wchar_t *wname = a2w(fix_device_name(p->dev)); struct rs232_windows_t *wx = p->pt; DBG("p=%p p->pt=%p name='%s' fix='%s'\n", (void *)p, p->pt, p->dev, fix_device_name(p->dev)); if (wname == NULL) return RS232_ERR_UNKNOWN; wx->fd = CreateFileW(wname, GENERIC_READ | GENERIC_WRITE, // Force Unicode version of CreateFile() -hg FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); if (wname) free(wname); if (wx->fd == INVALID_HANDLE_VALUE) { DBG("CreateFile() %s\n", last_error()); return RS232_ERR_OPEN; } p->status = RS232_PORT_OPEN; rs232_flush(p); GET_PORT_STATE(wx->fd, &wx->old_dcb); GET_PORT_TIMEOUTS(wx->fd, &wx->old_tm); port_timeout(p, wx->r_timeout, wx->w_timeout); port_buffers(p, wx->r_buffer, wx->w_buffer); rs232_set_baud(p, p->baud); rs232_set_data(p, p->data); rs232_set_parity(p, p->parity); rs232_set_stop(p, p->stop); rs232_set_flow(p, p->flow); return RS232_ERR_NOERROR; }
RS232_LIB unsigned int rs232_set_data(struct rs232_port_t *p, enum rs232_data_e data) { DCB pdcb; struct rs232_windows_t *wx = p->pt; DBG("p=%p p->pt=%p data=%d (%s data bits)\n", (void *)p, p->pt, data, rs232_strdata(data)); if (!rs232_port_open(p)) return RS232_ERR_PORT_CLOSED; GET_PORT_STATE(wx->fd, &pdcb); switch (data) { case RS232_DATA_5: pdcb.ByteSize = 5; break; case RS232_DATA_6: pdcb.ByteSize = 6; break; case RS232_DATA_7: pdcb.ByteSize = 7; break; case RS232_DATA_8: pdcb.ByteSize = 8; break; default: return RS232_ERR_UNKNOWN; } SET_PORT_STATE(wx->fd, &pdcb); p->data = data; return RS232_ERR_NOERROR; }