07-18-2019 02:28 PM
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.
07-18-2019 02:48 PM - edited 07-18-2019 02:48 PM
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.
07-19-2019 02:55 AM
On a side note, why change the display style of an indicator of a subVI?
07-19-2019 08:49 AM
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