Thread: RS232 serial port interfacing on Mac OS X

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    79

    RS232 serial port interfacing on Mac OS X

    Hello everyone,

    I'm trying to write a C program that interfaces with a device that is connected via the RS 232 serial port.

    I'm having a hard time finding 'libraries' that work on Mac OS X. All that I've found thus far are libraries for Win32...

    Could someone please recommend a library that I can use (ie. include in the code) that can be used to interface through the RS 232 port?

    I'm using GCC as my compiler on my Mac OS X.

    I've read that for this the Mac OS X is basically equivalent to Unix, but I still haven't been able to get very far...

    I'd appreciate anyone that could help.

    Thanks in advanced

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Once you have the driver for your serial port adapter installed, and identified the port being used, you may want to try some of the information from this link: Serial Programming Guide.

    Jim

  3. #3
    Registered User
    Join Date
    Mar 2010
    Posts
    79
    Hi,

    Thanks for your advice... But I don't think there's any "driver"... Unless I've been mistaken...

    I intend to use a Serial to USB cable to connect the device, which I believe doesn't actually have any drivers (again, if I haven't been mistaken).

    Could you please advise?

    Thanks in advanced

    EDIT: I had a look at that website provided (I haven't tested it on my mac -- will do tomorrow)... But their approach looks somewhat "complicated".

    I'm basically looking for something like the equivalent to the approach on this website: http://electrosofts.com/serial/ which communicates through the port using something like

    Code:
    #include <bios.h>
    #include <conio.h>
    #define COM1       0
    #define DATA_READY 0x100
    #define SETTINGS ( 0x80 | 0x02 | 0x00 | 0x00)
    int main(void)
    {
       int in, out, status;
       bioscom(0, SETTINGS, COM1); /*initialize the port*/
       cprintf("Data sent to you:  ");
       while (1)
       {
          status = bioscom(3, 0, COM1); /*wait until get a data*/
          if (status & DATA_READY)
               if ((out = bioscom(2, 0, COM1) & 0x7F) != 0)  /*input a data*/
                  putch(out);
               if (kbhit())
               {
                  if ((in = getch()) == 27)   /* ASCII of Esc*/
                     break;
                  bioscom(1, in, COM1);   /*output a data*/
               }
       }
       return 0;
    }
    Would anyone know a similar approach I could take using my Mac OS X?

    Thanks again
    Last edited by Mini; 11-23-2011 at 08:25 AM.

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    While I am no expert on Macs, I do believe you will need some kind of driver for your adapter. You should make sure that the adapter you purchase has support for your Mac OS. Hopefully the driver will already be included by your OS and you will not need to load the supplied drivers, but a driver is required.

    Please note the code you posted is problematic. That software was designed to run under MSDOS. Trying to use Bios calls will only work reliably with MSDOS, even most modern Windows versions do not always properly emulate these bios calls correctly. It will definitely not work with any version of the Mac OS.

    Jim

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    mac osx serial howto - Google Search
    I don't know what search terms you used to get that ancient DOS/BIOS code for a PC, but you really need to work on your search terms if that's the best you could find.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Serial RS232 + OpenGL (multithread+Serial Comm)
    By manatttta in forum C Programming
    Replies: 3
    Last Post: 10-15-2011, 01:33 AM
  2. beginner question about interfacing with a rs232 device.
    By luxeomni in forum C++ Programming
    Replies: 1
    Last Post: 08-08-2011, 04:49 PM
  3. RS232 serial port library for Linux and Windows
    By Theodoor in forum Networking/Device Communication
    Replies: 8
    Last Post: 09-26-2009, 06:45 AM
  4. codes for com port Rs232 in serial communication
    By justinwandji in forum C++ Programming
    Replies: 1
    Last Post: 06-05-2009, 01:33 AM
  5. Send and Recive Information through the serial Port RS232
    By amigoloko in forum C# Programming
    Replies: 4
    Last Post: 04-14-2006, 12:34 PM