NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

C++ instrument Handle type

hi, ALL

   I want to use some instrument driver(DLL) to create a sequence.and step type base on C++,When initialized instrument with hp34970a_init("GPIB0::5::INSTR", False, True, Locals.SW) ,the prototype is

ViStatus _VI_FUNC hp34970a_init(
        ViRsrc resourceName,
        ViBoolean IDQuery,
        ViBoolean resetDevice,
        ViPSession instrumentHandle)

   it works fine,So i want to more operations for intrument,Such as :write,read....

   the arg4 (Locals.SW)is defined as "pointer/handle" -->"by reference &" in the module pane.And Locals.SW is defined as a object reference in Variable pane.After the initialized function is executed,The Locals.SW will be evaluated "Pointer: 0x1fa4f908".So in the next step,I want to use this instrument handle to execute other functions(invoke some functions in the DLL).Example:hp34970a_reset(Locals.SW),the prototype is

ViStatus _VI_FUNC hp34970a_reset(
        ViSession instrumentHandle)

   it seems not to work.

   How to fix it? Thanks a lot.

 

BR

Johnny

0 Kudos
Message 1 of 7
(3,932 Views)

the version of TS is 2010.

0 Kudos
Message 2 of 7
(3,931 Views)

What does the prototype in the step module call for the reset function have specified for the instrumentHandle? It should be pointer/handle passed by value.

 

What do you mean by it not working, are you getting a crash or an error?

 

Hope this helps,

-Doug

0 Kudos
Message 3 of 7
(3,925 Views)

Hi Johnny,

 

I think you want to use a numeric for the instrumentHandle parameter, not an object reference. The init will set the value of the numeric as a reference number for the current instrument session, which you then pass to the other functions instrumentHandle parameter.

 

Hope this helps.

 

-Jack

0 Kudos
Message 4 of 7
(3,919 Views)

Hi,

   Appreciate your reply.

 

Doug,

   hp34970a_reset(Locals.SW),the prototype is

ViStatus _VI_FUNC hp34970a_reset(
        ViSession instrumentHandle).

  The instrumentHandle is defined pointer/handle passed by reference previously.So i change to "passed by value" instead of it as you said.The instrument can be reset.

It is done.

 

Jack,

   If i changed the Local.SW to numeric instead of object reference.And in

ViStatus _VI_FUNC hp34970a_init(
        ViRsrc resourceName,
        ViBoolean IDQuery,
        ViBoolean resetDevice,
        ViPSession instrumentHandle)

   instrumentHandle is passed by reference and in

ViStatus _VI_FUNC hp34970a_reset(
        ViSession instrumentHandle). the instrumentHandle is passed by value.The sequence works fine too.

 

Thank you very much!

one more question,Both of methods can meet the applicaiotn.Which one is reasonable?

 

BR

Johnny

 

0 Kudos
Message 5 of 7
(3,897 Views)

Hi Johnny,

 

I believe that using a numeric as your instrumentHandle would mean that you don't have to edit the prototype of the functions you're using in TestStand (which is what I assume you did to get the 'pass by value' to work).

 

If you look for the intrinsic type of ViResource, it is derived from an unsigned 32 bit integer in visatype.h, so I'd recommend setting you instrument handle using the numeric approach.

 

Hope this answers your question.

 

-Jack

0 Kudos
Message 6 of 7
(3,888 Views)

Using object references (i.e. pointers) is more future proof for 64-bit compatibility. This idea is that on a 64-bit version of TestStand (which does not yet exist) with a 64-bit version of your instrument drivers, the pointers/handles would automatically be treated as 64-bit values, which is what they will have to be if they are addresses in a 64-bit process. This feature of pointers/handles was added in TestStand 2010 for this purpose.

 

That said some instrument drivers might continue to use 32-bit values even in a 64-bit process, but if the handles are really addresses they would have to create some sort of map internally to map to the 32-bit value to the correct 64-bit address. You might be able to tell what the driver developer intends by looking at the typedef for the handle type. If it is really a void* or some other sort of pointer then it is very likely that the 64-bit version will require 64-bit handles and thus you should use object references. If it is just a typedef of int, then they might not.

 

For Windows SDK APIs handles definitely become 64-bit in a 64-bit process (and are 32-bit in a 32-bit process), so for Windows SDK calls with handles, object reference variables are definitely better than numbers for handles.

 

So it really depends on how instrument driver developers end up supporting 64-bit processes.

 

Hope this helps explain things,

-Doug

Message 7 of 7
(3,884 Views)