Thread: Serial Ports

  1. #1
    Registered User
    Join Date
    Jan 2002

    Exclamation Serial Ports

    Hi, everybody,

    Does anyone know how to read data from a serial port (RS232)?
    A tried to use open and read commands.
    It seems that the open command worked well, but the read command always returns -1.
    This is how I used them:
    fd=open("/dev/ttyS0",O_RDWR | O_NOCTTY | O_NONBLOCK);


    I'm trying to test this with a serial barcode scanner.

    If there is anyone who can help me, I'd be very grateful.



  2. #2
    Registered User
    Join Date
    Jan 2002
    It depends what type of operating system environment that your program is running on.

    If you are using windows then look for microsoft doc on the WIN32 comm API. A better method would be to buy a 3rd party communication package that know the intricies of the comm API such as the Sysfire/Greenleaf comm libraries.

    I'm sorry that I can't supply you with info on serial comms on other operating systems.


  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    > O_NONBLOCK);
    Well unless you have already scanned something, your read call will return immediately, whether there is any data or not.

    Either remove the NON_BLOCK and let read just wait until there's something on the port, or surround the read with a loop to continually monitor for possible input.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. virtual ports
    By royuco77 in forum Networking/Device Communication
    Replies: 5
    Last Post: 07-02-2005, 10:33 AM
  2. How do you send and recieve info from serial ports?
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 06-29-2002, 12:13 PM
  3. Polling serial ports
    By Nevyn in forum Windows Programming
    Replies: 3
    Last Post: 06-12-2002, 03:02 AM
  4. Need a hand accessing the serial ports
    By Danwood13 in forum C++ Programming
    Replies: 3
    Last Post: 04-24-2002, 10:03 AM
  5. Serial Ports
    By SavesTheDay in forum C Programming
    Replies: 4
    Last Post: 02-04-2002, 03:52 PM