Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

How to lock a serial line (VISA)

Hi folks,
 
i'd like to lock a serial line (COM2) while used by a VI.
I have some VIs performing a similar job - talking over COM2 to an embedded system. The setup is:
VISA Open, VISA Configure Serial Port, VISA Write, (Wait 200ms), VISA Read, VISA Close.
As long as one VI is finished before the next VI is started everything works fine.
But when one VI runs for a longer time no other VI should be able to interrupt the serial communication.
So how to do this using VISA?
 
So far i had only sucsess by setting "duplicate session (F)" to TRUE and "access mode" to 1 for "VISA Open".
But this works only if just one VI is set up this way. This one VI winns ....
If a second VI has the same setup an
Error -1073807345 occurred at Property Node (arg 2) in VISA Configure Serial Port (Instr).vi->VI2.vi
Possible reason(s):
VISA:  (Hex 0xBFFF000F) Specified type of lock cannot be obtained, or specified operation cannot be performed, because the resource is locked.
comes up just for the first time! Executed a second time there appears no error and it is able to access the serial line.
 
Any hint how to lock a serial line "first come - first serve"?
 
 
Best regards
Stefan Hutter
 
0 Kudos
Message 1 of 2
(3,449 Views)
Stefan,

this smells like a bug in VISA!

You can lock a ressource by putting the accessing code into a shell thats tries to obtain a semaphore before accessing the ressource and releases it after having done.
Example for 'com1':
1 Create semaphore 'com1' with size of 1
2 obtain semaphore 'com1'
3 if no timeout perform your code here ...
4 if no error in line 2 release the semaphore
5 destroy the semaphore if it has been created
6 Generate an error cluster if timeout or error had occured
Greetings from Germany!<br>-- <br>Uwe
0 Kudos
Message 2 of 2
(3,445 Views)