Пример #1
0
 private void RunButton_Click(object sender, EventArgs e)
 {
     try
     {
         application.Start();
         Console.WriteLine("run succesfully");
     }
     catch (xPCException ex)
     {
         xPCTarget.Disconnect();
         Console.WriteLine(ex.Message);
         MessageBox.Show(ex.Message);
     }
 }
Пример #2
0
        void demo()
        {
            // xPCTargetPC设置IP和端口
            xPCTargetPC xPCTarget = new xPCTargetPC();

            xPCTarget.TcpIpTargetAddress = "192.168.88.189";
            xPCTarget.TcpIpTargetPort    = "22222";
            try
            {
                // 建立连接
                xPCTarget.Connect();
                if (xPCTarget.IsConnected == true)
                {
                    Console.WriteLine(true);
                    // 装载模型,并获取target机的应用
                    xPCApplication           application = xPCTarget.Load("C:\\Users\\Closer\\Desktop\\matlab\\xpctank1.dlm");
                    xPCTargetScopeCollection tScopes     = application.Scopes.TargetScopes;
                    tScopes.Refresh();

                    // 指定参数
                    xPCParameters param = xPCTarget.Application.Parameters;
                    // 先清空参数
                    param.Refresh();
                    // 获取参数的坐标和参数名
                    xPCParameter p      = param["SetPoint", "Value"];
                    Double[]     values = new Double[] { 5.0 };
                    // 指定参数值
                    p.SetParam(values);

                    // 设置采样时间
                    application.SampleTime = 0.01;
                    // 设置结束时间 单位秒  -1是永不停止
                    application.StopTime = 60;
                    // target机开始运行
                    application.Start();
                }
                else
                {
                    //Call the Disconnect methods to close the communication channel with the target PC.
                    xPCTarget.Disconnect();
                }
            }
            catch (xPCException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }