21 #include <sys/types.h>
34 #include "sigrok-internal.h"
41 static const char *serial_port_glob[] = {
60 ports = g_slist_append(ports, g_strdup(
"COM1"));
66 for (i = 0; serial_port_glob[i]; i++) {
67 if (glob(serial_port_glob[i], 0, NULL, &g))
69 for (j = 0; j < g.gl_pathc; j++)
70 ports = g_slist_append(ports, g_strdup(g.gl_pathv[j]));
82 hdl = CreateFile(
"COM1", GENERIC_READ | GENERIC_WRITE, 0, 0,
83 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
84 if (hdl == INVALID_HANDLE_VALUE) {
89 return open(pathname, flags);
101 return (CloseHandle(hdl) == 0) ? -1 : 0;
116 return (PurgeComm(hdl, PURGE_RXCLEAR | PURGE_TXCLEAR) == 0) ? -1 : 0;
119 return tcflush(fd, TCIOFLUSH);
134 WriteFile(hdl, buf, count, &tmp, NULL);
137 return write(fd, buf, count);
152 return ReadFile(hdl, buf, count, &tmp, NULL);
155 return read(fd, buf, count);
164 struct termios *term;
167 if (!(term = g_try_malloc(
sizeof(
struct termios)))) {
168 sr_err(
"serial: %s: term malloc failed", __func__);
183 tcsetattr(fd, TCSADRAIN, (
struct termios *)backup);
194 int stopbits,
int flowcontrol)
199 if (!GetCommState(hdl, &dcb)) {
207 dcb.BaudRate = CBR_115200;
210 dcb.BaudRate = CBR_57600;
213 dcb.BaudRate = CBR_38400;
216 dcb.BaudRate = CBR_19200;
219 dcb.BaudRate = CBR_9600;
226 dcb.Parity = NOPARITY;
227 dcb.StopBits = ONESTOPBIT;
229 if (!SetCommState(hdl, &dcb)) {
259 if (tcgetattr(fd, &term) < 0)
261 if (cfsetispeed(&term, baud) < 0)
264 term.c_cflag &= ~CSIZE;
276 term.c_cflag &= ~CSTOPB;
281 term.c_cflag |= CSTOPB;
286 term.c_cflag &= ~(IXON | IXOFF | CRTSCTS);
287 switch (flowcontrol) {
289 term.c_cflag |= IXON | IXOFF;
292 term.c_cflag |= CRTSCTS;
297 term.c_iflag &= ~IGNPAR;
298 term.c_cflag &= ~(PARODD | PARENB);
301 term.c_iflag |= IGNPAR;
304 term.c_cflag |= PARENB;
307 term.c_cflag |= PARENB | PARODD;
313 if (tcsetattr(fd, TCSADRAIN, &term) < 0)