From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
03-19-2015 05:36 PM
Hello,
I am trying to acquire data from a device via serial communication. Now the device will only output information when the event occurs. I know i can stop the visa read from timing out, but then the program will be constantly in a hang state until the read is made. Is there a better way to do this than sit and wait for the string to come through the port?
THank you,
Solved! Go to Solution.
03-19-2015 05:46 PM
This is one of the few places where the Bytes at Port property node is useful. Poll that property until the data is present and then read.
Lynn
03-19-2015 05:49 PM
I can read the data coming from the device, but the device wont send it that often, or it may be at random times. But i dont want to have a high timeout value or to have a timeout error because its just waiting for data if that makes sense. Do you have any example of this?
03-19-2015 05:50 PM
Or keep reading with a short timeout and ignore the timeout error (no data received) and then post-process the received string (as it might come over multiple reads).
03-19-2015 05:56 PM
Please post the VI you are using to read (Make current values defualt and save first) and someone can show you how to modify it using the methods which have been suggested.
Lynn
03-19-2015 06:03 PM
Here is the basic read i am using. Im just starting to experiment with the read from this device.
03-19-2015 06:26 PM
You are using a termination character. This is good because it makes it easy to get complete messages. Normally you would not use Bytes at Port and termination characters at the same time because they tend to fight each other.
In this modification to your VI it checks bytes at port. If the value is zero it waits 100 ms and checks again. The 100 ms is arbitrary. If you need to detect a response from the device faster than that, the value can be reduced. It make no sense to reduce it below about 16 ms if that is the length of the messages because it akes about that long to transmit 16 bytes. Once the number of bytes is greater than zero it calls the VISA Read which will wait until the termination character is received.
It is not a good idea to have a while loop which runs forever. If you are using the Abort button to stop the program, STOP. Stopping that way does not allow closing the port and can cause complications. A long time Forum participant once said something like this: Using the Abort button to stop a VI is like using a tree to stop a car. It works but may have unintended consequences.
Lynn
03-19-2015 06:32 PM
Lynn,
Thank you. This is exactly what i was looking for. If i want to remove the byte count becuase im using a termination character how would i do that? Im not very familiar with serial communication, is this a good method to use when communicating between two devices? is there a more effective way to do it in labview?
Matt
03-19-2015 06:45 PM
Matt,
For your situation where the interval between messages can be longer than the timeout, using Bytes at Port as in the modified VI is fine.
If the messages always come faster than the timeout, then your original VI (with Stop button and VISA Close) is OK. You could also increase the timeout but that makes it very difficult to stop the VI in an orderly manner.
It seems that every manufacturer of devices which use RS-232 communication has its own idea of what protocol to use, so there really is not a "standard" or "always works" method. Each situation has to be evaluated as it comes along.
Lynn
03-19-2015 06:48 PM
I understand what youre saying, that the read has to be setup for the write, but everyone is different.
THank you for your help, this saved me a headache.