LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

missing data with rs232

Solved!
Go to solution

Dear expert,

 

I suffer missing data for RS 232 problem for 3 years. I do not know what I did wrong.

Our company develop a product called EVC. All the LabVIEW code I wrote need to communicate with EVC. I need monitor EVC performance for long time which usually longer than 8 hours. Every once a while I lost some data. The code I have is very large. In order to focus on my problem. I made this simple code to show my problem. This program asking EVC reading. I plot this first reading in the chart. I should read 437 all the time(fig1).

Every once a while I have 0 reading(fig2) :

I dig into my subVI. Here is what I found.

Here is normal screen shot(fig3):

 Every once a while, I have 0 reading. When I have 0 reading, EVC still provide data, but slower. It break into something like below(fig4&5) :

How do I prevent this happen? If I can not, how do I deal with this? Any suggestion will be great appreciate.

 

Best regards,

Victor Huang

0 Kudos
Message 1 of 16
(5,973 Views)

I'll make a quick guess and say that because you use bytes at port and you do a one-time read, sometimes not all the data is there and you move on.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 2 of 16
(5,963 Views)
Solution
Accepted by topic author VictorHuang1

Hi Victor,

 

- using BytesAtPort combined with wait functions is almost always wrong and leads to FAIL…

- using a while loop with a stop condition like "i>1" makes me ask "Why not use a FOR loop?"

- there is NO error handling in case something got wrong with serial communication: you plot new values regardless of the error state…

- you switched off the TermChar, but your device seems to answer with readable ASCII data: does your device REALLY don't use any TermChars? In your images there is a ">" char marking new lines…

- you are using ArrayToCluster followed by Unbundle for 3 years now? Instead of a simple IndexArray function?

- you don't use shift registers for the "Counts" value? Why?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 3 of 16
(5,959 Views)

Thanks for quick reply! What's your suggestion? Could you please kindly give me some direction to try? Yes, I do use bytes at port and one-time read. Could you please kindly guide me different way? Thanks in advance.

 

0 Kudos
Message 4 of 16
(5,956 Views)
Solution
Accepted by topic author VictorHuang1

Hi Victor,

 

What's your suggestion?

- check the manual of your device

- use a TermChar when possible

- read as many bytes as your messages contain - or more, when you use a TermChar

- implement some error handling

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 16
(5,952 Views)
Solution
Accepted by topic author VictorHuang1

BYTES AT PORT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Smiley Mad

 

My friend, you have a race condition.  If the device is slightly slow, you could have nothing at your port and read nothing.  So the stupid simple, non-ideal, solution is to increase your delay.  However, from what I can gather from the screenshots and code, the EVC is ending all of its transmissions with a Carriage Return (0x0D).  So the PROPER solution is to use the termination character.

 

1. In your configureSerialEVC.vi, set the Enable Termination to TRUE and the termination character to 0xD (default is 0xA, or Line Feed).  I would also add a property node and set theMessage Based Settings->Send End Enable to TRUE for the VISA reference.  This will have VISA automatically add your Carriage Return to the write data, eliminating the need for you to concatinate it yourself.

 

2.  Now where you do the Write and Read, remove the waits and the Bytes At Port.  Instead, have the VISA Read to read more bytes than you ever expect in a message (I typically use 100).  The VISA Read will stop reading when a) the termination character is read (assuming you enabled the termination character), b) the number of bytes you specified are read, or c) it times out (which will give you an error).  So by setting the bytes to read really high, you will depend on the termination character to end the read.  What this does is a) ensure you got a complete line and b) give you the data faster and c) be a lot more reliable.


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
0 Kudos
Message 6 of 16
(5,948 Views)
Solution
Accepted by topic author VictorHuang1

I don't think this loop is working in the manner which you expect.

Clipboard01.png

When the loop is initially entered, two things happen pretty much simultaneously. The 250ms timer is started and the number of bytes available at the serial port is obtained. The next thing that happens quickly is that a read of the serial port occurs and only the number of available bytes (including zero bytes) is done. The loop then waits until the 250ms timer times out and repeats. When the second (final) loop cycle starts, the same thing happens again. The timer starts along with a serial-port read of any available bytes (including zero) and then the loop waits for the timer to finish.

 

If your EVC device always terminates its responses with a unique termination character, then it would make most sense to configure the serial communications to use that termination character, set the serial timeouts sufficiently long and dump the use of the serial-bytes-available property. Otherwise, you might want to consider reworking your VI to wait until one or more bytes are seen at the port and then wait long enough for all bytes to be received before again getting the bytes at port followed by the read. 

 

EVC_pdat1_troubleshooting2.vi.png

0 Kudos
Message 7 of 16
(5,932 Views)

Hi Gerd,

 

Thanks a lot for your quick response. That's very helpful. I followed your suggestion and fix all the problem. Thanks a lot.

 

Best regards,

Victor

0 Kudos
Message 8 of 16
(5,835 Views)

Hi Crossrulz,

 

Thanks for your great detail. It help me a lot. I highly appreciate your great suggestion. I implement all your suggestion. It solved my problem.

 

Best regards,

Victor

0 Kudos
Message 9 of 16
(5,833 Views)
Hi GerdW, Your suggestion reduce my problem. In the pass, I got data loss around every 100 data. The new code is around every 1000 I loose 1 data. Can you help me further improve my code? Thanks in advance.
0 Kudos
Message 10 of 16
(5,793 Views)