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.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Serial Communcation Protocol

Solved!
Go to solution

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,

 

 



-Matt
0 Kudos
Message 1 of 10
(3,113 Views)

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

0 Kudos
Message 2 of 10
(3,109 Views)

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?



-Matt
0 Kudos
Message 3 of 10
(3,103 Views)

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).


LabVIEW Champion, CLA, CLED, CTD
(blog)
0 Kudos
Message 4 of 10
(3,101 Views)

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

0 Kudos
Message 5 of 10
(3,095 Views)

Here is the basic read i am using. Im just starting to experiment with the read from this device.



-Matt
0 Kudos
Message 6 of 10
(3,090 Views)
Solution
Accepted by topic author Wolleee

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

0 Kudos
Message 7 of 10
(3,083 Views)

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



-Matt
0 Kudos
Message 8 of 10
(3,078 Views)

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

0 Kudos
Message 9 of 10
(3,074 Views)

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.



-Matt
0 Kudos
Message 10 of 10
(3,069 Views)