Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

FireArse

macrumors 6502a
Original poster
Oct 29, 2004
900
110
Hello all,

Having looked through Cocoa and Google - there is very little in th e way of programming cocoa with RS232. If there is, my apologies, but I couln't find any!

Basically, I'm currently writing a VB App within .NET (for win32). It uses the stanard serial port (com1) to communicate with a device using the VT100 specification.

My colleague and I have this nearly working within the windows environment - and I'm wondering how hard it'd be to program in OS X. I know you can use the USB port in windows to do this - its just a matter of programming the code to an RS232 spec connection.

Can you do the same within OS X - and if so, where could I find details for it?

Many thanks,

FireArse
 

mduser63

macrumors 68040
Nov 9, 2004
3,042
31
Salt Lake City, UT
I'm interested in this as well. The next major area of work on the app I'm developing is going to be serial communications with external devices. I'm not there yet, but I'm interested to hear about your results. FWIW, there are definitely other programs out there that use RS-232 under OS X, because I've used at least two of them. I have a Keyspan USB->RS-232/Parallel adapter that works well in OS X.
 

Sayer

macrumors 6502a
Jan 4, 2002
981
0
Austin, TX
It seems to me that the easiest way to "talk" to a USB device is to emulate a RS-232 serial port and talk to that.

You can get tons of free (schematic/parts list) to pre-made self-contained circuits pre-programmed out on the Internets.

Programming to them, however, requires use of the naked I/OKit interfaces. For some reason Apple went old-school for its hardware-accessing interfaces in OS X instead of the nicely abstracted, friendly, high-level APIs, such as Comm Toolbox and Input Manager on Mac OS 9 (Classic).

I am sure there is Apple sample code for talking to the modem or something, because I built an app (and Unix daemon) ages ago for OS X that talks to an LCD device via an emulated RS-232 port using I/OKit.

http://developer.apple.com/samplecode/
 

FireArse

macrumors 6502a
Original poster
Oct 29, 2004
900
110
Rs232 I/o

I am sure there is Apple sample code for talking to the modem or something, because I built an app (and Unix daemon) ages ago for OS X that talks to an LCD device via an emulated RS-232 port using I/OKit.

This is most interesting. Yes, after the first reply - I noticed the keyspan usb interface...very interesting. Bit pricey though, for what they are. Still. Would be pretty neat.

Sayer - can you find further details about this project? Would you mind allowing others access to the source? Where did you get the LCD display from?

Thanks,

F
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
This is most interesting. Yes, after the first reply - I noticed the keyspan usb interface...very interesting. Bit pricey though, for what they are. Still. Would be pretty neat.

I have one that I used to use to update my GPS from Virtual PC. I no longer do this! It works really well. The biggest issue I can see with this is working out what the serial port is called. When you connect the device a serial port is created in /dev but it's name is not predictable as it varies depending on the port it's plugged into!

If you are somewhere in the UK I could lend you the one I have as I don't currently need it...
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
OK looks like the drivers have changed a little now. The serial port is predicable. When the device is connected you can see these files in /dev:

crw-rw-rw- 1 root wheel 10, 12 Nov 2 17:00 tty.KeySerial1
crw-rw-rw- 1 root wheel 10, 14 Nov 2 17:00 tty.USA19QW3d1P1.1

You should be able to simply write to these to write to the serial port...
 

mrichmon

macrumors 6502a
Jun 17, 2003
873
3
OK looks like the drivers have changed a little now. The serial port is predicable.

Yup, the device nodes are predictable. The original poster can just drop down into c and use iotcl() to read/write the serial port. Example code can be found in the minicom and/or pilot-link open source programs. Both of these programs access the serial device through the /dev device node and function correctly on OS X with USB->Serial dongles.
 

HiRez

macrumors 603
Jan 6, 2004
6,265
2,629
Western US
Python has a nice, simple serial API (which you can call from your Cocoa app probably using NSTask or other method) called pySerial. The serial code from Apple I glanced at a few years ago looked pretty complex and low-level. I've done a bunch of C stuff with QuickTime and CoreAudio, but this stuff made my head hurt. By contrast, pySerial was very easy to understand and use.
 

FireArse

macrumors 6502a
Original poster
Oct 29, 2004
900
110
well...

robbieduncan: Thanks! I am in the UK, but this stuff is so above me right now! I will bear your offer in mind once I get some of this into my head.

I haven't played around with XCode enough to confidently know what I'm doing - let alone calling python code into my Cocoa app!

What would be real cool, is if a few devs who knew what they were doing got together for a tutorial somewhere. Perhaps a public library or somewhere free & open till late-ish?

I work in London if it helps!

F
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
There is Cocoa Dev House London. I've signed up but never been. Other than that if you organise something I'm sure a few people would go along. I'm in London and would come if I'm around. I'm hardly a professional Mac developer though!
 

hexor

macrumors 6502
Nov 26, 2002
271
88
Minnesota
I'm interested in this as well. The next major area of work on the app I'm developing is going to be serial communications with external devices. I'm not there yet, but I'm interested to hear about your results. FWIW, there are definitely other programs out there that use RS-232 under OS X, because I've used at least two of them. I have a Keyspan USB->RS-232/Parallel adapter that works well in OS X.

Check http://www.harmless.de/cocoa.html for his AMSerialPort class.. Allows you to easily use the serial port(USB adapter) with Cocoa.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.