LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Serial asychronous communication with a start and end character for each frame of the message

Hello,

I have an application which must read the serial port to get data from a device. In my application I must identify each frame of the message I receive with a start and an end character (protocol TCP/IP  RFC 1055). This character is "CO" in hexadecimal for begging and end of the frame(C0_data_C0). To get the beginning of the frame I use the VISA Wait on event, with the event "Serial Termchar". The problem comes when it arrives at the port the end of a frame and the beginnig of the following, then I get two "C0" straight, and my application reads only "C0". So I get a good iteration with the message right, and a bad iteration with only "C0" the whole time.
How can i make so that "Wait on evet" can detect the "C0" twice, or detect it once and discard the other?

I would be very grateful if you can help me.

Thank you

Bye
0 Kudos
Message 1 of 4
(4,201 Views)
I think you already answered yourself. You detect a start frame by waiting and getting a single C0. Then, you wait again in the same iteration, obtaining the rest of the frame with the final C0. There is nothing wrong in this.
Of course, there are different approaches: for example, you may read one char at a time, concatenating them in a string: when you receive a C0, you examine the collected string: if not empty, it's a frame body. Then you reset the collected string and continue.
Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 2 of 4
(4,190 Views)
Hi pinc panter,

the problem with the events is that they function in parallel with the execution of the application, so I cannot put two events one after the other. It doesn´t work. So far, I have put one "wait on event" for the beginning of the frame, and then inside a while loop, I´ve put an algorithm which looks if the next character is a C0 character or different, so if I find a C0, it will do another iteration in the while loop until it finds a character different of C0. It works fine, but now I´m having problems wiht the timing. It seems that I have to synchronize the velocitiy with which messages are sent with the velocitiy of my application, so I do not lose any frame. Thank you for your interest, and if you have any idea it will be welcomed.

Fran
0 Kudos
Message 3 of 4
(4,173 Views)
Actually, I did not use VISA events for this kind of management; I rather set a termination character (in this case, C0) and did a simple Read operation with a large number of characters (> of the message I'm waiting for). I don't know if this can fit your need, but i think so; certainly, it's simpler than using events, because in a single node you wait and receive your datagram. VISA events are more powerful, though, and maybe you need their flexibility.
Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 4 of 4
(4,171 Views)