Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Thread safety of IVI drivers developed in LabWindows/CVI

If I write an instrument driver using LabWindows/CVI and the appropriate wizards, is it inherently threadsafe? Or do I have to add all of the various lock/unlock functions myself? (I know that I have to add syncronization to make sure that separate threads don't step on each other while one has control of the instrument, that's a separate issue).

0 Kudos
Message 1 of 5
(3,842 Views)
Hi, Assuming that you are talking about IVI-C specific driver case. In my opinion, specific driver need to invoke the lock/unlock function to ensure the VISA communication thread safe. Take agx2k3k IVI-C scope driver for example as below. You could download these kind of driver in http://www.ni.com/devzone/idnet/. ViStatus _VI_FUNC agx2k3k_reset (ViSession vi) { ViStatus error = VI_SUCCESS; checkErr( Ivi_LockSession (vi, VI_NULL)); if (!Ivi_Simulating(vi)) { ViSession io = Ivi_IOSession(vi); checkErr( Ivi_SetNeedToCheckStatus (vi, VI_TRUE)); viCheckErr( viPrintf (io, "*RST")); } checkErr( agx2k3k_DefaultInstrSetup (vi)); checkErr( agx2k3k_CheckStatus (vi)); Error: Ivi_UnlockSession (vi, VI_NULL); return error; }
0 Kudos
Message 2 of 5
(3,830 Views)
ViStatus _VI_FUNC agx2k3k_reset (ViSession vi) 
{ 
    ViStatus error = VI_SUCCESS; 
    checkErr( Ivi_LockSession (vi, VI_NULL)); 

    if (!Ivi_Simulating(vi)) 
    {  
        ViSession io = Ivi_IOSession(vi); 
        checkErr( Ivi_SetNeedToCheckStatus (vi, VI_TRUE)); 
        viCheckErr( viPrintf (io, "*RST")); 
    } 
    
    checkErr( agx2k3k_DefaultInstrSetup (vi)); 
    checkErr( agx2k3k_CheckStatus (vi)); 

Error: 
    Ivi_UnlockSession (vi, VI_NULL); 
    return error; 
} 

 

0 Kudos
Message 3 of 5
(3,820 Views)

Hi pblase,

 

If you wrote your driver to be thread safe you should pick the option "run in any thread", but if you did not, this is not inherently threadsafe. You can do either, modify  your driver to be threadsafe, or select the option run in "UI thread" when you call your library.

 

ThreadSafe

Also, if you are importing a library that you are not sure if is threadsafe, you should pick the option "run in UI thread" too, with this option you force the execution to run that specific library only in the User interface thread.

 

I hope this helps.

0 Kudos
Message 4 of 5
(3,811 Views)

Last two posts (10-18-12 and 10-19-12) are related to this thread.

Message 5 of 5
(3,803 Views)