LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Why would bytes at port read 0?

I'm writing a command to a com port write VI, writing to a Nordic Bluetooth board, and then reading responses from a com port read VI. The com port read VI works 95% of the time and I get bytes read back and responses, but there is 5% of the time where I get 0 bytes at port read, and the only fix for it is restarting the Nordic Bluetooth board. This problem only happens when I use labview as an interface for writing commands to it and not when I use other software interfaces. Any ideas on why my VI won't read any bytes at port that 5% of the time? Thanks.

0 Kudos
Message 1 of 4
(2,753 Views)

You really should NOT be using the Bytes At Port.  How do you know you got the full frame of data?  What exactly is the format of the data you are trying to read?  There are likely MUCH better ways such as relying on a termination character.



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 2 of 4
(2,736 Views)

On a side note, why change the display style of an indicator of a subVI?

0 Kudos
Message 3 of 4
(2,655 Views)

The "simple" answer to your question, why would Bytes at Port be 0, is that there are no bytes at port.  Why should there be any?  Well, probably you previously sent a Command to the Device (through VISA) to give you some data, so you expect to see data.  What if your Device is "slow", and takes 100 microseconds more time to get those data to you than it takes your LabVIEW code to ask if there are any Bytes at Port?  The answer might well be "not yet, give me another 20 microseconds" ...

 

A Better Way is to "know" something about what VISA is going to give you when you request data from it.  Many VISA devices can be set to terminate their messages with a "Termination Character", the most common being <LF> (0xA).  You can configure a VISA Read to "Read N Bytes or until you see a Termination Character", and then tell VISA to read 1000 bytes (or some number that you know will be longer than any message).  Now VISA will wait, if necessary, for the Message.  But what if the Device has "died" and give you no message?  That's the purpose of the VISA TimeOut (often 10 seconds), to detect just such an Error condition.

 

Bob Schor

Message 4 of 4
(2,628 Views)