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 Communication only works in Highlight Execution

I have searched through the forums and have found similar issues but none of the solutions have solved my problem.  In my VI, I have an array of bytes which I convert to strings and send via serial communication to my device.  The device will respond with some bytes (variable lengths).  I can read some of the response if I wire "return count" of the "VISA Write" to the "byte count" of the "VISA Read," but the responses are longer than the sent messages so some of the data gets at the end gets cut off.  So I found the "Bytes at Port" function and tried to implement it, but I found it only works in Highlight Execution.  When I don't run in Highlight Execution, I get no response from the device but it I know the transmit went through because the device responds to the messages sent.  I've tried adding a sequence structure putting the "Bytes At Port" in the first frame and the "VISA Read" in the second frame but that didn't work.  I also tried adding the while-loop and case structure that was in the thread by the user Seppfish but that had the same affect as wiring the "return count" of the "VISA Write" to the "byte count" of the "VISA Read."
 
I've attached my VI, hopefully someone can help.  Thanks.
0 Kudos
Message 1 of 9
(4,576 Views)

You're assuming that the device will respond instantly with some response. If there is no data immediately there when you run the VISA Bytes at Serial Port, you just go on and then send the next command. What highlight execution does is slow things down by quite a bit so you are giving the device time to respond. What you could do is put a fixed delay after the VISA Write. More elegant and robust is to put the VISA Bytes at Serial Port in a loop. When the byte count is greater than zero, exit the loop. Then in another loop, keep reading until a VISA Bytes at Serial Port says that available bytes is 0.

You also need to set the termination character enable to false with the VISA Initialize Serial Port. And please, clean up that wiring where you convert to a string for the VISA Write. Wires should go from left to right.

Message 2 of 9
(4,569 Views)
Hi Dennis,
 
I was just reading the announcement of your knighting - and then I see you reply to my post! I feel honored.  So I tried to implement what you suggested but it is still not working.  Now it just hangs.  What am I doing wrong now?  
 
Thanks.
0 Kudos
Message 3 of 9
(4,555 Views)

The first thing to do is to determine which loop is running. Put a probe on the conditional terminal in each loop to see if either become true. In your second loop, you have a problem. The number of bytes to read should be coming from the VISA Bytes at Serial Port in that loop. Not the function in the first loop. You should also put a small wait (ms) or delay function in each loop.

At some point, if there is the possiblity that the instrument connection might fail, you would want to add some timeout check in each loop. For example, an elapsed time function could be used and the Boolean output OR'd with the other condition.

Message 4 of 9
(4,548 Views)
Ok, so it runs now and gets the data, the problem is that it runs the 2nd loop twice - the first time it reads the data and the second time, since there are 0 bytes to read, the read buffer is empty.  So the output of the loop is the empty string instead of the one with the data and that's what is getting sent to my string array.  I added a case structure with a condition on "Bytes at Port" but the problem is that for both TRUE and FALSE cases, I have to have some value going to the string buffer.  I put in "EMPTY" for the true case and this proved what I thought was happening.  Is there a way that I can just wire "read bugger" to the string array ("String READ") only in the FALSE case?
 
Thanks.
 
jeremy
 
(I've attached my most recent version)
 
 
0 Kudos
Message 5 of 9
(4,535 Views)
This is what I do. I can have very long strings that might take quite a while to get. It's just a shift register to hold the pieces as they come in and a case statement. If the second while loop always gets all data in the first read, you could just eliminate the while loop.
 

Message Edited by Dennis Knutson on 04-17-2007 11:04 AM

Message 6 of 9
(4,533 Views)

Works by removing the second loop.  Thanks so much for the help!

0 Kudos
Message 7 of 9
(4,513 Views)

Dennis, thank you for your insight. This solved a big problem I was having when communicating with a serial device!

0 Kudos
Message 8 of 9
(4,076 Views)

Thanks!!! It's help me a lot Smiley Happy

0 Kudos
Message 9 of 9
(4,022 Views)