Forums
New posts
Articles
Product Reviews
Policies
FAQ
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Menu
Log in
Register
Install the app
Install
Forums
macOS & iOS Developer Playground
macOS - Development and Darwin
problem on open(/dev/tty.usbserial"....)
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="laplace" data-source="post: 929826" data-attributes="member: 128480"><p><strong>Re: problem on open</strong></p><p></p><p>Hi,</p><p></p><p>You can try the device /dev/cu.usbserial instead (check with ls /dev if it exists).</p><p>I think you must open using O_RDWR.</p><p>Do you need to write a command to the port before reading?</p><p>You can also try to set the speed to 9600.</p><p>If that doesn't work try looping until read returns 1.</p><p></p><p>I hope this helps.</p><p></p><p>Regards,</p><p>Magnus</p><p></p><p> strcpy(bsdPath, "/dev/cu.usbserial");</p><p> fileDescriptor = open(bsdPath, O_RDWR);</p><p> if (-1 == fileDescriptor)</p><p> {</p><p> return EX_IOERR;</p><p> }</p><p></p><p> struct termios theTermios;</p><p> memset(&theTermios, 0, sizeof(struct termios));</p><p> cfmakeraw(&theTermios);</p><p> cfsetspeed(&theTermios, 9600);</p><p> theTermios.c_cflag = CREAD | CLOCAL; // turn on READ and ignore modem control lines</p><p> theTermios.c_cflag |= CS8;</p><p> theTermios.c_cc[VMIN] = 0;</p><p> theTermios.c_cc[VTIME] = 10; // 1 sec timeout</p><p> int ret = ioctl(fileDescriptor, TIOCSETA, &theTermios);</p><p> </p><p> ret = read(fileDescriptor, &c, 1);</p></blockquote><p></p>
[QUOTE="laplace, post: 929826, member: 128480"] [b]Re: problem on open[/b] Hi, You can try the device /dev/cu.usbserial instead (check with ls /dev if it exists). I think you must open using O_RDWR. Do you need to write a command to the port before reading? You can also try to set the speed to 9600. If that doesn't work try looping until read returns 1. I hope this helps. Regards, Magnus strcpy(bsdPath, "/dev/cu.usbserial"); fileDescriptor = open(bsdPath, O_RDWR); if (-1 == fileDescriptor) { return EX_IOERR; } struct termios theTermios; memset(&theTermios, 0, sizeof(struct termios)); cfmakeraw(&theTermios); cfsetspeed(&theTermios, 9600); theTermios.c_cflag = CREAD | CLOCAL; // turn on READ and ignore modem control lines theTermios.c_cflag |= CS8; theTermios.c_cc[VMIN] = 0; theTermios.c_cc[VTIME] = 10; // 1 sec timeout int ret = ioctl(fileDescriptor, TIOCSETA, &theTermios); ret = read(fileDescriptor, &c, 1); [/QUOTE]
Verification
Name this item 🌈
Post reply
Forums
macOS & iOS Developer Playground
macOS - Development and Darwin
problem on open(/dev/tty.usbserial"....)
Top