Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

IVI driver error: specified handle is invalid or of an incorrect type

This one has me stumped. Running LabWindows/CVI 8.1. As previously mentioned, I wrote an IVI driver and a class driver to talk to an instrument controller. Trying to operate in simulation mode, with the equipment not attached. When I initialize the driver (XXX_InitWithOptions()) from a small test program, it initializes fine. When I call it - identically - from my actual program I get Error -1074130400 (BFFA1220) - "specified handle is invalid or of an incorrect type". this comes from the Ivi_ClassDriverNew (logicalName, className, functionNames, &vi) call in the ClassUtil_CreateNewSession routine in the class driver. Since it's simulating, it never gets to the InitWithOptions call in the actual driver. What the heck is it talking about? All of the parameters seem fine, the call is identical to the one that works in the other program. (In both cases the class and actual drivers are in dll's, and I've followed all of the IVI protocols for using them, as far as I can tell) Any suggestions greatly appreciated.

0 Kudos
Message 1 of 18
(5,553 Views)

Hi,

 

It sounds to me like you may be setting up the simulation incorrectly. In order to successfully simulate an instrument, you need to pass the argument signifying that you are simulating the instrument to InitWithOptions, or else the driver will throw an invalid handle error similar to the one you are seeing. Since your error is being thrown before you call InitWithOptions, I would make the call to InitWithOptions earlier in your program, in order to ensure that a valid simulated instrument handle is being passed. This link has some useful information about IVI simulation, as well: http://zone.ni.com/devzone/cda/tut/p/id/4560

 

Best,

Dan N

Applications Engineer

National Instruments 

0 Kudos
Message 2 of 18
(5,540 Views)

Here's what I'm doing.The problem is that we have multiple axes controlled by multiple controllers, and a "system" may have stages from different controllers. So, I've abstracted everything.

Start in MotionControl.c, the highest level. MCP_Set_MC_Axis calls "STAGE_InitWithOptions()".Since I don't have the actual controllers attached at the moment, the simulation flag is set. The function NVESDU_GenOptionStr() (in the STAGE_InitWithOptions() call) just generates a standard opion string from integer parameters. 

 

The Stage driver figures out which controller and which axis to use.

In MotionStage.c/STAGE_IviInit(...) MotionController_InitWithOptions (....) is called.

 

MotionController is a class driver which abstracts to the specific driver for the stage.

MotionController_InitWithOptions() calls ClassUtil_CreateNewSession, which in turn calls Ivi_ClassDriverNew (). This is where the error is coming back from. 

 

Which InitWithOptions call are you refering to?

Question: since the Simulate option is passed down, should I filter it out at the upper levels?

 

Download All
0 Kudos
Message 3 of 18
(5,534 Views)

The real puzzler is that I used exactly the same call (cut-and-paste) to STAGE_InitWithOptions in a small test program, and it works fine. It even calls the exact same dll's.

0 Kudos
Message 4 of 18
(5,533 Views)

Hmm. It does the same thing whether simulating or not.

0 Kudos
Message 5 of 18
(5,526 Views)

Ok, I've narrowed it down and it's getting stranger.

Previously in the code I have two routines that tell me what controllers and motion stages are present on the routine.Both routines access the IVI configuration server (the stuff shown in MAX).

MCP_ReturnAvailableControllers() finds the list of Logical Names (which point to IVI Driver Sessions) and gets the pertinent information (namely the resource descriptor, which is the GPIB address) from them. It then attempts to open the actual unit and see if it's physically attached to the system. So far, so good. The information on the controller is stored in a List.

 

MCP_Scan_Stages() then goes through each found controller and gets a list of virtual names from each. Each virtual name corresponds to an axis ("real" name = 1, 2, 3....; virtual name = "Horizontal", "Vertical", etc). These are, again, set in MAX. 

(I fixed the error at the end, where I used IviConfig_Close() and should have used IviConfig_DisposeHandle() ).

 

For some reason, MCP_Scan_Stages() messes something up. I call  the Open routine in question before MCP_Scan_Stages() (via cut-and-paste), and it works fine. Afterwards and it throws the "bad handle" error. I get no errors in MCP_Scan_Stages() itself, no warnings, no flags. 

Download All
0 Kudos
Message 6 of 18
(5,515 Views)

Hi pblase,

 

I would check to see if any of the calls you make in MCP_Scan_Stages alter the arguments you're passing to your class driver InitWithOptions() call. I noticed in your MCP_Scan_Stages routine that you alter the Simulating property of each Stage List entry; try making the initialization call before/after this step in MCP_Scan_Stages (if the code allows), and see if the invalid handle error occurs. There's definitely some call within the MCP_Scan_Stages routine that's causing the error. 

 

Best,

Dan N

Applications Engineer

National Instruments 

0 Kudos
Message 7 of 18
(5,510 Views)

Hi pblase,

 

As for the Error -1074130400 (BFFA1220) - "specified handle is invalid or of an incorrect type", I think it is caused by your struct type : MotionData.StageData[axis].Stage_session

 

You can replace &MotionData.StageData[axis].Stage_session with &StageHandle(simple ViSession type like in your MotionStageTest.c). If it works, problem comes from your struct type. If the code still doesn't work, problem may come from the STAGE_InitWithOptions.

 

Please reply to me with your result. I will go on my support with your reply.

 

National  Instruments

Haoran Feng

 

0 Kudos
Message 8 of 18
(5,499 Views)

I'm attaching for reference the entire MotionControl.c file, which is the high level file that calls the various driver routines.

At line 287, I call MCP_ReturnAvailableControllers() to get a list of the available controllers (the routine gets the list of Logical Names from the IVI store and then checks to see if the controllers are physically available).

It then calls MCP_Scan_Stages(), which gets the list of Virtual Names associated with each found controller (Logical Name). 

 

I put two calls to the device driver STAGE_InitWithOptions(); one prior to the MCP_Scan_Stages(), one after it. The first one concludes successfully, the second fails with the "handle" error previously mentioned. Since in both cases the resource descriptor ("Midwave:Z") and the handle return are local, they should not be the source of the problem. (I made the change that you suggested, anyways). 

 

Part of the problem is that the IVI_config routines used in MCP_Scan_Stages() are not well documented. I would appreciate it if you could verify that I am calling them properly. I believe that I am closing all handles after they are opened, but something is obviously getting left open, or getting changed when it shouldn't be. 

Download All
0 Kudos
Message 9 of 18
(5,492 Views)

Hi pblase,

 

I have read your code, I found following problem:

 

		//Get listed IVI stages (defined in MAX as virtual names for IVI driver session axes) for each stage. 
		Status = IviConfig_GetDriverSession (ConfigStoreHandle,
											 Controller.ControllerName, 
											 &DriverSessionHandle);
		Status = IviConfig_GetSessionVirtualNameCollection (DriverSessionHandle,
                                                            &VirtualNameCollectionHandle);
		//the "virtual names" are the names assigned to the various axes in MAX, e.g. "azimuth". 
		Status = IviConfig_GetVirtualNameCount (VirtualNameCollectionHandle,
		                                        &NumAxes);

 You have defined Status to receive the return value from the IviConfig_xx API, but you do not check the Status after calling functions!

 

 

 Your code can not be compiled for lack of other files, so I wrote a simple demo code:

 

    //Get control store handle
    Status = Ivi_GetConfigStoreHandle (&ConfigStoreHandle);

    printf("\n-------------Status is %d-----------------------------------\n", Status);

    /*//Get listed IVI stages (defined in MAX as virtual names for IVI driver session axes) for each stage. */
    Status = IviConfig_GetDriverSession (ConfigStoreHandle,
                                         ControllerName,
                                         &DriverSessionHandle);
    printf("\n-------------Status is %d-----------------------------------\n", Status);

    Status = IviConfig_GetSessionVirtualNameCollection (DriverSessionHandle,
                                                        &VirtualNameCollectionHandle);
    printf("\n-------------Status is %d-----------------------------------\n", Status);

    //the "virtual names" are the names assigned to the various axes in MAX, e.g. "azimuth".
    Status = IviConfig_GetVirtualNameCount (VirtualNameCollectionHandle,
                                            &NumAxes);   
    printf("\n-------------Status is %d-----------------------------------\n", Status);

 The Console result is: 

-------------Status is 0-----------------------------------

-------------Status is -1074130429-----------------------------------

-------------Status is -1074130400-----------------------------------

-------------Status is -1074130400-----------------------------------

 

So, it is quite likely that your error happend as early as at this point(IviConfig_GetDriverSession, IviConfig_GetSessionVirtualNameCollection, IviConfig_GetVirtualNameCount )

 

Please do necessary check on your Status each time after callling function , and find the Error's location, then I can help to find why calling this function is illegal.

 

 

Haoran Feng

National Instruments

 

 

0 Kudos
Message 10 of 18
(5,477 Views)