LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Data Loss in Serial Read Using Labview Visa

Solved!
Go to solution

Dear

I am a student major in Mechanism Engeering, and my English is not very well....sorry for my poor English.

I try to read the JY61 data from UART using Labview Visa. The specific description of JY61 is in the attached PDF file. (mainly focus on Page 9-10)

I modify the example "Continuous Serial Write and Read.VI".

The data format is 33byte, and begain with 55 51.  I set the read byte of Visa Read is 33, however, the data missing sometimes. 

The code is attached. 

This issue bothered me more than three weeks. Could anyone give me some advices? Thank you very much!

Download All
0 Kudos
Message 1 of 5
(1,912 Views)
Solution
Accepted by topic author Tianci

You need to set the termination character to False.  It seems like you are receiving binary data, which means any of the values from 0-255 are possibly valid data.  If you have to get a byte of value 10 decimal (the default termination character of line feed), your message will come up short, and anything after that line feed character will show up in the next VISA read throwing everything out of whack.

 

Also, why are you taking two string constants and concatenating them together?  Just put 5152 in to a single constant and you can eliminate 2 out of the 3 nodes!

Also, when a string constant is set to a mode other than normal, you should make the display style visible so it is obvious to the programmer and others reviewing the program that it is set for hex style.

Message 2 of 5
(1,903 Views)

I set the termination character to False, and it works.

Thank you very much!

0 Kudos
Message 3 of 5
(1,886 Views)
Solution
Accepted by topic author Tianci

I have other concerns such as what if the first package you read was actually the velocity packet instead of the acceleration packet or what if you start reading in the middle of a packet.  You need much more robust code to handle these situations.  Here is the start of what I recommend.  The idea is that you read 1 byte until you read the 0x55.  Then you read 1 more byte to determine which packet you are reading.  You can then read the rest of the packet based on the data, verify the checksum, and (if the checksum passed) parse the data for that packet.

NOTE: The VI was saved in 2017, snippet is in 2019.

NOTE 2: I only set this up for 1 of the packets.  You need to duplicate the packet ID case structure for each packet you could read.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Download All
Message 4 of 5
(1,879 Views)

Thanks for your reply.

It is true that sometimes start reading in the middle of a packet. And I use the Match Pattern to match the 55 51  and then merge the preceding and subsequent strings. It is very lax, and I will remodify the code based on your suggestion.

Thank you very much!

Tianci_0-1595253005882.png

 

0 Kudos
Message 5 of 5
(1,867 Views)