11-27-2012 02:04 PM
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()
11-28-2012 03:22 PM
Anyone .. using this VISA NS ? Can help me ?
11-28-2012 04:09 PM
Have you looked at the FindResources example for C#?
It searcheds for valid resources.
11-28-2012 05:44 PM
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;
}