Termios Flags Rs232 Serial Ttys0 Modbus Rtu

This is a discussion on Termios Flags Rs232 Serial Ttys0 Modbus Rtu within the Linux Programming forums, part of the Platform Specific Boards category; Hi, I'm writting a program to send and receive data through a serial rs232 line. In the future this program ...

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    2

    Wink Termios Flags Rs232 Serial Ttys0 Modbus Rtu

    Hi, I'm writting a program to send and receive data through a serial rs232 line.

    In the future this program will comunicate with a modbus field device and be able to store data in a sql database.

    Right now, i'm trying to figure out the MODBUS communication, i have tested CRC code implementation successfully, and i'm able to write and read from the serial line.

    However, when i read from the serial line, i can't get unsigned char bytes in rtu mode. I can only get ascii charachters. ie. instead of getting 0x84 i get 0x04

    When i write i dont get the same error.

    Now, i don't think its the type of my variables what its causing the program to miss the most significative bit.

    I made this test with good results:

    ~:make, and run './' the binary (lets call it "my program"), stopped "my program" and run minicom in the foreground, set the baudspeed, parity and number of bits in minicom, then stopped minicom, got my program to the foreground. After this my program received ok (0x84 is 0x84 ). !!!!

    Im using this values for my flags:
    termios.c_cflag = 0x9bd;
    termios.c_ifalg = 1;
    termios.c_lflag = 0;
    termios.c_oflag = 0;

    WHAT MAY BE CAUSING IT? , im going crazy here lol , please give me a hand.

    I almost forgot: Excuse my english is very hard to translate after 28 hours of work. :P
    Last edited by Mighty-D; 10-31-2006 at 09:40 AM.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,659
    > termios.c_cflag = 0x9bd;
    Where did you get that magic hex number from?

    It certainly isn't portable, since each implementation only defines constants for say baud rate, not actual bit patterns.

    > instead of getting 0x84 i get 0x04
    http://www.rootr.net/man/man/termios/4
    Read about this bit
    ISTRIP /* strip 8th bit off chars */

    > after 28 hours of work
    I suggest you get some sleep then.
    Trivial problems are plainly obvious with a good rest break.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    2

    Thumbs up Thank You

    Thank you, ISTRIP, i had miss read this flag in the termios, now its working fine!

    You can't imagine how gratefull i am!


    thanks again, and a lot.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. codes for com port Rs232 in serial communication
    By justinwandji in forum C++ Programming
    Replies: 1
    Last Post: 06-05-2009, 01:33 AM
  2. Read and display signel serial mouse RS232 in C
    By zebres in forum C Programming
    Replies: 1
    Last Post: 03-22-2009, 09:09 AM
  3. 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
  4. Please help with serial communication problem - Long
    By spdylude in forum Windows Programming
    Replies: 3
    Last Post: 04-06-2005, 09:41 AM
  5. rs232 serial driver
    By GreyMattr in forum C Programming
    Replies: 2
    Last Post: 03-20-2002, 11:55 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21