ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
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:
ffffffc0 (not a correct value for the received character. My programm takes this as -64 (float))
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?
I have written many program of this type. My first question is what does your frame look like and what are you talking to. Different architectures store integer and floating point numbers in different formats. For integers I often have to swap bytes around get the correct values. For floating point numbers, conversions can be far more complex depending on how the two architectures represent these numbers in memory.
Point of clarification - ffffffc0 (not a correct value for the received character. My programm takes this as -64 (float))
ffffffco is four bytes or characters, you use the singular form of character making it dificult to interpret you question.
Integer values vary depending of the data to display. For example, dates and time are directly represented by the hex value of the byte (MM/DD HH:MM = HEX1/HEX2 HEX3:HEX4).
In general everything works OK. I can read coherent values and calculate its correspondant integer/float. The problem appears in some specific bytes.
Indeed, ffffffc0 should be a single byte and not four bytes. My program takes this byte and interpretes it in a wrong way. Capturing bytes into an unsigned char string transforms this byte into "c0", but again this is not a correct value. But before continuing with this question, I need a good serial monitor in order to spy the RS232 frames. I'll post my results then.
I've declared the string as unsigned char. It takes now positive values although I still have some reserves about the coherence of the information. Anyway, next time I'll remember to capture strings in an unsigned char format.