LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Serial read LabVIEW: Error overrun

Solved!
Go to solution

I have to read  bytes from a PCB board, which is sending 20bytes every 10ms. The 20 bytes have a protocol attached to it, so I am confined to read a single byte at a time. 

 

Because of this I am getting at overrun error. I played with my buffer size and increased it, but no luck. The baud rate is 115200. 

 

Is there any other way, I could modify my program, so I wont face this problem? 

 

Please find attached

0 Kudos
Message 1 of 13
(3,841 Views)

Hi looser,

 

which is sending 20bytes every 10ms.

This one is ok!

 

The 20 bytes have a protocol attached to it, so I am confined to read a single byte at a time. 

Why? Can you explain this sentence?

 

Is there any other way, I could modify my program, so I wont face this problem? 

Sure!

Read the full message with just one VISARead function!

 

- You configured the serial port to use the default TermChar. Does your "PCB" send messages terminated by a LF char? If that is the case you should simply call VISARead with 32 bytes to read: it will give you the full message!

- Parse the message once you read it. You can use any string or array function to do so!

 

Recommendations:

- Use Autocleanup more often!

- Always show the display mode indicator for strings (and numbers), when you don't use the default display mode!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 13
(3,831 Views)

Protocol to identify the corresponding bytes. 

The header, length, data, check sum and a dummy value. 

 

The header is important to identify the start of the message, length gives the lenght of the data I want to read, data is say the values I want to read (for example say a sine wave), next chk sum to ensure the length and data is interpreted properly, dummy value is just an additional byte for future use. 

 

I dont want to read the full message at once, as I want to keep checking the header, length and chksum regularly to ensure the proper message. Reading the full message will void me of this checking and I would not have an idea, if the info is good or not. I dont have a termChar. So I left it blank.

 

 

0 Kudos
Message 3 of 13
(3,825 Views)
Solution
Accepted by topic author looser_engineer

Hi looser,

 

I dont want to read the full message at once

But that will improve processing speed quite a lot and will avoid buffer overruns!

 

as I want to keep checking the header, length and chksum regularly to ensure the proper message.

You can do this with full messages too!

 

Reading the full message will void me of this checking and I would not have an idea, if the info is good or not.

Why do you think so???

 

I dont have a termChar. So I left it blank.

Then you should configure the serial port differently: you need to disable the TermChar! Please read the LabVIEW help for this function!!!

 

For reading a datastream from serial port you should do like this:

- Read a block of bytes like 20 chars from the port

- append those 20 chars to previously read data

- search for your "Start of message" char in the collected stream data

- split the collected string at that marker, anything before that marker is an older message, anything after will be the next message!

- keep appending new chars by starting this algorithm over!

-

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 13
(3,822 Views)

I see your bullet points. Won;t it be too much math?

Could you please post a VI to read say 20 bytes and save it in an array ? Preferably converted to Decimals

 

With NO While loop

0 Kudos
Message 5 of 13
(3,816 Views)

Hi looser,

 

Won;t it be too much math?

No…

At 115200baud you will receive at most 11500 bytes/second. At 20 bytes/message this will be less than 600 messages per second: any modern computer can handle this!

 

Once you have your message (of 20 chars) you can stuff it into a queue and use a producer-consumer-scheme to parse them. This will decouple the communication loop from your "hard math" loop and will improve performance even more…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 13
(3,798 Views)

I was thinking something like int he attached file would work?

0 Kudos
Message 7 of 13
(3,794 Views)

Just a rough sketch…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 8 of 13
(3,788 Views)

I updated my similar to your suggestions and probably employ the data manipulation soon. However I am still getting the error over run when I initially start the code. The error shows up for first two iterations and the code works like a charm after that. I believe it is because I did not close the port. Could you comment please?

0 Kudos
Message 9 of 13
(3,772 Views)

Hi looser,

 

I believe it is because I did not close the port.

Yes!

 

- You also forgot to implement any error handling at all!

- Calling VISAClear before opening/configuring the serial port is kind of silly…

- You still have not implemented my suggestions from above regarding display modes of string (and numeric) constants!

 

Another suggestion:

When your loop should run as fast as possible you should not update any indicators in your loop. What's the point of displaying "header, length, data" in a string indicator when those strings will rush in at ~1500 updates per second?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 10 of 13
(3,728 Views)