Re: Serial device driver
Re: Serial device driver
- Subject: Re: Serial device driver
- From: Howard Oakley <email@hidden>
- Date: Mon, 12 May 2003 21:48:16 +0100
On 12/5/03 7:02 pm, Justin Lundy wrote:
>
I want to write a method to download information off a serial device
>
through a Serial2USB adapter (most likely Keyspan). This device is not
>
directly Mac compatible. I have no idea where to start, as I have
>
never written drivers for even USB devices, or any devices for that
>
matter. Can anyone point me in the right direction (an example, book,
>
leaflet)?
Justin,
There is good sample code available from the Keyspan site that should get
you on your way. Look at
http://www.keyspan.com/support/developers/ for it.
In essence, USB->serial adaptor drivers (i.e. The Keyspan software you
install to support the adaptor) make the serial port(s) they add available
as standard Unix devices. The example code show how you can discover which
devices are available, or you can hardwire if you prefer. For instance, one
device makes the serial port available as /dev/tty.USA28X11P1.1
Then all your code has to do is open the port, e.g.
fd0 = open(DEVICENAME, O_RDWR | O_NONBLOCK);
You can then configure it as necessary using calls like
ret = tcsetattr(fd0, TCSANOW, &theTermios);
and
ioctl(fd0, TIOCMGET, &modem);
Read using
k = read(fd0, rdBuff, count);
And write using
k = write(fd0, theBuff, strlen(theBuff));
When done,
close(fd0);
There is also some Apple source that shows how to do threaded I/O with
serial ports, I think.
Unless you really really want to write a higher level 'driver', I suggest
that you either build your code into your Cocoa app, or (as I did) write a
little command line tool that you can drive from a Cocoa app. The latter has
many attractions, not least of which is the fact that you can make the tool
rock solid and reliable before you venture into the app front end.
This approach to Unix I/O is also covered in books such as Stevens' Advanced
Programming in the UNIX Environment, which I commend to you for reference
and constant use.
Howard.
Dr Howard Oakley (M1BWR) * email@hidden
EHN & DIJ Oakley * email@hidden
Isle of Wight, UK
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.