RS232 through USB port in Cocoa

Discussion in 'Mac Programming' started by FireArse, Nov 1, 2006.

  1. FireArse macrumors 6502a

    Joined:
    Oct 29, 2004
    #1
    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
     
  2. iMeowbot macrumors G3

    iMeowbot

    Joined:
    Aug 30, 2003
    #2
  3. mduser63 macrumors 68040

    mduser63

    Joined:
    Nov 9, 2004
    Location:
    Salt Lake City, UT
    #3
    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.
     
  4. Sayer macrumors 6502a

    Sayer

    Joined:
    Jan 4, 2002
    Location:
    Austin, TX
    #4
    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/
     
  5. FireArse thread starter macrumors 6502a

    Joined:
    Oct 29, 2004
    #5
    Rs232 I/o

    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
     
  6. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #6
    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...
     
  7. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #7
    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...
     
  8. mrichmon macrumors 6502a

    Joined:
    Jun 17, 2003
    #8
    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.
     
  9. HiRez macrumors 603

    HiRez

    Joined:
    Jan 6, 2004
    Location:
    Western US
    #9
    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.
     
  10. FireArse thread starter macrumors 6502a

    Joined:
    Oct 29, 2004
    #10
    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
     
  11. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #11
    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!
     
  12. hexor macrumors 6502

    Joined:
    Nov 26, 2002
    Location:
    Minnesota
    #12
    Check http://www.harmless.de/cocoa.html for his AMSerialPort class.. Allows you to easily use the serial port(USB adapter) with Cocoa.
     
  13. FireArse thread starter macrumors 6502a

    Joined:
    Oct 29, 2004
    #13
    :)

    Thats great! Would it work on RobbieDuncan's bit of kit? I'd love to test it out!
     

Share This Page