LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Serial Read locks up program

I'm using the Serial Port Write.vi to write strings to a control board. When I use Serial Port Read, it works, but the program from that point on will not Write to the port again. I am initializing at startup, and I am using the Bytes At Serial Port.vi with a scaler of 5 wired to it because that's how many bytes I want to read. Any help? I prefer not to use Visa, unless i can be persuaded otherwise.
Richard






0 Kudos
Message 1 of 7
(2,732 Views)
It sounds like a race condition (the attempt to read is happening before writing the command or too fast after it). Try to use a sequence, having Write in frame 0, a Delay in frame 1 and Read in frame 2.
Regarding the Bytes At Serial Port I am not sure I understood how you are using it. Usually, have a loop ending when you have enough bytes to serial port or a timeout occurs (and after that read if not timeout)
It may be easier for us if you can post that VI.

Hope this helps
0 Kudos
Message 2 of 7
(2,732 Views)
I've thought about the race condition... I'll look into it, especialy since I'm using a few local variables in the program.
As for the Bytes At Serial Port, by trail & error, I found I had to put that vi before the Read Serial Port vi or the Read vi would not work. Without using the Bytes At Serial Port vi, the readout would look like pure ASCII and did not make any sense. Assuming it *was* ascii, I converted several data points to decimal and it made no sense. By using Bytes At Serial Port, the gibberish ascii looking stuff became decimal and the data was correct. I grab 5 bytes because that gives me 3 digits right of the decimal point.
Richard






0 Kudos
Message 5 of 7
(2,732 Views)
Oops, CORRECTION:
After reading the comment by Rob, I looked at the code again, and the 5 is wired to "requested byte count" of the Serial Port Read vi. The 5 is NOT wired to the Bytes At Serial Port. My mistake!
Richard






0 Kudos
Message 6 of 7
(2,732 Views)
Just out of curiosity, why do you not want to use VISA?
0 Kudos
Message 3 of 7
(2,732 Views)
There is confusion regarding how you are using Bytes at Serial Port.vi. Are you using this to find the number of bytes waiting in the buffer and then feeding that into the Serial Port Read.vi? It sounds like you have wired a 5 into the Bytes at Serial Port.vi which would mean that you're reading from COM6. Please clarify or send your VI so we can have a look at it.

And, one of my usual addins: No, don't use VISA. Your serial VIs will work on a much wider range of machines if you don't use VISA for the serial port.

Rob
0 Kudos
Message 4 of 7
(2,732 Views)
Rob,
See my comment above... I made a mistake in describing where I had the 5 wired. I edited my code, deleted what I thought was a race condition, and now there's NO Bytes At Serial Port vi, and it works fine, but I still have the problem with the machine not writing to com1 after it has read from com1. I have to reboot!

As for Visa: I don't want to use Visa because I don't want to worry about other machines that use my code (and exe's) having Visa available.
Richard






0 Kudos
Message 7 of 7
(2,732 Views)