Receiving serial string and displaying it on LCD

Hello!

I have one very old device which send me serial string via serial port, it's normal 8bit, 9600baud 2stop bits.......and when units send something it send HEX character what is sending (i need to have two displays, or big display with two rows, not mather how hardware is solved...)

So when i monitor serial communication i got something like this:

85 C9 C3 D3 A0 AA AA AA AA 83 C0 FF FF FF FF 85 83

Thing is, when there is HEX 0x85 that means that all 8 bit characters after it are ascii letters that need to be displayed in first display, and when there is 0xC0 it means that four HEX after needs to be display on second display.

Basicly i know how thing is working, but since till now my programming was mostly displaying, timers, automation, keyboard reads etc.....newer had task to work with sommunication. As i can see, i should use read serial string, than somehow parse this value in some char register depending on HEX string first byte (83 or C0).

So i am here to ask for some example and what would be good aproach to do this.

thanks!

Here is a thread on receiving serial data and parsing the data. Once you have the whole data packet, it is easy to look at the first character (byte) and decide what to do from there.

And nothing sends HEX. It sends binary. The incoming data can be represented in HEXadecimal, DECimal, BINary, ASCII text. That is for humans to read, the data is binary.

So when i monitor serial communication i got something like this

How are you monitoring it? Is that data '8', '5', ' ', 'C', '9', etc., or is it 85, C9, etc.

As i can see, i should use read serial string, than somehow parse this value in some char register depending on HEX string first byte (83 or C0).

I don't understand what you mean by "parse in some char register".

Read the data as it arrives, one byte at a time.
If a byte is 85, set a flag, display1 to true. Set display2 to false.
Else, if the byte is C0, set display1 to false. Set display2 to true.
Else
If display1 is true, send the character to display 1
Else if display2 is true, send the character to display 2
Else, send the character to the bit bucket.

First, yes all data are binary.

Data are comming like i wrote, so 0x85 0xC0, 0XFF etc.......

will read post with examples, will try to figure out something

I don't think the examples in my Serial Input Basics are immediately suitable for this application. They assume an identifiable end-marker whereas this data seems only to have start-markers - and there are two different start markers. I guess the code could be adapted.

But the system that @PaulS has suggested will probably be simpler.

...R

I have end markers on some strings and on other no, but i think all are same size, so everytime i receive start marker i can chose lenght of string so i think it will work that way? If string which start for example with 0x67 has 12 ascii characters (12 bytes) and other which starts with 0xC2 has four bytes i can set length to 4 or 12 and after that all will be discarded untill start marker is received again and another 12 or 4 bytes are read after ot depending on chosen size.

It does not look like your data contains any ascii characters; the ascii table ends at 0x7F.

So I'm actually not sure how string (text) comes into play. Am I missing something?

marinbnm:
so everytime i receive start marker i can chose lenght of string so i think it will work that way?

That can work. And it would probably be quicker and more effective to write a short test program than to ask questions here. If your test program does not work exactly as you want then we will have something more definite on which to base suggestions.

...R

sterretje:
It does not look like your data contains any ascii characters; the ascii table ends at 0x7F.

So I’m actually not sure how string (text) comes into play. Am I missing something?

True, but thing is that unit sends me only lower 7 bits as data for display, first MSB bit is always 1, i have idea how to handle that.

But first i will wrote test program and see will it work, and probably come back with questions :slight_smile:

Your data that you presented might consist of 3 blocks.

Start with 0x85 and it is text up to 0x83
2)
Start with 0xC0 and it's 4 bytes
3)
See (1), it's an empty text in this case

Below might have a meaning (or not)
0x85 -> 0x05 -> ascii ENQ (enquiry)
0x83 -> 0x03 -> ascii ETX (end of text)
0xC0 -> 0x40 -> the '4' might indicate 4 bytes binary data

You have only presented data to us; do you have any idea about the protocol of your device? Can you tell us what the device is?