Ncurses and reading from serial port in C

Discussion in 'Mac Programming' started by CunningWard, Jan 18, 2010.

  1. CunningWard macrumors member

    CunningWard

    Joined:
    Jan 30, 2008
    Location:
    Middle of a Cornfield, Iowa
    #1
    I just started programming with an Arduino a few months ago and now one of the projects I would like to do for a lab I work for is read in sensor data and send that to a terminal program via the USB connected Arduino. This has presented a few problems:

    #1) Ncurses is not working properly in Xcode. I've tried macports and reinstalling ncurses to no avail. I keep getting a linking error in Xcode.

    #2) Nowhere can I find information on reading in from a serial port in C for Mac...I know this can be done on Windows, but that just takes the fun out of it.

    Any help would be greatly appreciated!
     
  2. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #2
    Post the error message. We can't see your Xcode window from here.


    Google AMSerialPort

    AMSerialPort is an Objective-C library for using serial ports. It's open source under the BSD License.

    I know you asked for C, but AMSerialPort uses the C IOKit functions in its implementation. If it's too much work to rewrite it, you can write C functions that wrap AMSerialPort and then call those from your C code.
     
  3. ScoobyMcDoo macrumors 65816

    Joined:
    Nov 26, 2007
    Location:
    Austin, TX
    #3
    Couldn't one simply open a /dev/ttyxxx file from a C program to use the RS-232 port?
     
  4. robj macrumors regular

    Joined:
    Dec 23, 2009
    Location:
    Madrid, Spain
    #4
    I know that this is kinda offtopic but, why won't you use a Cocoa Application to display the data?

    Knowing that there is a Library to read from serial port, you'll rid of complications about ncurses :)

    I'm starting with Arduino, it's a great device!
     
  5. blueillusion macrumors member

    Joined:
    Aug 18, 2008
    #5
    you can just use standard posix functions in c to read/write from a serial port.
    Your device should show up as /dev/tty.something
    I haven't figured out how to use nonstandard baud rates yet though. Because of that, I can't gather data from my hardware using the fastest settings (my hardware goes up to 921660 baud).

    I used this page to learn how to work with serial ports:
    http://www.easysw.com/~mike/serial/serial.html

    It should serve you well.
     
  6. CunningWard thread starter macrumors member

    CunningWard

    Joined:
    Jan 30, 2008
    Location:
    Middle of a Cornfield, Iowa
    #6
    Gave up on C

    I found a program that will do all I want:

    http://processing.org/

    Check it.

    Thanks for the help!
     
  7. ciotorob macrumors newbie

    Joined:
    Dec 20, 2010
    #7
    Hello, I need to develop an XCode app able to use the serial port ON THE iPHONE. I already arranged the physical connection, jailbroke the iphone, installed minicom and so on, and I can see on the little mobile terminal app (cydia) the characters sent from arduino.
    But I need to read these characters from my XCode app.
    Is everything you wrote here still true? Can I use AMSerialPort or is it only for Cocoa desktop?
    Thank you!
     

Share This Page