[Noisebridge-discuss] read/write to usb serial port with gcc

Adam Fritzler mid at zigamorph.net
Fri Aug 26 21:09:20 UTC 2011


yes, you can treat it just like a file--open() it and read()/write()
it. To change the speed, encoding, etc and set/read the control lines,
you'll need a few special calls (eg tcgetattr). Here's a couple
reasonable pages on the subject, with C examples:

http://www.easysw.com/~mike/serial/serial.html
http://en.wikibooks.org/wiki/Serial_Programming

cu and tty are quite nearly the same, they just differ in how control
lines are used. Chances are you want to use /dev/cu.usbserial*, which
will ignore DTR on open(). If you use the tty device, open() will
block until DTR goes up, which isn't useful unless your device
actually acts that way (eg a real modem).

On OS X, if you don't have /dev/cu.usbserial* devices automatically,
your device isn't getting recognized. A common problem lately is
needing to upgrade to the latest Prolific and Keyspan drivers, since
64-bit kernels are now the default on new Macs, silently rendering
your old 32-bit drivers useless.

asf.


On Fri, Aug 26, 2011 at 1:13 AM, Robby <robwasab at gmail.com> wrote:
> I don't know if I'm asking the wrong question, but in short, I want to
> create a program that writes to a serial port on my macbook (OS X) using
> gcc.
> I've been googling for hours on end and can't find any powerful libraries
> specifically tailored for mac.
> but, because mac is unix, its pretty compatible with linux stuff?
> I found a library that was tested/compiled under gcc, but some of its
> functions refer to
> USB0          as 0
> USB1          as 1
> USB2          as 2
> but in mac land, all i get under /dev is a bunch of tty stuff, and I'm
> aiming for a usb-serial convert that's called tty.usbserial###. And i have
> no idea how that even relates to the above.
> Does anybody have any experience with writing code that talks to serial
> ports in c or c++, at a glance it seems like there would be a dead shot YES,
> but after looking there really isn't anything standardized like cout, but i
> could be an idiot.
> p.s. what is the difference between cu.usbserial and tty.usbserial?
>
> _______________________________________________
> Noisebridge-discuss mailing list
> Noisebridge-discuss at lists.noisebridge.net
> https://www.noisebridge.net/mailman/listinfo/noisebridge-discuss
>
>



More information about the Noisebridge-discuss mailing list