LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

VISA Shared resources by lock CVI functions

Hello,

Attach to the post : http://forums.ni.com/t5/LabWindows-CVI/VISA-Shared-resources/m-p/1000856#M43685

I use LabWindows/CVI 2013 SP2.

I have a share VISA problem : 2 functions VISA (Read and Write), on the same ressource.
I want to protect the access to the ressource VISA with the lock functions.
Like they propose and also the "ThreadLockTimeout" NI example.

So only at the beginning of the software, I do step 1 : cmtStatus = CmtNewLock ("", 0, &LockHandleRS), add before that, to a free handle in case of...
Only at the end, step 4 : cmtStatus = CmtDiscardLock (LockHandleRS), add to a "LockHandleRS = 0".

In each read and the write VISA function (20 ms < time < 100 ms, timeOut =2 s),
I try to use different methodes, without success :
- to lock (step 2) :
     1) cmtStatus = CmtGetLock (LockHandleRS)
     2) cmtStatus = CmtTryToGetLock (LockHandleRS, &lock), add to a while loop (for timeOut)
     3) cmtStatus = CmtGetLockEx (LockHandleRS, 0, timeOut, &lock)
     4) and even, statusRS = viLock (portVISA, VI_EXCLUSIVE_LOCK, timeOut, VI_NULL, VI_NULL)
- the VISA read/write function :
     "viWrite" for the ask, following by a "viRead" for the answer
     (VISA read function (# measure) : for only an acknowledge echo traitment and read data reponse)
     (VISA write function (# order) : for only an acknowledge echo traitment)
- to unlock (if lock successfull) (step 3)
     1)2)3) cmtStatus = CmtReleaseLock (LockHandleRS)
     4) statusRS = viUnlock (portVISA)

I display every wrong "cmtStatus" and "statusRS", but nothing appears.

The VISA read function is called following an "EveryNCallback" DAQmx function (every 0.5 s).
The VISA write function is called punctually, by an operator action throught various interfaces.

If I use only the periodic VISA read function, no problem on lock/unlock.
N.B. : Lock function (step 2) take only # 100 µs (for case 2) : at the 1rst iteration).
N.B. : I use the same external lock/unlock functions for the VISA read/write.

But nearly at every VISA write asking (3 on 5), I can display 2 consecutive successfull locks function (VISA read and write) ???
N.B. : same time (100 µs).
Following, of course, to 2 unlock functions (step 3).
And every time, the echo of the VISA read function is treat by the VISA write function.
And the echo of the VISA read traitment is truncked.
So for me, I treat it like 2 VISA errors (read/write).

======================================

I try to improve the NI example to show my problem.
I hope that I do not make so much big mistakes, which would cancel the interest of this example.

Into this small code lines, I can reproduce my problem (by quick applies on F1 button).
I do not implimente all the fonctions I try.

Into a bigger one, it is very easy to reproduce (even with the other functions).

N.B. : In my final application, the thead n°1, look like more to a CVICALLBACK, than a thread with a while loop inside.
But the problem still the same.

Thanks a lot for consideration.


Certified LabWindows/CVI DEVELOPER (2004)
LabVIEW since 5.01 | LabWindows/CVI since 4.01
0 Kudos
Message 1 of 3
(4,477 Views)

Hello,

With NI France support, we improve to the NI example again.

We show, with adding timing, that the example can display the message in a wrong sense (with a  software slowing down, at this moment, why ???) (see Explication°1.png).

If we display the message before the release (//#define M2), we can not reproduce the double lock (and release),

but also any software slowing down.

So this example can not be use to help me to resolve my application lock trouble.

It is not representative of my problem, which is always in progress. Smiley Sad


Certified LabWindows/CVI DEVELOPER (2004)
LabVIEW since 5.01 | LabWindows/CVI since 4.01
0 Kudos
Message 2 of 3
(4,439 Views)

Hello,

To resolve (it is a very great word) the problem, I have create a FIFO on the VISA write function.

Every called of it, I save the concerned data into an own software "queue".

At each "EveryNCallback", I do the VISA read function (like it was already the past).

But in more, I treat just after the FIFO of the VISA write function.

Like this , I am sequenced on the all VISA resources (write/read).

The little problem is that now my VISA write requests are delayed and write in time with the "EveryNCallback" treatment.

So if the acquisition dead, the VISA write is not done (it was necessary to do another special treatment, at the acquisition stop).

If that can help someone else until a better solution.

 


Certified LabWindows/CVI DEVELOPER (2004)
LabVIEW since 5.01 | LabWindows/CVI since 4.01
0 Kudos
Message 3 of 3
(4,403 Views)