Пример #1
0
        static bool Find(string searchString, ref List <KeysightDevice> deviceList)
        {
            IEnumerable <string> devices;

            try
            {
                devices = GlobalResourceManager.Find(searchString);

                foreach (string device in devices)
                {
                    //Console.WriteLine("\tAddress: {0}, Alias: {1}", device, GlobalResourceManager.Parse(device).AliasIfExists);
                    KeysightDevice d = new KeysightDevice
                    {
                        VisaAddress = device,
                        Alias       = GlobalResourceManager.Parse(device).AliasIfExists
                    };
                    deviceList.Add(d);
                }
                return(true);
            }
            catch (VisaException ex)
            {
                return(false);
            }
        }
Пример #2
0
        public static string[] FindGPIBAddresses()
        {
            IEnumerable <string> result = new List <string>();

            try
            {
                result = GlobalResourceManager.Find($"GPIB?*INSTR");
            }
            catch (Exception ex)
            {
                if (!(ex is NativeVisaException))
                {
                    if (ex.InnerException != null)
                    {
                        throw ex.InnerException;
                    }
                    else
                    {
                        throw ex;
                    }
                }
            }

            return(result.ToArray().Where(n => !n.Contains("//")).ToArray());
        }
Пример #3
0
        static void Main(string[] args)
        {
            IEnumerable <string> devices;

            try
            {
                // Finding all devices and interfaces is straightforward
                Console.WriteLine("Find all devices and interfaces:");
                devices = GlobalResourceManager.Find();

                foreach (string device in devices)
                {
                    Console.WriteLine("\tAddress: {0}, Alias: {1}", device, GlobalResourceManager.Parse(device).AliasIfExists);
                }
            }
            catch (VisaException ex)
            {
                Console.WriteLine("Didn't find any devices!");
            }
            Console.WriteLine();

            // You can specify other device types using different search strings. Here are some common examples:

            // All instruments (no INTFC, BACKPLANE or MEMACC)
            Find("?*INSTR");
            // PXI modules
            Find("PXI?*INSTR");
            // USB devices
            Find("USB?*INSTR");
            // GPIB instruments
            Find("GPIB?*");
            // GPIB interfaces
            Find("GPIB?*INTFC");
            // GPIB instruments on the GPIB0 interface
            Find("GPIB0?*INSTR");
            // LAN instruments
            Find("TCPIP?*");
            // SOCKET (::SOCKET) instruments
            Find("TCPIP?*SOCKET");
            // VXI-11 (inst) instruments
            Find("TCPIP?*inst?*INSTR");
            // HiSLIP (hislip) instruments
            Find("TCPIP?*hislip?*INSTR");
            // RS-232 instruments
            Find("ASRL?*INSTR");

            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
Пример #4
0
        /// <summary>
        /// Search for a device matching a specific pattern.
        /// </summary>
        /// <remarks>
        /// Several common patterns are included in this class.
        /// You can use this method to narrow your search, then use Open()
        /// with the same pattern to open an instrument.
        /// </remarks>
        /// <param name="pattern">string to match in resource names</param>
        /// <returns>list of resource names that include pattern</returns>
        public static IEnumerable <string> Find(string pattern = VisaPattern.USB)
        {
            IEnumerable <string> resourceNames;

            try
            {
                resourceNames = GlobalResourceManager.Find(pattern).ToList();
            }
            catch (EntryPointNotFoundException ex)
            {
                throw new DevicePortException("The IVI.VISA dll appears to be missing."
                                              + Environment.NewLine + "It must be installed as a separate package."
                                              + Environment.NewLine + "Details:"
                                              + Environment.NewLine + ex.Message);
            }

            return(resourceNames);
        }
Пример #5
0
        /// <summary>
        /// Returns a ConnectedDevicestruct that contains information about the VISA devices of device type DeviceType.* connected to the system.
        /// Only devices that can be located by a VISA
        /// library can be found by this function, e.g. something connected using raw sockets over LAN won't work.
        /// NOT THREAD SAFE. This is best used before any regular I/O transfer has started in your program.
        /// </summary>
        /// <remarks>Look at ConnectedDeviceStruct documentation for additional info.</remarks>
        /// <returns>a ConnectedDeviceStruct, containing information about connected Devices of the passed in device type</returns>
        /// <exception cref="System.Runtime.InteropServices.ExternalException">Thrown if the program cannot locate a valid
        /// VISA implementation on the system. There are no checked exceptions in C# but please,
        /// handle this one with a message in ANY application you build with this library.</exception>
        public static ConnectedDeviceStruct <T> GetConnectedDevices <T>() where T : VISADevice, ITestAndMeasurement
        {
            IEnumerable <string> resources;
            IMessageBasedSession searcherMBS;
            List <string>        connectedDeviceModels = new List <string>(); // get a list of connected VISA device model names
            List <string>        rawVISAIDs            = new List <string>(); // get a list of connect VISA devices' returned IDs
            List <T>             toReturn = new List <T>();
            bool unknownDeviceFound       = false;

            try
            {
                resources = GlobalResourceManager.Find("?*");                            // find all connected VISA devices
                foreach (string s in resources)                                          // after this loop, connectedDeviceModels contains a list of connected devices in the form <Model>
                {
                    rawVISAIDs.Add(s);                                                   // we need to add
                    string IDNResponse;
                    searcherMBS = GlobalResourceManager.Open(s) as IMessageBasedSession; // open the message session
                    searcherMBS.FormattedIO.WriteLine("*IDN?");                          // All SCPI compliant devices (and therefore all VISA devices) are required to respon to *IDN?
                    IDNResponse = searcherMBS.FormattedIO.ReadLine();
                    string[] tokens             = IDNResponse.Split(',');                // hopefully this isn't too slow
                    string   formattedIDNString = tokens[1];                             // we run the IDN command on all connected devices
                                                                                         // and then parse the response into the form <Model>
                    connectedDeviceModels.Add(formattedIDNString);
                }
                for (int i = 0; i < connectedDeviceModels.Count; i++)  // connectedDeviceModels.Count() == rawVISAIDs.Count()
                {
                    T temp = GetDeviceFromModelString <T>(connectedDeviceModels[i], rawVISAIDs[i]);
                    if (temp == null)
                    {
                        unknownDeviceFound = true;  // if there's one
                    }
                    else
                    {
                        toReturn.Add(temp);
                    }
                }
                return(new ConnectedDeviceStruct <T>(toReturn.ToArray(), unknownDeviceFound));
            }
            catch (VisaException)  // if no devices are found, return a struct with an array of size 0
            {
                return(new ConnectedDeviceStruct <T>(new T[0], false));
            }
        }
Пример #6
0
        static void Find(string searchString)
        {
            IEnumerable <string> devices;

            try
            {
                Console.WriteLine("Find with search string \"" + searchString + "\"");
                devices = GlobalResourceManager.Find(searchString);

                foreach (string device in devices)
                {
                    Console.WriteLine("\tAddress: {0}, Alias: {1}", device, GlobalResourceManager.Parse(device).AliasIfExists);
                }
            }
            catch (VisaException ex)
            {
                Console.WriteLine("... didn't find anything!");
            }
            Console.WriteLine();
        }
Пример #7
0
        private void button1_Click(object sender, EventArgs e)
        {
            label1.Show();
            listBox1.Show();
            IEnumerable <string> devices;

            try
            {
                devices = GlobalResourceManager.Find();
                var every2ndElement = devices.Where((p, index) => index % 2 == 0);
                foreach (string device in every2ndElement)
                {
                    listBox1.Items.Add(device);
                }
                this.listBox1.MouseClick += new MouseEventHandler(listBox1_MouseClick);
            }
            catch (VisaException ex)
            {
                MessageBox.Show("Инструментов не найдено");
            }
        }
Пример #8
0
        public static bool FindDevices(INTERFACE_TYPE interfaceType, out List <KeysightDevice> deviceList, out string outMessage)
        {
            deviceList = new List <KeysightDevice>();
            outMessage = string.Empty;
            IEnumerable <string> devices;

            try
            {
                // Finding all devices and interfaces is straightforward
                devices = GlobalResourceManager.Find();

                //foreach (string device in devices)
                //{
                //  Console.WriteLine("\tAddress: {0}, Alias: {1}", device, GlobalResourceManager.Parse(device).AliasIfExists);
                //}
            }
            catch (VisaException ex)
            {
                outMessage = "Didn't find any devices!" + ex.Message;
                return(false);
            }

            bool b = false;

            // All instruments (no INTFC, BACKPLANE or MEMACC)
            //Find("?*INSTR");
            if (interfaceType == INTERFACE_TYPE.PXI)
            {
                // PXI modules
                b = Find("PXI?*INSTR", ref deviceList);
            }
            if (interfaceType == INTERFACE_TYPE.USB)
            {
                // USB devices
                b = Find("USB?*INSTR", ref deviceList);
            }
            if (interfaceType == INTERFACE_TYPE.GPIB)
            {
                // GPIB instruments
                b = Find("GPIB?*", ref deviceList);
                // GPIB interfaces
                b = Find("GPIB?*INTFC", ref deviceList);
                // GPIB instruments on the GPIB0 interface
                b = Find("GPIB0?*INSTR", ref deviceList);
            }
            if (interfaceType == INTERFACE_TYPE.TCPIP_LAN)
            {
                // LAN instruments
                b = Find("TCPIP?*", ref deviceList);
            }
            if (interfaceType == INTERFACE_TYPE.TCPIP_SOCKET)
            {
                // SOCKET (::SOCKET) instruments
                b = Find("TCPIP?*SOCKET", ref deviceList);
            }

            if (interfaceType == INTERFACE_TYPE.VXI_11)
            {
                // VXI-11 (inst) instruments
                b = Find("TCPIP?*inst?*INSTR", ref deviceList);
            }

            if (interfaceType == INTERFACE_TYPE.HiSLIP)
            {
                // HiSLIP (hislip) instruments
                b = Find("TCPIP?*hislip?*INSTR", ref deviceList);
            }
            if (interfaceType == INTERFACE_TYPE.ASRL)
            {
                // RS-232 instruments
                b = Find("ASRL?*INSTR", ref deviceList);
            }
            return(b);
        }