LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Multiple string write

 

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

0 Kudos
Message 1 of 9
(3,914 Views)
You can create an array of commands and pass it through a for loop with the write inside.
0 Kudos
Message 2 of 9
(3,907 Views)

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 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

 

mmulti visa2.PNG

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 3 of 9
(3,865 Views)

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

0 Kudos
Message 4 of 9
(3,841 Views)
Unless you are using a very old version of LabVIEW, using the run VISA Open is just unnecessary and if you close a session in each event, you just create a lot of sessions and that is inefficient. You simply wire the wire the reference out of the while loop or put the close inside a close event. You pass the reference from one event to another with a shift register.

Using the low level GPIB functions will not make a difference. The functions perform just like the VISA ones and you just make your app less portable.

Some of your other comments do not make any sense without seeing your code. Post an image of the block diagram please.
0 Kudos
Message 5 of 9
(3,827 Views)

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.

 

term.PNG

 

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.

 

 

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 6 of 9
(3,820 Views)

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?

 

 

0 Kudos
Message 7 of 9
(3,784 Views)
GPIB communication is sequential. Parallel communication is not possible. You would need some mechanism to prevent both loops reading/writing at the same time.

If you already have an event structure, you can place the waveform read in the timeout event.
0 Kudos
Message 8 of 9
(3,776 Views)

thanks, the Timeout solution is simple and working grate!

0 Kudos
Message 9 of 9
(3,753 Views)