Thread: Serial Port - Problem with binary frames

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    4

    Serial Port - Problem with binary frames

    I'm developing a program in C that comunicates with a RS232 device. I'm using the POSIX method in order to access the ttyS0 device, as described in the Serial Programming HOW-TO.

    The external device uses a binary protocol, so it's been hard to debug. The problem is the following:

    My programm receives data from the RS232 device but some of the received characters are interpreted by Linux as negative hex values. For instance, I receive:

    01 (OK)
    0a (OK)
    15 (OK)
    ...
    ffffffc0 (not a correct value for the received character. My programm takes this as -64 (float))
    00 (OK)
    ...

    And here my questions:

    1 - I don't know any good serial monitor or sniffer for Linux. What do you recommend me? Remember that I'm working with binary frames. I really need this tool.
    2 - Could my problem have something to do with the termio configuration?

    Here you have my settings:

    newtio.c_cflag = BAUDRATE | CRTSCTS | CS8 | CLOCAL | CREAD;
    newtio.c_iflag = IGNPAR | ICRNL;
    newtio.c_oflag &= ~OPOST;
    newtio.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
    newtio.c_cc[VTIME] = 0;
    newtio.c_cc[VMIN] = 1;

    Any idea?

    Thank you very much.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > ffffffc0 (not a correct value for the received character. My programm takes this as -64 (float))
    Using unsigned char rather than char as your receive buffer would help.

  3. #3
    Registered User
    Join Date
    Jan 2006
    Posts
    4
    Thanks Salem.

    unsigned char seems to solve my problem.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Send image (.jpg) file over serial port
    By aSpareName in forum Networking/Device Communication
    Replies: 2
    Last Post: 06-30-2009, 09:35 AM
  2. Can Only Read From Serial Port in Function That Opened It
    By HalNineThousand in forum Linux Programming
    Replies: 6
    Last Post: 03-22-2008, 09:35 AM
  3. Can't Read From Serial Port
    By HalNineThousand in forum Linux Programming
    Replies: 14
    Last Post: 03-20-2008, 05:56 PM
  4. Reading and writing to a serial port
    By SwarfEye in forum C Programming
    Replies: 2
    Last Post: 08-18-2006, 12:28 AM
  5. need guidance to connect to serial port
    By gnychis in forum Linux Programming
    Replies: 1
    Last Post: 06-02-2005, 10:10 AM