LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

serial write and read sometimes works, sometimes times out

Solved!
Go to solution

I'm using the VISA serial VIs to acquire data through an instrument.  After configuring the port, I send the instrument the command "AZK" followed by a carriage return (Hexadecimal string "2A61 7A6B 0D").  This prompts the instrument to trasmit data.  When I do this in Hyperterminal with all the same port settings, it works every time when I repeat the command as quickly as I can with no problems.  When I run my VI in LabVIEW, sometimes it works and sometimes it doesn't (works maybe 25% of time).  When it works, the data is displayed in an indicator very quickly.  When it doesn't work, I receive a timeout error (10 seconds).   

 

I think the data string is ~ 330 bytes; since I'm troubleshooting, I've cut it back to 20 bytes just to make sure the Serial Read isn't waiting for more bytes.  I've also tried extending the timeout, but that doesn't help.  Thinking this was maybe timing, sequence, or buffer related, I've also tried putting the write and read into separate frames of a sequence frame and also tried an intial frame with VISA clear to clear the buffers before the write and read, but none of this has helped. 

 

Any ideas why this might be working sometime but not others? 

 

I've attached a VI that I'm using to try and get this working.  (Note there are some data parsing operations along with the VISA read from a previous VI, but they haven't been configured for this particular instrument input yet and only the Input Read String indicator is meaningful right now.)

 

If I can't get this to work, my fallback is to set the instrument to trasmit automatically on some frequency (like 1 sec) and acquire that data.  I've been able to do that successfully with another serial device.  But I wanted to be able to have LabVIEW control the timing of the data transmission since this device has that capability. 

 

Thanks for any help.             

0 Kudos
Message 1 of 8
(4,323 Views)

You currently have the serial port configured with the termination character disabled, but you have a "D" (carriage return) wired to the termination characters. If the message from the instrument ends with a carriage return as well then you need to enable termination character in the VISA Configure Serial Port. These two parameters (on/off and character) are used by VISA Read. When termination character is on you do not need to wire an exact number of bytes to the VISA Read. Simply wire a sufficiently large number. The VISA Read will end once it sees the termination character.

0 Kudos
Message 2 of 8
(4,314 Views)
Solution
Accepted by topic author prenaut41

You could try adding a delay between characters like Hyperterminal does.

 

And please don't say that you are using the run continuous button. That would be wrong.

0 Kudos
Message 3 of 8
(4,308 Views)

Thanks, ,

I was using the carriage return as a termination character for another instrument.  But when I tried that for this instrument, it would terminate the data transmission early after the first line (when the read would actually work).  The transmission consists of four lines containing data, and it looks like each one ends with a carriage return instead of a line return.  So that is why I had disabled the termination character, and just left the character input wired for the time being.  But even with using the carriage return and accepting the truncated read of the data transmission, I had the same problems with the read sometimes working and mostly timing out. 

 

Along the lines of termination characters, the transmission starts and ends with (and I don't know what the right term is) shape characters, such as smiley face, heart, triangle on it's side (I don't recall which ones are at which end of transmission right now).  I would like to use these characters for ending the read, but do not know how to use them in LabVIEW.  Are there hexademical or some other equivalent code for these that would be easy to use? 

0 Kudos
Message 4 of 8
(4,295 Views)

On your string indicator (without the strip white space), simply right click on it and select Hex Display.

0 Kudos
Message 5 of 8
(4,289 Views)

Thanks, Dennis. 

I'll give the delay when writing a try and see if that helps.  I guess the thinking there is that the instrument might not be able to read and process the bytes/characters quickly enough? 

 

In trying to understand, this delay time would help if the bytes are seen as overlapping in time - from the perspective of the instrument - and it cannot properly break up the bit stream into the 8-bit bytes that it requires, correct?

 

If the high/low voltages (bits) that make up the signal from the PC were switching to quickly for the instrument to always properly interpret the binary signal that makes up the bytes, then that would be the result of an incorrect baud rate, correct?  But since the same baud rate works just find in hyperterminal, then it wouldn't be worth trying a different baud rate in LabVIEW, right?  (In case the manufacturer had given me an incorrect baud rate.)  I assume here that "a baud rate is a baud rate" and a baud rate in hyperterminal would be the exact same frequency as a baud rate in LabVIEW. 

 

0 Kudos
Message 6 of 8
(4,287 Views)

Oh, forgot to add that I'm not using the run continuously button.  I've seen under other posts that this is not good for routine use and only meant for specialized debugging. 

0 Kudos
Message 7 of 8
(4,286 Views)

Dennis, thanks a ton.  The delay time between characters worked beautifully.  Only 1 ms was adequate, but I'll probably use a slightly longer delay in practice just to make sure I don't have the problem creep up again at a lower rate of occurance. 

 

Also, the trick to figure out the hexadecimal code for those termination characters worked quite well! 

Message 8 of 8
(4,277 Views)