Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Session Returned by Open(resourceName) in NI-VISA in C# is valid ?

Hi ,

 

am using ResourceManager.GetLocalManager().Open(resourceName) NI-VISA in C# . The function returns a session , my question is how do we know if this session is a valid session or not? i.e by valid i mean can we use it to send and recieve the commands to this session?

 

e.g I can get the 2 sessions by using following resource strings GPIB0::0::INSTR GPIB0::2::INSTR without any exception from below code

 

try

{

good_session = ResourceManager.GetLocalManager().Open(GPIB0::0::INSTR);

bad_session = ResourceManager.GetLocalManager().Open("GPIB0::2::INSTR");

}

catch (Exceptions ex)

{

}

 

The good_session can return successful return value to *IDN? command but the bad session returns the timeout error. Which means the Bad session was actually invalid one. because the primary address at which device is listening was '0' not the '2'

 

Is there a way to find out this session was actually invalid from visa documentation ?

 

I checked the documents that viOpen() returns 3 different values  0x3FFF007D (VI_SUCCESS_DEV_NPRESENT) etc , How can we access the return values of viOpen in C# by calling Open()

 

 

 

 

0 Kudos
Message 1 of 4
(5,208 Views)

Anyone .. using this VISA NS ? Can help me ?

0 Kudos
Message 2 of 4
(5,185 Views)

Have you looked at the FindResources example for C#?

It searcheds for valid resources.

 

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

Yes i did , here is what they do .., thats the same i am also doing. But the problem if i execute their code and mention a wrong GPIB port number, there also i dont recieve any error it gives me a success as return value. Where as the viOpen() function returned VI_SUCCESS_DEV_NPRESENT meaning , session opened successfully, but the device at the specified address is not responding...

 

Any more suggestions pls 

 

private string ValidResourceName(string resourceName)
{
Session session = null;
string fullName = null;
try
{
session = ResourceManager.GetLocalManager().Open(resourceName);
fullName = session.ResourceName;
}
catch (VisaException)
{
// Don't do anything
}
catch (Exception ex)
{
    MessageBox.Show(ex.Message);
}

if (session != null)
{
    session.Dispose();
}

return fullName;
}

0 Kudos
Message 4 of 4
(5,176 Views)