05-31-2011 03:13 PM
hello,
when talking to a serial instrument, do you have to insert millisecond waits in the while loop or will the reading and writing from the instrument generally control the loop speed of the loop? On the basic read write example they feed in the Bytes at Port into the VISA Read.... is this making the VISA not read until those bytes are avilable? I'm wondering if this was in a while loop if the loop would only iterated once the VISA has executed the read... which in turn depends on whether the bytes are avilable at the port?
I'm trying to figure out a general best practice way of setting up a serial device in an effecient manner, for something where you send a write then read.... in the basic serial read write example there is a delay in-between the write and read... is this an arbitrary number? does it need to be there if you're not reading until a specified number of bytes are at the port anyway?
much thanks!
05-31-2011 03:59 PM
As far as I use the serial VI's for communication I do not use Loops, I do use loops when I need to send a bunch of query commands. Bytes at port just gives a count that how many bytes are there at the port, even if you don't use it and wire byte count in read VI you must get the response, but you will not be sure whether you have recieved exact data. Time delay between write command read response also depends on how the protocol is setup.
I would always prefer VISA configure -> Bytes at port -> Read (this will empty any previous buffer)-> Visa write -> Bytes at port -> Visa read -> Visa Close.
05-31-2011 04:25 PM
05-31-2011 04:29 PM
In that case I would have a delay in ms or wait in ms only to reduce overhead.
05-31-2011 05:01 PM
"General practice" is an oxymoron when it comes to serial communication. There is no standard and every instrument is a little different. A well-behaved instrument such as one from a vendor that makes versions with GPIB communication (or USB or Ethernet), will use a termination character on reads and writes. In this case, no need at all for a delay or the VISA Byes at Serial Port. In this case, you can just use an arbitrary number when doing a read. The read will automatically terminate when the term character is detected. Looking at an instrument driver such as the 34401 that comes with LabVIEW is a much better example.