Ncurses and reading from serial port in C

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

  1. CunningWard macrumors member


    Jan 30, 2008
    Middle of a Cornfield, Iowa
    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

    Aug 9, 2009
    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

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

    Dec 23, 2009
    Madrid, Spain
    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

    Aug 18, 2008
    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:

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


    Jan 30, 2008
    Middle of a Cornfield, Iowa
    Gave up on C

    I found a program that will do all I want:

    Check it.

    Thanks for the help!
  7. ciotorob macrumors newbie

    Dec 20, 2010
    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