Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Getting general protection faults and a "The given session or object reference is invalid".

Hi all,
 
I'm having some trouble with getting a visa session for an IVI driver.  I was wondering if anyone can see what I'm doing wrong here.  Here is the code that is giving me a problem:
 
ViStatus _VI_FUNC XanXTR_InitWithOptions( ViRsrc resourceName,
                                          ViBoolean IDQuery,
                                          ViBoolean resetDevice,
                                          ViConstString optionString,
                                          ViSession *newVi )
{  
   ViStatus    error = VI_SUCCESS;
   ViSession   vi = VI_NULL;
   ViChar      newResourceName[ IVI_MAX_MESSAGE_BUF_SIZE ];
   ViChar      newOptionString[ IVI_MAX_MESSAGE_BUF_SIZE ];
   ViBoolean   isLogicalName;
   // Debug code.
   ViChar      setup[ BUFFER_SIZE ],
        masterchannelAddress[ BUFFER_SIZE ];
  
   if( newVi == VI_NULL )
   {
      Ivi_SetErrorInfo( VI_NULL, VI_FALSE, IVI_ERROR_INVALID_PARAMETER,
                        VI_ERROR_PARAMETER5,
                        "Null address for Instrument Handle" );
                       
      checkErr( IVI_ERROR_INVALID_PARAMETER );
   }
   *newVi = VI_NULL;
   
   checkErr( Ivi_GetInfoFromResourceName( resourceName,
                                         ( ViString )optionString,
                                          newResourceName,
                                          newOptionString, &isLogicalName ) );
   
   /* create a new interchangeable driver */
   checkErr( Ivi_SpecificDriverNew( "XanXTR", newOptionString, &vi ) );
// PROBLEM on occurs in following line: Inserted for debugging.
   viSScanf(vi, "MCHADDR:1", "%*[^:]:%[0-9]%[^\n]", masterchannelAddress, setup);  
  
   /* init the driver */
   checkErr( XanXTR_IviInit( newResourceName, IDQuery, resetDevice, vi ) );
  
   if( isLogicalName )
   {  
      checkErr( Ivi_ApplyDefaultSetup( vi ) );
   }
  
   *newVi = vi;
   
Error:
   if( error < VI_SUCCESS )
   {
      Ivi_Dispose( vi );
   }
   return( error );
}
 
If I try to step through the code, I get a pair of general protection faults and then the given session or object reference is invalid error when the viSSprintf function call is made. 
 
Does anyone have some suggestions on what to look into to trouble shoot this further or better yet see a glaring omission of mine?
 
Thanks for taking the time to read through my problem. 
0 Kudos
Message 1 of 5
(4,384 Views)
/* create a new interchangeable driver */
   checkErr( Ivi_SpecificDriverNew( "XanXTR", newOptionString, &vi ) );
// PROBLEM on occurs in following line: Inserted for debugging.
   viSScanf(vi, "MCHADDR:1", "%*[^:]:%[0-9]%[^\n]", masterchannelAddress, setup);   
   
/* init the driver */
  checkErr( XanXTR_IviInit( newResourceName, IDQuery, resetDevice, vi ) );
The vi that you acquired by Ivi_SpecificDriverNew() is an instrument session handle.  It is actually an IVI session handle but not a VISA session handle.  Therefore you *cannot* pass the instrument session handle directly to VISA API functions.  (An IVI instrument session handle is equal to IVI session handle.  However a VXIpnp instrument session handles was exactly the same as VISA session handle in VXIpnp drivers.)
 
To acquire the VISA session handle from an IVI session, you may be able to use Ivi_GetAttributeViInt32() with IVI_ATTR_IO_SESSION attribute.  (Sorry but I have never used this before, so I am not sure if it works.)
 
Also, assuming you can acquire the VISA session, it is valid after viOpen() is invoked inside the instrument driver.  The VISA open will be invoked actually inside XanXTR_IviInit() call on the above example.  Therefore it means you can't use viSScanf() before XanXTR_IviInit().
 
 
 
 
 
0 Kudos
Message 2 of 5
(4,375 Views)
You're probably having the same problem that I did last week. See the thread
How do I work with dynamic range tables in Labwindows/CVI instrument drivers , and look at the last 2 postings having to do with the difference between an IO session and a VI session.
 
Paul
0 Kudos
Message 3 of 5
(4,354 Views)

Thanks Makoto,

That was the problem.  I wasn't clear on how the buffering and IO sessions worked in relation to the VISA library.  It there any documentation that I could read up on this just in case I have more questions?

 

0 Kudos
Message 4 of 5
(4,349 Views)
Hello XtxFirmEng:

Thank you for contacting National Instruments. Besides the help file which pblase provided, the VISA manual and these VISA links here may be helpful to you.
Regards,

Roland A.
Applications Engineer
National Instruments

Check out VI Roadshow
0 Kudos
Message 5 of 5
(4,332 Views)