Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

VISA Practices

I am working on a project that involves extensive VISA communications thorough a serial port. In my past observations, the communication protocol consisted of opening the serial port then writing and reading as needed then, and as a step in the orderly shutdown, closing the serial port. This is practice 1 and consists of opening and closing the port once each. On this project, I received a subVI (practice 2) that opens, writes and reads, and closes every time a command is sent down. Which practice is preferable? If you're feeling generous, Why?
 
Thanks,
Mike Reilly
0 Kudos
Message 1 of 9
(3,772 Views)
Hi Mike

The practice of opening once and closing just before the end of your program is simply the best.
Opening a port does some intensive search on hardware, initialise it and claim it for your program.
So this is really timeconsuming.
Only if other programs on the same computer should have acces to the same port you have to close the session and
that should anyhow be guarded by assuring that not both programs try at the same time.

My 2 cents is that you always open and close instruments when you start using them and keep open until you  are absolutely sure
that you don't need them anymore unless you have a very very very special reason to close each time.
And very very very special means that you should document why you do it.
greetings from the Netherlands
0 Kudos
Message 2 of 9
(3,764 Views)
Hi Mike,

I don't mean to contradict, but rather offer a different point of view.

I interface with quite a few different RS-232 devices via VISA and I have made the experience that (as long as no very large data transfer frequencies are required) opening and closing each time can be more reliable.  Of course if you require high transfer speeds then opening and closing the port each time will cripple the transfer, but for slower devices, the time simply doesn't register in the entire system.

What you can then have is a self-contained VI for reading which takes care of opening, writing, reading and closing the VISA port.  For me, this is sometimes worth the loss in communication speed.  Of course, when I say "speed", I generally only send one command every few seconds, so I suppose "slowness" may be more accurate 🙂  A little trick: You can use the "run for the first time" function to only initialise the port on the first run.  I find that the initialization takes quite a long time, but the opening anc closing is not so bad.

I like "Drop and forget" code.

Shane.
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
0 Kudos
Message 3 of 9
(3,762 Views)
What kind of missing reliability is missing.
Is it a hanging operation, a timeout or badcharacters?
It is not only the speed, but the general architecture.
I get the feeling that you don't trust your underlying operating system, and that is sometimes true
So in which os are you working?

greetings from the Netherlands
0 Kudos
Message 4 of 9
(3,759 Views)
I'm working on Win2k, and winxp.

I do some working with half-finished drivers, and regularly experience problems with dll drivers and so on which require me to reach for the red "stop" button.

I find that VISA connections which are closed as you say (once at the end of the program) create more problems when I try to re-start a program afterwards.

Whenever I can afford to (from speed point of view) I open and close so that if the program dives on me, then I get much less problems when I re-access the port.  I often have trouble accessing a port which was not previously correctly shut down.  Of course exiting LV and re-starting fixes any problems, but that's a pain.

I suppose I should have added that I do this because I rarely have finished code to work with, I'm generally debugging crashy code.

I suppose it depends on the level of crash-proofing the code requires.

But apart from the reliability issues, I also find it nice to have code I can simply use once on a diagram without having to worry about opening, closing, when or if.  I just use the VI and I know everything is sorted out.  Using eventy and so on to capture panel closures is one thing, but crashed don't usually generate events (unless this is a new addition since 6.1 - a "crash" event yould be interesting!). 🙂

Shane.

PS some questions: What kind of overhead do you see when openiing and closing a port? RS-232, GPIB, or something else?  I've never had a problem with it.  What speeds are you communicating at that opening and closing is a problem?

Message Edited by shoneill on 09-20-2006 11:41 AM

Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
0 Kudos
Message 5 of 9
(3,759 Views)
Hi Shane

Ok incase of the abort button I don't blame the operating system or VISA.
It is no problem anymore with visa to not open the device, if you are fine with the default settings or if you have defined new defaults in MAX
so except for abort you also can use it on a per vi base.

greetings from the Netherlands
Message 6 of 9
(3,753 Views)
Now you've said something to get my attention.

What's that about setting defaults in MAX?  Why that would solve my problems, wouldn't it?

I always went to the windows properties when dealing with RS-232 ports.  I never thought of looking in MAX for something as trivial as a COM port.

The issue with self-contained code remains though.

Shane.


Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
0 Kudos
Message 7 of 9
(3,748 Views)
If you change the properties of the com port in max, visa will use those for automatic opening when you run a vi.

in max select devices and interfaces\ports\com1 (e.g) and at the bottom of the middle window you see a tab port settings
The rest is easy
greetings from the Netherlands
0 Kudos
Message 8 of 9
(3,738 Views)
That seems clear and logical.

No wonder it's something I never thought of.....  Smiley Very Happy

Thanks

Shane.
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
0 Kudos
Message 9 of 9
(3,729 Views)