返回首页

{S0的} 介绍远程控制桌面的测试仪器,包括物理连接的instrumentnbsp; 计算机使用GPIB,USB,以太网,LXI局域网和串行端口,通过仪器的命令集设置的测量条件下,获得的测量resultsnbsp和记录测量进一步analysis.nbsp结果;有些厂商(美国国家仪器公司,安捷伦,罗德施瓦茨,吉时利,泰克...)提供了一个广泛的各种各样的仪器控制硬件和软件工具,帮助,整个生活的仪器控制,节省时间和金钱系统。提高性能与总线的硬件和GPIB,USB,以太网,LXI的,局域网,和序列,同时由于提高生产力的软件工具,如Visual Studio的C#中的NI LabVIEW,Agilent VEE的和预制仪器drivers.nbsp优势提高可靠性;准备使用的仪器驱动程序可能不适合我们的需求,因为我们需要自定义应用程序和测量厂商从来不知道。因此,开发仪器驱动程序,使用直接I / O命令(命令设置与测试仪器的用户/编程手册提供),解决自定义驱动程序的要求。本文介绍了如何远程控制桌面的电子测试仪器(在这种情况下,安捷伦N9010A)步步使用#以上LAN.nbspÇ;背景与,可以使用电脑连接到桌面的工具,并进行测量。有几种不同的方式来控制仪器??您可以使用一个仪器驱动程序,或通过直接I / O命令控制仪器(见图1)。{S}图1。越来越Startednbsp;
在本教程中,我们将与仪器沟通{A2的}。我们是沟通的仪器是安捷伦N9010A IP 192.168.1.47和端口号5025。(见图){S2的}图2。 N9010A 通信用户界面要做到这一点,我们需要使用Visual Studio 2010创建新的Windows项目,因此,点击文件 - >新建项目。然后给一个项目的名称和位置(见图3-1){中三}Figure3.N9010A项目设置创建一个VS的C#。NET项目后,我们开始设计我们的用户界面(UI)。我们的UI包括下列控制和相关的属性; Table1.Instrument控制Formnbsp;controlnbsp;名称文本Windows.FormsMainForm的N9010A通讯超过Windows.Forms.ButtonbtnConnect放大器连接Windows.Forms.TextBox 5025Windows.Forms.TextBoxtbSAAddress192.168.1.47Windows.Forms.LabellblIDN这个控制文本填写*国际化域名(IDN)?查询从N9010AWindows.Forms.LabellabelControl1Windows.Forms.LabellabelControl2SA的端口: Windows.Forms.LabellabelControl3国际化域名(IDN):Windows.Forms.ToolStripMenuItemtsmiFile文件Windows.Forms.ToolStripMenuItemtsmiExit出口在名为N9010A下面的类,我们打算写一个N9010A通信infrastructue。的WriteLine(字符串命令)的方法,发送命令到仪器附加quot; \ nquot;这quot; \ nquot;字符作为EOL的表示年底command.nbsp,已知的readLine methodnbsp;读取仪器响应远程命令发送bynbsp的WriteLine(字符串命令) 为ASCII string.nbsp的回报; NBSP ;

using System;

using System.Text;

using System.Net.Sockets;

using System.Net;



namespace N90101A

{

    // N9010A Spectrumm Analyzer Class

    public class N9010A

    {

        //N9010A IP Address

        private string IpAddr;

        //N9010A Port number

        private int PortNumber;

        //a network endpoint as an IP address and a port number

        private IPEndPoint ip = null;

        //IPEndPoint property for N9010A

        public IPEndPoint Ip

        {

            get

            {

                if (ip == null)

                    ip = new IPEndPoint(IPAddress.Parse(this.IpAddr), this.PortNumber);

                return ip;

            }

            set { ip = value; }

        }

        //N9010A Spectrum Analyzer Constructor

        //instrIPAddress:N9010A IP Address,ex:"192.168.001.047"

        //instrPortNo:N9010A Port Number, ex:5025

        public N9010A(string instrIPAddress, int instrPortNo)

        {

            this.IpAddr = instrIPAddress;

            this.PortNumber = instrPortNo;



            if (!Soket.Connected)

                throw new ApplicationException("Instrument at "+ this.Ip.Address + ":" + this.Ip.Port + " is not connected");

        }



        //Writes an remote command to an N9010A with "\n"

        public void writeLine(string command)

        {

            Soket.Send(Encoding.ASCII.GetBytes(command + "\n"));

        }

        //Reads the N9010A response as string to a command sent with writeLine method

        public string readLine()

        {

            byte[] data = new byte[1024];

            int receivedDataLength = Soket.Receive(data);

            return Encoding.ASCII.GetString(data, 0, receivedDataLength);

        }



        Socket soket = null;



        //TCPIP connection to a N9010A

        public Socket Soket

        {

            get

            {

                if (soket == null)

                {

                    soket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

                    try

                    {

                        if (!soket.Connected)

                            soket.Connect(this.Ip);

                    }

                    //Throw an exception if not connected

                    catch (SocketException e)

                    {

                        Console.WriteLine("Unable to connect to server.");

                        throw new ApplicationException("Instrument at "+ this.Ip.Address + ":" + this.Ip.Port + " is not connected");

                    }

                }

                return soket;

            }

            set { soket = value; }

        }

    }

}

让我们设计一个表格,使我们可以沟通与仪器,N9010A。 Table1中,我们在表格上使用的控制。
MainForm类如下{C}
从频谱分析仪获得的IDN响应是作为folllows的:{S4}的提高N9010A类
它是改善N9010A加入更多methods.One的类的时间可以延长通过创造新的类库项目。dll的类N9010A
        

        // Adjusts the N9010A's RBW, VBW and Sweep Time

        // <param name="rbw" />RBW in MHz

        // <param name="vbw" />VBW in MHz

        // <param name="swe" />Sweep Auto 0-->OFF, 1-->ON

        public void saRbwVbwSweTime(double rbw, double vbw, byte swe)

        {

            writeLine("BAND " + rbw + " MHZ");

            writeLine("BAND:VID " + vbw + " MHZ");

            writeLine("SWE:TIME:AUTO " + (swe == 0 ? "OFF":"ON"));

        }



//Read the Marker Peak values and return the marker1 frequency to SAFreqOut, amplitude value to SAAmpOut

public void readMarker1Peak(out double SAFreqOut, out double SAAmpOut)

        {

            writeLine(":CALC:MARK1:STAT ON");

            writeLine(":CALC:MARK1:MAX");//Do a peak search

            writeLine(":CALC:MARK1:X?");//Query the marker peak value

            SAFreqOut = double.Parse(readDouble())/1E6;//in MHz

            writeLine(":CALC:MARK1:Y?");

            SAAmpOut = double.Parse(readLine());

        }

conclusionnbsp;在本教程中,Inbsp;解释如何远程控制Electronicnbsp测试仪通过LAN和开发仪器驱动程序,无需签证库和仪器制造商的设备驱动程序(dll文件,驱动程序文件...)。为了延长的N9010A类,可以编写和添加更多的方法,一个类,并发展为更多的文章访问{A5的} NBSP instrument.For自定义驱动程序。| ceken

回答

评论会员: 时间:2