09-07-2019 06:57 PM
Hi All,
is it good practice (apparently not required) to use VISA OPEN in serial communication? I usually start with VISA OPEN, then configure my resource with property nodes, then CLR, then start my WRITE/READ loop and CLOSE after exiting my loop. However, what I see in the examples is that for serial, VISA OPEN is not used, only when connecting to GPIB. Is there any disadvantage opening VISA before configuring it, or should it be even done the other way around (first property nodes, then VISA OPEN)?
Thank you!
09-07-2019 08:50 PM
It really depends on what you want to do. VISA is a pretty general protocol that works with many different types of peripherals, generally (but not always!) doing "character-based" communication using USB, RS-232, GPIB, TCP/IP, or (probably) other protocols.
I suspect that if you did a search on the Forum with the word "VISA" in the title, you'd get lots of "hits". You'd probably find that many (but not all!) protocols for VISA reading start with a VISA Configure Serial Port, possibly a VISA Write (to send a command to the device to start sending data), then (in a While loop) a VISA Read, specifying 1000 bytes (or maybe 1024, if it's my routine, as I like powers of 2). You may see some code that uses the Bytes at Port property instead of asking for these ridiculously-large number of bytes, but then one of the responders with more experience will say "Don't Use Bytes-at-Port!!!".
But it really does depend on (a) what you want to do, (b) the nature of the device using the Virtual Instrument Software Architecture (for example, does it use a Termination Character and communicate using plain text), (c) the nature of the data, and (d) what you hope to do with the data.
Do some reading, Web searching, etc. If you have more questions, provide (much) more background information to get a more targeted response.
Bob Schor
09-08-2019 12:41 AM
Thanks Bob, very informative, but my only specific question is if it is advantageous to use VISA OPEN at the begin of a SERIAL (RS232) communication.
To add background information (not sure if this is essential for this question):
- LabVIEW 2018
- cRIO 9045 with 2 modules 9870 in hybrid mode (6 ports used)
- text based communication, some ports with termination character, some with fixed data length, XON/XOFF
- my architecture is: OPEN > Configure (property node) > CLR > [WRITE command > READ response in loop] if error CLR and reinitialise, if stopped CLOSE.
Thanks
09-08-2019 10:13 AM - edited 09-08-2019 10:14 AM
There is no advantage to explicitly putting in a VISA Open that I'm aware of. The VISA Configure effectively takes care of that.
I rarely see VISA Open's used in anyone's code.
09-08-2019 03:02 PM
Thank you, that is what I saw at example code as well, just wanted to make that I am not overlooking something.
Greetings, Guenter
09-08-2019 03:40 PM
Thank you! I was very confused, as I couldn't find VISA Open. Turns out you have the Instrument I/O Palette visible, and I have it hidden, so I find VISA under Data Communication\Protocols\Serial, which shows a much simplified VISA setup consisting of four functions, VISA Configure Port, VISA Read, VISA Write, and VISA Close. Do not use Bytes at Port (except in very rare instances where VISA is communicating using binary characters, not Ascii Text). The Configure function is simpler than the Property Node, but does the same thing (most of the default settings are, one hopes, what you want, except possibly for the Baud Rate).
You might like these functions (which are, I'm 99.44% certain, the same as the Instrument I/O VISA functions, but I think more straight-forward).
Bob Schor
09-09-2019 07:21 AM
@Bob_Schor wrote:
Do not use Bytes at Port (except in very rare instances where VISA is communicating using binary characters, not Ascii Text).
BAD, Bob! Even with binary/hex/raw messaging formats, any instrument worth a lick of salt will have a set protocol so you know how many bytes to read at any given time (often 1 at a time until a sync byte is read, followed by 1 or 2 bytes for the length or message ID, then based on that value read the rest of the message, and typically a checksum or CRC). See, still no Bytes At Port required. The Bytes At Port should only ever be used with sporadic messaging protocols (the instrument "randomly" sends data, typically when a measurement changes and/or an error occurs). Even then, it should only be used to see if a message has at least started to come in. It should still not be used to tell the VISA Read how many bytes to read.
09-09-2019 07:43 AM
Sorry I didn't give as detailed a critique as you did, and glossed over the "bad-ness" of Bytes at Port (I tried to emphasize "Do not use Bytes at Port" ...). I had an instrument that used VISA Binary, and recall reading one byte at a time until I got to the "Frame" byte, which told me that there were 11 more Binary bytes to follow, after which I could "snap in" to reading in groups of 12 ... But everything else I've ever used VISA for used Text, so I simply enable the default Termination setting and read 1024 bytes at a time.
Bob Schor