02-03-2014 02:22 PM
Hey all,
I'm a new to LabView programming (three days by now...) and I really hope to have an answer to my question.
I am communicating with a ten years old optical spectrum analyzer. It has a GPIB connection and I have successfully read and write using VISA.
At the moment - I have a subVI for every command in which I prepare to correct string. I then route it to a write function that perform visa open, write and close.
I end up with a block diagram that has multiple and identical write functions.
I was wonder if there is a more elegant way to do it?
I intend to implement more frequently used commands as an event structure - so the program will respond to changes only (I've just saw the tutorial).
Is it possible to the same with VISA write? And if so, how will it respond to multiple changes?
How do you recommend to handle multiple strings command into a single write function?
Thanks, Avishay
02-03-2014 02:42 PM
02-04-2014 11:09 AM - edited 02-04-2014 11:18 AM
You should avoid opening and closing a VISA session every single time you write.
At the beginning of your program open one VISA session to your insturment.
Pass that same session to every VI that needs to read or write to the instrument.
Close the VISA session at the end of your program before it stops or exits.
As for muitipule VISA writes, as Dennis_Knutson said, place your command strings in an array constant.
Place a VISA write in a For-Loop and feed the array, the commands will be auto indexed one at a time to the VISA write.
I have attached an example that shows both of the topics I touched on
02-04-2014 02:37 PM
thanks, for this.
I'm not sure I understand the pic to the end. In my application, I have commands I want to do once at value change - so I insert them all to an event case. when a change happen - I write the command - and open and close the VISA.
why is it a problem to open and close a session for a short time, with each change?
also, even If do want to open and close a session once - how can I do that?
this is possible only if my application is running for a few seconds, in my case - I want it to be dynamic for hours (imagine you want to monitor something over a long time in your spectrometer or scope). it is possible to insert very long wait function or delay or even to set very high session timeout instead of the default but it doesn't sound to me as a good method....
maybe you can help me with another issues I encounted today. I have no problem to read and write simple command, but I have a problem reading massive data (about 8000 bytes count).
my optical spectrum analyzer constantly sweeping over a wavelength range. I want to show this on my computer as a "live" waveform. but when reading a full trace I get a time our error after a few trials (2 or more). at first I thought it was a read \ write delay issues - but I couldn't fix it with any delay I input.
I suspect this because my program is not synchronized with the OSA sweep triger, thus some time I read in the middle of a cycle and do not get all the expected byte count.
I did a polling techinque that start to read data only after a full scan is complete.
I also did a for loop over the entire program to see how many reads I can do without failure. I manage to do 15 reads at max. before I get the time-out error. the wierd thing is that when I run it at debugging mode, where you can see the values propagating throuthout the program - I manage to read for more iteration.
any suggestion on how to solve it? is this couldl be related to me using VISA instead of GPIB directly? by the way, does anyone know how to initialize and read\wtire with GPIB commands? I could'nt find any tutorial on this anywhere...
Avishay
02-04-2014 03:40 PM
02-04-2014 03:55 PM
In my experience repeatedly opening and closing VISA sessions causes memory leaks and eventual program crashes over time.
You really need to post your code so I can see what you are doing.
For your long read problem I suggest you use the VISA property node to enable termination character and set the TermChar to match the termination charactor your instrument sends.
Then set the VISA read to read a much higher byte count than you expect and the VISA timeout higher than it takes to read the longest set of data.
Now the VISA read will read until it reaceives a termination character regardless of how many bytes it receives.
02-05-2014 01:06 PM
Thanks for the replay.
I gave up all VISA open, and have one VISA close outside my while loop - and it solve the problem.
I have another questions. Is it possible to use two seperate write\read operation? or to synchronize between them somehow?
for example - let's say I have a while loop that endlessly reading my spectrum by sending some command. and in the middle, I want to change my spectrum range i.e. send a different command.
I thought this will be possible If I put the specrum reading inside my while loop - and the spectrum range modification in an event case - also inside my while loop.
but this results in an error - maybe because the spectrum read command is also sent during the event.
how can this be solved?
I thought using the event case as latch button to stop the while loop. Is this possible?
02-05-2014 01:14 PM
02-06-2014 03:50 AM
thanks, the Timeout solution is simple and working grate!