02-04-2018 02:34 PM
Hello ,
In my C# application to control an oscilloscope I am trying to find the list of devices connected so after I can connect using ResourceManager.Open(strDevice)
I found a syntax error in the rm.find
I would appreciate if somebody can help me to get the right syntax to find the list of devices and connect
Follows my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NationalInstruments.Visa;
using Ivi.Visa;
namespace Oscilloscope_Test
{
class DeviceTest
{
public ResourceManager rm = new ResourceManager();
public MessageBasedSession visaSession;
public string[] ListDevices()
{
string[] device = rm.Find("(ASRL|GPIB|TCPIP|USB)?*"); // Error here wrong sintaxis
return device;
}
}
thanks
02-06-2018 03:35 AM
Hi,
Thank you for posting this question. I would like to check up on this post since no one in the community has gotten back to you yet. I have a couple of questions to clarify the issue:
1. Do you get a more detailed error message? If so, please include it. An error code especially would be helpful.
2. Please try finding only ASRL, GPIB, TCP IP, USB separately and see if you still get a syntax error.
Best regards,
Sara Nordin Hällgren
Applications Engineer
National Instruments
02-12-2018 02:30 PM
Thanks Sara, I appreciate your assistance
I think I may have 2 problems in the code (in red error messages):
1.Some syntax problem or variable type
It is mainly underlining in red this part of the line:
string[] device = rm.Find("(ASRL|GPIB|TCPIP|USB)?*");
“Cannot implicitly convert type ‘System.Collections.Generic.IEnumerable <string> to string[]. An explicit conversion exist(are you missing a cast?)”
If I declare device as string:
string device = rm.Find("(ASRL|GPIB|TCPIP|USB)?*");
“Cannot implicitly convert type ‘System.Collections.Generic.IEnumerable <string> to string
But also if I tried basic instructions like just connect and my device id:
string device = rm.Open("USB0::0x1AB1::0x04CE::DS1ZA190300641::INSTR");
(Still underlined in red)
“The type ’IVisaSession is definded in an assembly that is not referenced. You must add a reference to assembly’Ivi.Visa,Version=5.6.0.0,Culture=neutral,PublicKeyToken=a18c98f1d7717c1’”
I have added in the reference the : NationalInstruments.Visa.dll
C:\Program Files (x86)\IVI Foundation\VISA\Microsoft.NET\Framework32\v4.0.30319\NI VISA.NET 17.0.
And also added the: IviVIsa.Interop.dll
C:\WINDOWS\assembly\GAC_64\Ivi.Visa.Interop\5.8.0.0__a128c98f1d7717c1\
Seems like Find() or Open() are not define in my dlls, do I need an special dll or maybe there is an easier way to open ,fine a device???
Thank you in advance
02-14-2018 09:28 AM
Is the answer to No 1:
List<string> device = rm.Find("(ASRL|GPIB|TCPIP|USB)?*");
03-03-2020 03:32 AM
I noticed this is a bit old, but answering since no one else did.
For
string[] device = rm.Find("(ASRL|GPIB|TCPIP|USB)?*");
“Cannot implicitly convert type ‘System.Collections.Generic.IEnumerable <string> to string[]. An explicit conversion exist(are you missing a cast?)”
Do a casting for the above, like
var devices = rm.Find("(ASRL|GPIB|TCPIP|USB)?*");
string[] devicesArr = devices.ToArray();
For the 1b error, if you want access one of the device, please use a search condition or access by index after you convert to array. If you didn't get what I meant, google "c# linq first"
For 1c, add a reference to the Ivi.Visa.
I didn't quite understand your 2nd question, but the ResourceManager is defined in the Ivi.Visa. Add a reference to that dll in your project and you should see those methods.