예제 #1
0
파일: scpi.cs 프로젝트: ucdart/dart-scpi
        public int GetData(string sparam, out Double[] MagData, out Double[] PhaData)
        {
            string mode = GetMode();

            SetSmithChart();

            int numpoints = GetPoints();

            Double[] data = new Double[numpoints];

            IMessageBasedFormattedIO io = session.FormattedIO;

            write(":CALC1:PAR1:DEF " + sparam);

            Thread.Sleep(GetWaitTime(numpoints));
            write(":CALC1:DATA:FDAT?");
            io.Scanf("%,f", out data);

            MagData = new Double[numpoints];
            PhaData = new Double[numpoints];

            for (int i = 0; i < numpoints; i++)
            {
                double magnitude = data[i * 2];
                double phase     = data[i * 2 + 1];
                MagData[i] = magnitude;
                PhaData[i] = phase;
            }

            SetMode(mode);
            return(numpoints);
        }
예제 #2
0
 /// <summary>
 /// 关闭连接
 /// </summary>
 private void Disconnect()
 {
     if (ibfIo != null)
     {
         ibfIo = null;
     }
 }
예제 #3
0
        /// <summary>
        /// Dispose of the device connection.
        /// </summary>
        public void Close()
        {
            // Dispose of the instrument connection if it is not null.
            ((IDisposable)_instrument)?.Dispose();

            // Free the reference to the session.
            _instrument = null;
        }
예제 #4
0
파일: scpi.cs 프로젝트: ucdart/dart-scpi
        public void SetFrequency(double start, double end)
        {
            IMessageBasedFormattedIO io = session.FormattedIO;

            write(":SENS1:FREQ:STAR " + start.ToString());
            Thread.Sleep(10);
            write(":SENS1:FREQ:STOP " + end.ToString());
            Thread.Sleep(10);
        }
예제 #5
0
파일: scpi.cs 프로젝트: ucdart/dart-scpi
        public string GetMode()
        {
            IMessageBasedFormattedIO io = session.FormattedIO;

            write(":CALC1:FORM?");
            string mode = read();

            return(mode);
        }
예제 #6
0
파일: scpi.cs 프로젝트: ucdart/dart-scpi
        public int GetPoints()
        {
            IMessageBasedFormattedIO io = session.FormattedIO;

            write(":SENS:SWE:POIN?");
            long num = io.ReadInt64();

            Debug.Print("Num points: {0}", num);
            return((int)num);
        }
예제 #7
0
 /// <summary>
 /// 使用lvi.Visa库中的类打开与设备的会话(方式1)
 /// </summary>
 /// <param name="resourceName">资源名称,例如"TCPIP0::192.168.0.10::inst0::INSTR"</param>
 private void connectDevice(string resourceName)
 {
     try
     {
         ITcpipSession session = (ITcpipSession)GlobalResourceManager.Open(resourceName);
         ibfIo = session.FormattedIO;
         ShowMsg("*[" + DateTime.Now.ToString() + "] " + "Connect to the device successfully!:lvi.Visa.");
     }
     catch
     {
         lbxReception.Items.Add("*[" + DateTime.Now.ToString() + "] " + "Can't connect to the device!:lvi.Visa.");
     }
 }
예제 #8
0
파일: scpi.cs 프로젝트: ucdart/dart-scpi
        public double[] GetFrequencies()
        {
            int numpoints = GetPoints();

            Double[] frequencies = new Double[numpoints];

            IMessageBasedFormattedIO io = session.FormattedIO;

            write(":SENS1:FREQ:DATA?");
            Thread.Sleep(500);
            io.Scanf("%,f", out frequencies);
            return(frequencies);
        }
예제 #9
0
 public void Disconnect()
 {
     try
     {
         session.DisableEvent(EventType.AllEnabled);
         session.Clear();
         io      = null;
         session = null;
     }
     catch (Exception exception)
     {
         throw CreateThrowUpException(exception);
     }
 }
예제 #10
0
파일: scpi.cs 프로젝트: ucdart/dart-scpi
        public void write(string str)
        {
            IMessageBasedFormattedIO io = session.FormattedIO;

            try
            {
                io.PrintfAndFlush(str);
            }
            catch
            {
                Console.WriteLine("PrintfAndFlush failed");
                session.Dispose();
                session = null;
                return;
            }
        }
예제 #11
0
파일: scpi.cs 프로젝트: ucdart/dart-scpi
        public string read()
        {
            IMessageBasedFormattedIO io = session.FormattedIO;
            //string[] response = new string[] { "", "", "", "" };
            string response;

            try
            {
                response = io.ReadLine();
            }
            catch
            {
                Console.WriteLine("Scanf failed");
                session.Dispose();
                session = null;
                return(null);
            }

            Debug.WriteLine(response);
            return(response);
        }
예제 #12
0
        /// <summary>
        /// Search for and then open a device.
        /// </summary>
        /// <remarks>
        /// By default, the first USB device found is opened.
        /// </remarks>
        /// <param name="pattern">string to match in resource names</param>
        /// <param name="index">which of the instruments matching the pattern to open</param>
        public void Open(string pattern = VisaPattern.USB, int index = 0)
        {
            try
            {
                // Find all available instruments.
                string[] resourceStrings = Find(pattern).ToArray();

                // Open a connection to the desired instrument.
                _instrument = GlobalResourceManager.Open(resourceStrings[index]) as IMessageBasedFormattedIO;
            }
            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);
            }
            catch (IndexOutOfRangeException ex)
            {
                throw new DeviceCommunicationException("Device was not found."
                                                       + Environment.NewLine + "Details:"
                                                       + Environment.NewLine + ex.Message);
            }
        }
예제 #13
0
파일: scpi.cs 프로젝트: ucdart/dart-scpi
        public void SetMode(string mode)
        {
            IMessageBasedFormattedIO io = session.FormattedIO;

            write(":CALC1:FORM " + mode);
        }
예제 #14
0
파일: scpi.cs 프로젝트: ucdart/dart-scpi
        public void SetPoints(int num)
        {
            IMessageBasedFormattedIO io = session.FormattedIO;

            write(":SENS1:SWE:POIN " + num.ToString());
        }
예제 #15
0
        public void Connect(string deviceName, VISASessionType sessionType)
        {
            switch (sessionType)
            {
            case VISASessionType.USB:
            {
                session = new UsbSession(deviceName);
                break;
            }

            case VISASessionType.Serial:
            {
                session = new SerialSession(deviceName);
                break;
            }

            case VISASessionType.TcpIp:
            {
                session = new TcpipSession(deviceName);
                break;
            }

            case VISASessionType.TcpIpSocket:
            {
                session = new TcpipSocketSession(deviceName);
                break;
            }

            case VISASessionType.GPIB:
            {
                session = new GpibSession(deviceName);
                break;
            }

            case VISASessionType.PXI:
            {
                registerSession = new PxiSession(deviceName);
                break;
            }

            case VISASessionType.VXI:
            {
                session = new VxiSession(deviceName);
                break;
            }

            default:
                break;
            }

            if (session != null)
            {
                try
                {
                    session.EnableEvent(EventType.UsbInterrupt);
                    io = session.FormattedIO;

                    return;
                }
                catch (Exception exception)
                {
                    throw CreateThrowUpException(exception);
                }
            }
        }