c - Opening a serial port on OS X hangs forever without O_NONBLOCK flag -



c - Opening a serial port on OS X hangs forever without O_NONBLOCK flag -

i have serial usb converter (ftdi, drivers installed http://www.ftdichip.com/drivers/vcp.htm) connecting serial device macbook air. shows on macbook both /dev/cu.usbserial-a4017cqy , /dev/tty.usbserial-a4017cqy. all behaviour describe identical regardless of of these 2 use.

edit: using /dev/cu.* did solve problem. i'm not sure why seemed not work when first posted question. duskwuff pointing me in right direction, though has tty names backwards: /dev/tty.* wait flow control, while /dev/cu.* not.

the first problem encountered syscall open() block forever if did not utilize o_nonblock flag. using flag, file descriptor, write() not seem write (though returns fine claiming have written bytes), , read() fails error "resource temporarily unavailable".

stty -af /dev/cu.usbserial-a4017cqy shows settings fine, if seek alter them command stty -f /dev/cu.usbserial-a4017cqy -clocal, appear changed when displayed successive phone call stty.

if utilize select() wait device become ready before reading/writing, reports after short time ready write, never read. gels how write() completes without complaint, while read() fails. note info written never create device.

the entire test programme wrote debug below:

#include <stdio.h> #include <fcntl.h> #include <termios.h> #include <unistd.h> #include <sys/select.h> #define syscall(a) { ret = a; if (ret == -1) { perror(#a); homecoming -1; } else printf("%s returned %d\n", #a, ret); } while (0) int ret; /* necessary syscall */ int main() { struct termios tio; char buf[256]; int fd = open("/dev/cu.usbserial-a4017cqy", o_rdwr | o_noctty | o_nonblock); fd_set rfds, wfds, xfds; struct timeval to; to.tv_sec = 5; to.tv_usec = 0; syscall(tcgetattr(fd, &tio)); cfmakeraw(&tio); tio.c_cflag = cs8|cread|clocal; tio.c_cc[vmin] = 1; tio.c_cc[vtime] = 1; cfsetispeed(&tio, b115200); cfsetospeed(&tio, b115200); syscall(tcsetattr(fd, tcsanow, &tio)); fd_zero(&rfds); fd_zero(&wfds); fd_zero(&xfds); fd_set(fd, &rfds); fd_set(fd, &wfds); fd_set(fd, &xfds); int ret = select(fd+1, &rfds, null, &xfds, &to); if (ret == -1) perror("select"); else if (ret > 0) { if(fd_isset(fd, &rfds)) puts("ready read"); if(fd_isset(fd, &wfds)) puts("ready write"); if(fd_isset(fd, &xfds)) puts("exception!"); } else puts("timed out!"); syscall(write(fd, "/home\n", 5)); syscall(read(fd, buf, 256)); homecoming 0; }

you have flow command issue. either loop bring together rts/cts , dtr/dsr/cd on cable, have other end provide command signals, or, @duskwuff suggests, utilize device ignores flow control.

i see setting clocal -- should work, usb devices not right thing. description consistent device waiting modem command signals.

c osx serial-port termios stty

Comments

Popular posts from this blog

java Multi query from Mysql using netbeans -

c# - DotNetZip fails with "stream does not support seek operations" -

c++ - StartServiceCtrlDispatcher don't can access 1063 error -