Beispiel #1
0
 public LoadedApplicationState(xPCApplication xpcApplication)
 {
     TargetStatus    = xpcApplication.Status;
     AverageTeT      = xpcApplication.AverageTeT;
     CpuOverload     = xpcApplication.CPUOverload;
     ExecutionTime   = xpcApplication.ExecTime;
     LoadedModelName = xpcApplication.Name;
 }
Beispiel #2
0
        public void TargetConnectionTests()
        {
            _targetPC = new xPCTargetPC();
            _targetPC.TcpIpTargetAddress = "192.168.7.1";
            _targetPC.TcpIpTargetPort    = "22222";
            _targetPC.Connect();

            _targetApplication = _targetPC.Load();
        }
Beispiel #3
0
        private void LoadButton_Click(object sender, EventArgs e)
        {
            if (xPCTarget.IsConnected == true)
            {
                try
                {
                    application = xPCTarget.Load("C:\\Users\\Closer\\Desktop\\matlab\\xpctank1.dlm");

                    // 设置hostScope来获取xPCTarget的信号信息
                    SetAppHostScopes();

                    xPCScopes scopes = application.Scopes;
                    xPCHostScopeCollection   hScopes = scopes.HostScopes;
                    xPCTargetScopeCollection tScopes = scopes.TargetScopes;

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

                    // 设置采样时间
                    application.SampleTime = 0.01;
                    // 设置结束时间 单位秒  -1是永不停止
                    application.StopTime = 360;
                    tScopes.StartAll();
                    hScopes.StartAll();
                    Console.WriteLine("load successfully");
                }
                catch (xPCException ex)
                {
                    Console.WriteLine(ex.Message);
                    MessageBox.Show(ex.Message);
                }
            }
            else
            {
                Console.WriteLine("please connect first");
                //Call the Disconnect methods to close the communication channel with the target PC.
                xPCTarget.Disconnect();
            }
        }
Beispiel #4
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);
            }
        }
Beispiel #5
0
        private void SetAppHostScopes()
        {
            try
            {
                // Initialize scopes.
                xPCApplication app = xPCTarget.Application;

                if (app.Status == xPCAppStatus.Running)
                {
                    app.Stop();
                }

                // Refresh all scopes.
                xPCScopes scopes = app.Scopes;
                scopes.RefreshAll();

                // Delete any existing host scopes.
                xPCHostScopeCollection hScopes = scopes.HostScopes;
                hScopes.Remove();

                // Add a host scope to capture data for signal display.
                this.refSc = hScopes.Add();
                // NumSamples是采样的数量,10000即采样10000次
                // application.StopTime = 360;运行360s
                // 每次采样间隔0.01s,采样5000次需要50s
                this.refSc.DataTimeObject.NumSamples = 5000;
                refSc.NumSamples = 5000;
                refSc.Signals.Add("SetPoint");
                refSc.Signals.Add("TankLevel");
                Console.WriteLine("in0");
            }
            catch (xPCException ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }