LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

Building Robust Serial Drivers

Building Robust Serial Drivers

I've searched this topic, and haven't found anything meaningful online (but would be happy to read if anyone has a resource). I'm dealing with an issue right now where an instrument I'm using is pretty consistently dropping the first 5-20 bytes in a 700 byte transmission. The serial driver I'm using for a read is here:

lsYgzuZ

 

I've checked and double checked the baud, timeout, termchar, flow control etc and it all checks out. If it weren't, I wouldn't expect to get any data at all, but the drop of bytes only occurs about 47% of the time.

How do you all do robust serial comms?

0 Kudos
Message 1 of 5
(253 Views)

Re: Building Robust Serial Drivers

It is strange that it is at the beginning where you are dropping data. Could it be that the buffer is filling up too quickly so the oldest data is lost?

 

Are you running this read VI immediately after writing something to the device?

Maybe move your "milliseconds to wait" to the end of the loop so that it reads data right away.



CLA // LabVIEW 2016 // BALUG // Unofficial Forum Rules and Guidelines
0 Kudos
Message 2 of 5
(227 Views)

Re: Building Robust Serial Drivers

That's an interesting idea. The device is at 9600baud, so the transfer time is almost 700ms, which may lend some credence to that theory. I have confirmed that the device itself does not drop data using a logic analyzer. The wait before the read is there so that the data has time to come into the port. I'm exploring another option right now that doesn't involve error clearing.

0 Kudos
Message 3 of 5
(224 Views)

Re: Building Robust Serial Drivers

As it has been said many many many times on this forum

 

DON'T USE BYTES AT PORT!

 

If the device you are communicating with has a termination character (always ends with the same character) USE IT!

 

Use the VISA serial config to enable the "term char", and set it to the proper character.

 

Then set the VISA Read to read way more bytes than you expect to receive.

 

Now the VISA read will read until it sees the termination character or times out.

-------------------------------------------------------------------
Unfortunately, most readers of this Forum, including some real Experts, have not mastered the skill of being able to read the code that Posters fail to post. If we cannot see "what you did wrong", we are unable to tell you how to fix it. (Bob Schor 28 August 2018)
0 Kudos
Message 4 of 5
(215 Views)

Re: Building Robust Serial Drivers

BTW: your "milliseconds to wait" is what is probably causing you to lose that first chunk of data.

-------------------------------------------------------------------
Unfortunately, most readers of this Forum, including some real Experts, have not mastered the skill of being able to read the code that Posters fail to post. If we cannot see "what you did wrong", we are unable to tell you how to fix it. (Bob Schor 28 August 2018)
0 Kudos
Message 5 of 5
(212 Views)