Tender Gherkin
Tender Gherkin

Reputation: 3

Serial port readfile() with what type of parameter out? in C/C++

I spent a long time finding out the actual origin type of data sent out from the serial port. Since I want byte by byte data, I cannot see he correct answer if I just use a char[] buffer to read!

Upvotes: 0

Views: 288

Answers (1)

mathematician1975
mathematician1975

Reputation: 21351

You just write bytes into the serial port. When reading them back on the receiving end just read into an unsigned char buffer. To correctly interpret the data, you need to know how it was structured when it was sent. This is usually specified by some kind of protocol so that you can detect the end of transmission (an example is Modbus protocol). Provided you know the structure of the packet of data you receive (as well as the endianness for interpreting multi-byte integers and floats for example) you should have no problems reinterpreting the data that you receive as a raw byte array. You question is a little unclear, but this is what I inferred that you are asking about.

Upvotes: 1

Related Questions