CANoe_调用C#控件的方法_DEMO方法演示

news2024/10/11 17:00:10
1、DEMO存放位置
D:\Users\Public\Documents\Vector\CANoe\Sample Configurations 11.0.96\CAN\MoreExamples\ActiveX_DotNET_Panels

每个人的电脑因为有区别存放位置不一样

2、控件制作--使用C#控件可以直接制作

 3、控件代码
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.Diagnostics;

namespace CSharpPanels
{
    public class CSharpControl : System.Windows.Forms.UserControl
    {
        // Declare types
        private CANoe.Application         App;
        private CANoe.Measurement         Measurement;
        private CANoe.Variable            svMotorSwitch = null;
        private CANoe.Variable            svTurnSignal = null;
        private CANoe.Variable            svEngineSpeedEntry = null;
        private System.Windows.Forms.Timer tmrSignals;
                
        private System.Windows.Forms.GroupBox fraMotor;
        private System.Windows.Forms.GroupBox fraLight;
        private System.Windows.Forms.Label lblDriving;
        private System.Windows.Forms.Label lblTurn;
        private System.Windows.Forms.Button btnLightSwitch;
        private System.Windows.Forms.Button btnTurnSignal;
        private System.Windows.Forms.GroupBox fraEntry;
        private System.Windows.Forms.TrackBar sliSpeedEntry;
        private System.Windows.Forms.Button btnMotorSwitch;
        private System.Windows.Forms.Label lblCaption;
        
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components = null;

        public CSharpControl()
        {
            // This call is required by the Windows.Forms Form Designer.
            InitializeComponent();

            // Initialize timer to get Signal changes
            tmrSignals = new System.Windows.Forms.Timer(components);
            if (tmrSignals != null)
            {
                tmrSignals.Enabled = true;
                tmrSignals.Tick += new System.EventHandler(tmrSignals_Tick);
            }

            // Initialize types
            App            = new CANoe.Application();
            Measurement    = (CANoe.Measurement)App.Measurement;
            CANoe.System system = (CANoe.System)App.System;

            if (system != null)
            {
                CANoe.Namespaces namespaces = (CANoe.Namespaces)system.Namespaces;
                if (namespaces != null)
                {
                    CANoe.Namespace nsEngine = (CANoe.Namespace)namespaces["Engine"];
                    if (nsEngine != null)
                    {
                        CANoe.Variables engineVars = (CANoe.Variables)nsEngine.Variables;
                        if (engineVars != null)
                        {
                            svMotorSwitch = (CANoe.Variable)engineVars["MotorSwitch"];
                            svEngineSpeedEntry = (CANoe.Variable)engineVars["EngineSpeedEntry"];

                            if (svMotorSwitch != null)
                                svMotorSwitch.OnChange += new CANoe._IVariableEvents_OnChangeEventHandler(svMotorSwitch_OnChange);
                            if (svEngineSpeedEntry != null)
                                svEngineSpeedEntry.OnChange += new CANoe._IVariableEvents_OnChangeEventHandler(svEngineSpeedEntry_OnChange);
                        }
                    }
                    CANoe.Namespace nsLights = (CANoe.Namespace)namespaces["Lights"];
                    if (nsLights != null)
                    {
                        CANoe.Variables lightsVars = (CANoe.Variables)nsLights.Variables;
                        if (lightsVars != null)
                        {
                            svTurnSignal = (CANoe.Variable)lightsVars["TurnSignal"];

                            if (svTurnSignal != null)
                                svTurnSignal.OnChange += new CANoe._IVariableEvents_OnChangeEventHandler(svTurnSignal_OnChange);
                        }
                    }
                }
            }
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if( components != null )
                    components.Dispose();

                if (tmrSignals != null)
                    tmrSignals.Dispose();
            }
            base.Dispose( disposing );
        }

        #region Component Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify 
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
          this.components = new System.ComponentModel.Container();
          this.fraMotor = new System.Windows.Forms.GroupBox();
          this.btnMotorSwitch = new System.Windows.Forms.Button();
          this.fraLight = new System.Windows.Forms.GroupBox();
          this.btnTurnSignal = new System.Windows.Forms.Button();
          this.btnLightSwitch = new System.Windows.Forms.Button();
          this.lblTurn = new System.Windows.Forms.Label();
          this.lblDriving = new System.Windows.Forms.Label();
          this.fraEntry = new System.Windows.Forms.GroupBox();
          this.sliSpeedEntry = new System.Windows.Forms.TrackBar();
          this.lblCaption = new System.Windows.Forms.Label();
          this.fraMotor.SuspendLayout();
          this.fraLight.SuspendLayout();
          this.fraEntry.SuspendLayout();
          ((System.ComponentModel.ISupportInitialize)(this.sliSpeedEntry)).BeginInit();
          this.SuspendLayout();
          // 
          // fraMotor
          // 
          this.fraMotor.Controls.Add(this.btnMotorSwitch);
          this.fraMotor.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
          this.fraMotor.Location = new System.Drawing.Point(8, 32);
          this.fraMotor.Name = "fraMotor";
          this.fraMotor.Size = new System.Drawing.Size(104, 72);
          this.fraMotor.TabIndex = 0;
          this.fraMotor.TabStop = false;
          this.fraMotor.Text = "Motor Switch";
          // 
          // btnMotorSwitch
          // 
          this.btnMotorSwitch.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
          this.btnMotorSwitch.Location = new System.Drawing.Point(24, 32);
          this.btnMotorSwitch.Name = "btnMotorSwitch";
          this.btnMotorSwitch.Size = new System.Drawing.Size(56, 25);
          this.btnMotorSwitch.TabIndex = 0;
          this.btnMotorSwitch.Text = "Off";
          this.btnMotorSwitch.Click += new System.EventHandler(this.btnMotorSwitch_Click);
          // 
          // fraLight
          // 
          this.fraLight.Controls.Add(this.btnTurnSignal);
          this.fraLight.Controls.Add(this.btnLightSwitch);
          this.fraLight.Controls.Add(this.lblTurn);
          this.fraLight.Controls.Add(this.lblDriving);
          this.fraLight.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
          this.fraLight.Location = new System.Drawing.Point(120, 32);
          this.fraLight.Name = "fraLight";
          this.fraLight.Size = new System.Drawing.Size(136, 72);
          this.fraLight.TabIndex = 1;
          this.fraLight.TabStop = false;
          this.fraLight.Text = "Light Switch";
          // 
          // btnTurnSignal
          // 
          this.btnTurnSignal.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
          this.btnTurnSignal.Location = new System.Drawing.Point(78, 38);
          this.btnTurnSignal.Name = "btnTurnSignal";
          this.btnTurnSignal.Size = new System.Drawing.Size(40, 25);
          this.btnTurnSignal.TabIndex = 3;
          this.btnTurnSignal.Text = "Off";
          this.btnTurnSignal.Click += new System.EventHandler(this.btnTurnSignal_Click);
          // 
          // btnLightSwitch
          // 
          this.btnLightSwitch.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
          this.btnLightSwitch.Location = new System.Drawing.Point(14, 38);
          this.btnLightSwitch.Name = "btnLightSwitch";
          this.btnLightSwitch.Size = new System.Drawing.Size(40, 25);
          this.btnLightSwitch.TabIndex = 2;
          this.btnLightSwitch.Text = "Off";
          this.btnLightSwitch.Click += new System.EventHandler(this.btnLightSwitch_Click);
          // 
          // lblTurn
          // 
          this.lblTurn.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
          this.lblTurn.Location = new System.Drawing.Point(66, 20);
          this.lblTurn.Name = "lblTurn";
          this.lblTurn.Size = new System.Drawing.Size(66, 16);
          this.lblTurn.TabIndex = 1;
          this.lblTurn.Text = "Turn signal";
          // 
          // lblDriving
          // 
          this.lblDriving.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
          this.lblDriving.Location = new System.Drawing.Point(14, 20);
          this.lblDriving.Name = "lblDriving";
          this.lblDriving.Size = new System.Drawing.Size(48, 16);
          this.lblDriving.TabIndex = 0;
          this.lblDriving.Text = "Driving";
          // 
          // fraEntry
          // 
          this.fraEntry.Controls.Add(this.sliSpeedEntry);
          this.fraEntry.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
          this.fraEntry.Location = new System.Drawing.Point(8, 112);
          this.fraEntry.Name = "fraEntry";
          this.fraEntry.Size = new System.Drawing.Size(248, 72);
          this.fraEntry.TabIndex = 2;
          this.fraEntry.TabStop = false;
          this.fraEntry.Text = "Motor Entry";
          // 
          // sliSpeedEntry
          // 
          this.sliSpeedEntry.Location = new System.Drawing.Point(16, 24);
          this.sliSpeedEntry.Maximum = 3500;
          this.sliSpeedEntry.Name = "sliSpeedEntry";
          this.sliSpeedEntry.Size = new System.Drawing.Size(216, 45);
          this.sliSpeedEntry.TabIndex = 0;
          this.sliSpeedEntry.TickFrequency = 350;
          this.sliSpeedEntry.Scroll += new System.EventHandler(this.sliSpeedEntry_Scroll);
          // 
          // lblCaption
          // 
          this.lblCaption.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
          this.lblCaption.Location = new System.Drawing.Point(8, 8);
          this.lblCaption.Name = "lblCaption";
          this.lblCaption.Size = new System.Drawing.Size(256, 16);
          this.lblCaption.TabIndex = 3;
          this.lblCaption.Text = "C# Control";
          this.lblCaption.TextAlign = System.Drawing.ContentAlignment.TopCenter;
          // 
          // CSharpControl
          // 
          this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
          this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
          this.Controls.Add(this.lblCaption);
          this.Controls.Add(this.fraEntry);
          this.Controls.Add(this.fraLight);
          this.Controls.Add(this.fraMotor);
          this.Name = "CSharpControl";
          this.Size = new System.Drawing.Size(264, 192);
          this.fraMotor.ResumeLayout(false);
          this.fraLight.ResumeLayout(false);
          this.fraEntry.ResumeLayout(false);
          this.fraEntry.PerformLayout();
          ((System.ComponentModel.ISupportInitialize)(this.sliSpeedEntry)).EndInit();
          this.ResumeLayout(false);

        }
        #endregion

        private void btnMotorSwitch_Click(object sender, System.EventArgs e)
        {
            if (Measurement.Running)
            {
                if (svMotorSwitch != null)
                {
                    if (btnMotorSwitch.Text == "Off")
                    {
                        svMotorSwitch.Value = 1;
                        btnMotorSwitch.Text = "On";
                    }
                    else
                    {
                        svMotorSwitch.Value = 0;
                        btnMotorSwitch.Text = "Off";
                    }
                }
            }
        }

        private void svMotorSwitch_OnChange(object Value)
        {
            int tmp = (int)Value;
            if (tmp == 0)
            {
                btnMotorSwitch.Text = "Off";
            }
            else
            {
                btnMotorSwitch.Text = "On";
            }
        }

        private void btnLightSwitch_Click(object sender, System.EventArgs e)
        {
            if (Measurement.Running)
            {
                CANoe.Bus bus = null;
                try
                {
                    bus = (CANoe.Bus)App.get_Bus("CAN");
                    if (bus != null)
                    {
                        CANoe.Signal signal = (CANoe.Signal)bus.GetSignal(1, "LightState", "OnOff");
                        if (signal != null)
                        {
                            if (btnLightSwitch.Text == "Off")
                            {
                                signal.Value = 1;
                                btnLightSwitch.Text = "On";
                            }
                            else
                            {
                                signal.Value = 0;
                                btnLightSwitch.Text = "Off";
                            }
                        }
                    }
                }
                catch
                {
                }
            }
        }
   
        private void tmrSignals_Tick(object sender, System.EventArgs e)
        {
            // get all the signal values and actualize controls
            if (Measurement.Running)
            {
                CANoe.Bus bus = null;
                try
                {
                    bus = (CANoe.Bus)App.get_Bus("CAN");
                    if (bus != null)
                    {
                        CANoe.Signal signal = (CANoe.Signal)bus.GetSignal(1, "LightState", "OnOff");
                        if (signal != null)
                        {
                            if (signal.Value == 0)
                                btnLightSwitch.Text = "Off";
                            else
                                btnLightSwitch.Text = "On";
                        }
                    }
                }
                catch
                {
                }
            }
        }

        private void btnTurnSignal_Click(object sender, System.EventArgs e)
        {
            if (Measurement.Running)
            {
                if (btnTurnSignal.Text == "Off") 
                {
                    if (svTurnSignal != null)
                    {
                        svTurnSignal.Value = 1;
                        btnTurnSignal.Text = "On";
                    }
                }
                else
                {
                    if (svTurnSignal != null)
                    {
                        svTurnSignal.Value = 0;
                        btnTurnSignal.Text = "Off";
                    }
                }
            }
        }

        private void svTurnSignal_OnChange(object Value)
        {
            int tmp = (int)Value;
            if (tmp == 0)
            {
                btnTurnSignal.Text = "Off";
            }
            else
            {
                btnTurnSignal.Text = "On";
            }
        }

        private void sliSpeedEntry_Scroll(object sender, System.EventArgs e)
        {
            if(Measurement.Running)
            {
                if (svEngineSpeedEntry != null)
                {
                    double tmp = sliSpeedEntry.Value;
                    svEngineSpeedEntry.Value = tmp;
                }
            }
        }

        private void svEngineSpeedEntry_OnChange(object Value)
        {
            sliSpeedEntry.Value = (int)((double)Value);
        }
    }
}
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

namespace CSharpPanels
{
    public class CSharpDisplay : System.Windows.Forms.UserControl
    {
        // Declare types
        private CANoe.Application App;
      private CANoe.Measurement Measurement;
      internal GroupBox fraEngineSpeed;
      internal GroupBox fraMotor;
      internal GroupBox fraLight;
      internal Label lblEngine;
      internal Label lblRunning;
      internal Label lblDriving;
      internal Label lblTurn;
      internal Label lblDrivingState;
      internal Label lblTurnState;
      private System.Windows.Forms.Timer tmrSignals;
      internal Label lblCaption;
        private System.ComponentModel.IContainer components;

        public CSharpDisplay()
        {
            // This call is required by the Windows.Forms Form Designer.
            InitializeComponent();

            // Initialize types
            App         = new CANoe.Application();
            Measurement = (CANoe.Measurement)App.Measurement;
        }

        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if(components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }

        #region Component Designer generated code
        /// <summary> 
        /// Required method for Designer support - do not modify 
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            this.fraEngineSpeed = new System.Windows.Forms.GroupBox();
            this.lblEngine = new System.Windows.Forms.Label();
            this.fraMotor = new System.Windows.Forms.GroupBox();
            this.lblRunning = new System.Windows.Forms.Label();
            this.fraLight = new System.Windows.Forms.GroupBox();
            this.lblTurnState = new System.Windows.Forms.Label();
            this.lblDrivingState = new System.Windows.Forms.Label();
            this.lblTurn = new System.Windows.Forms.Label();
            this.lblDriving = new System.Windows.Forms.Label();
            this.tmrSignals = new System.Windows.Forms.Timer(this.components);
            this.lblCaption = new System.Windows.Forms.Label();
            this.fraEngineSpeed.SuspendLayout();
            this.fraMotor.SuspendLayout();
            this.fraLight.SuspendLayout();
            this.SuspendLayout();
            // 
            // fraEngineSpeed
            // 
            this.fraEngineSpeed.Controls.Add(this.lblEngine);
            this.fraEngineSpeed.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.fraEngineSpeed.Location = new System.Drawing.Point(6, 26);
            this.fraEngineSpeed.Name = "fraEngineSpeed";
            this.fraEngineSpeed.Size = new System.Drawing.Size(111, 39);
            this.fraEngineSpeed.TabIndex = 0;
            this.fraEngineSpeed.TabStop = false;
            this.fraEngineSpeed.Text = "Engine Speed";
            // 
            // lblEngine
            // 
            this.lblEngine.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.lblEngine.Location = new System.Drawing.Point(6, 14);
            this.lblEngine.Name = "lblEngine";
            this.lblEngine.Size = new System.Drawing.Size(101, 19);
            this.lblEngine.TabIndex = 0;
            this.lblEngine.Text = "0";
            this.lblEngine.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            // 
            // fraMotor
            // 
            this.fraMotor.Controls.Add(this.lblRunning);
            this.fraMotor.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.fraMotor.Location = new System.Drawing.Point(121, 26);
            this.fraMotor.Name = "fraMotor";
            this.fraMotor.Size = new System.Drawing.Size(99, 39);
            this.fraMotor.TabIndex = 1;
            this.fraMotor.TabStop = false;
            this.fraMotor.Text = "Motor State";
            // 
            // lblRunning
            // 
            this.lblRunning.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.lblRunning.Location = new System.Drawing.Point(6, 14);
            this.lblRunning.Name = "lblRunning";
            this.lblRunning.Size = new System.Drawing.Size(89, 19);
            this.lblRunning.TabIndex = 0;
            this.lblRunning.Text = "Not Running";
            this.lblRunning.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            // 
            // fraLight
            // 
            this.fraLight.Controls.Add(this.lblTurnState);
            this.fraLight.Controls.Add(this.lblDrivingState);
            this.fraLight.Controls.Add(this.lblTurn);
            this.fraLight.Controls.Add(this.lblDriving);
            this.fraLight.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.fraLight.Location = new System.Drawing.Point(6, 70);
            this.fraLight.Name = "fraLight";
            this.fraLight.Size = new System.Drawing.Size(214, 39);
            this.fraLight.TabIndex = 2;
            this.fraLight.TabStop = false;
            this.fraLight.Text = "Driving Light";
            // 
            // lblTurnState
            // 
            this.lblTurnState.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.lblTurnState.Location = new System.Drawing.Point(184, 17);
            this.lblTurnState.Name = "lblTurnState";
            this.lblTurnState.Size = new System.Drawing.Size(26, 15);
            this.lblTurnState.TabIndex = 3;
            this.lblTurnState.Text = "Off";
            this.lblTurnState.TextAlign = System.Drawing.ContentAlignment.TopRight;
            // 
            // lblDrivingState
            // 
            this.lblDrivingState.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.lblDrivingState.Location = new System.Drawing.Point(80, 17);
            this.lblDrivingState.Name = "lblDrivingState";
            this.lblDrivingState.Size = new System.Drawing.Size(26, 15);
            this.lblDrivingState.TabIndex = 2;
            this.lblDrivingState.Text = "Off";
            this.lblDrivingState.TextAlign = System.Drawing.ContentAlignment.TopRight;
            // 
            // lblTurn
            // 
            this.lblTurn.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.lblTurn.Location = new System.Drawing.Point(110, 17);
            this.lblTurn.Name = "lblTurn";
            this.lblTurn.Size = new System.Drawing.Size(76, 19);
            this.lblTurn.TabIndex = 1;
            this.lblTurn.Text = "Turn signal:";
            // 
            // lblDriving
            // 
            this.lblDriving.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.lblDriving.Location = new System.Drawing.Point(12, 17);
            this.lblDriving.Name = "lblDriving";
            this.lblDriving.Size = new System.Drawing.Size(63, 20);
            this.lblDriving.TabIndex = 0;
            this.lblDriving.Text = "Driving:";
            // 
            // tmrSignals
            // 
            this.tmrSignals.Enabled = true;
            this.tmrSignals.Tick += new System.EventHandler(this.tmrSignals_Tick);
            // 
            // lblCaption
            // 
            this.lblCaption.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Bold);
            this.lblCaption.Location = new System.Drawing.Point(6, 6);
            this.lblCaption.Name = "lblCaption";
            this.lblCaption.Size = new System.Drawing.Size(214, 17);
            this.lblCaption.TabIndex = 3;
            this.lblCaption.Text = "C# Display";
            this.lblCaption.TextAlign = System.Drawing.ContentAlignment.TopCenter;
            // 
            // CSharpDisplay
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.Controls.Add(this.lblCaption);
            this.Controls.Add(this.fraLight);
            this.Controls.Add(this.fraMotor);
            this.Controls.Add(this.fraEngineSpeed);
            this.Name = "CSharpDisplay";
            this.Size = new System.Drawing.Size(226, 117);
            this.fraEngineSpeed.ResumeLayout(false);
            this.fraMotor.ResumeLayout(false);
            this.fraLight.ResumeLayout(false);
            this.ResumeLayout(false);

        }
        #endregion

        private void tmrSignals_Tick(object sender, System.EventArgs e)
        {
            // get all the signal values and actualize controls
            if(Measurement.Running)
            {
                CANoe.Configuration configuration     = null;
                CANoe.SimulationSetup simulationSetup = null; 
                CANoe.Nodes nodes                     = null;
                CANoe.Node node                       = null;
                CANoe.Signals motorInputs             = null;
                CANoe.Signals motorControlInputs      = null;
                try
                {
                    configuration   = (CANoe.Configuration)App.Configuration;
                    simulationSetup = (CANoe.SimulationSetup)configuration.SimulationSetup;
                    nodes           = (CANoe.Nodes)simulationSetup.Nodes;
                    node            = (CANoe.Node)nodes["Motor"];
                    motorInputs     = (CANoe.Signals)node.Inputs;
                
                    if (motorInputs["OnOff"].Value == 0)
                    {
                        lblRunning.Text = "Not Running";
                    }
                    else
                    {
                        lblRunning.Text = "Running";
                    }

                    lblEngine.Text = motorInputs["EngineSpeed"].Value.ToString();
        
                    motorInputs = null;
                
                    node = (CANoe.Node)nodes["MotorControl"];
                    motorControlInputs = (CANoe.Signals)node.Inputs;
        
                    if(motorControlInputs["OnOff"].Value == 0)
                    {
                        lblDrivingState.Text = "Off";
                    }
                    else
                    {
                        lblDrivingState.Text = "On";
                    }

                    if(motorControlInputs["TurnSignal"].Value == 0)
                    {
                        lblTurnState.Text = "Off";
                    }
                    else
                    {
                        lblTurnState.Text = "On";
                    }
                }
                catch
                {
                }
                finally
                {
                    motorControlInputs = null;
                    node = null;
                    nodes = null;
                    simulationSetup = null;
                    configuration = null;
                }
            }
        }
    }
}
4、运行效果展示

 

 5、总结

现在啊,汽车电子这块儿技术发展得太快了,对测试和验证这些系统的需求也越来越多。CANoe呢,就像一个超级英雄的工具,专门用来模拟和测试汽车里的网络通信。我们想了个招儿,就是做几个自己定义的小工具,这样跟CANoe打交道就更直观了,能实时看着汽车信号怎么样,还能动手调调。

小工具是咋设计的:

我们做了两个小帮手,一个叫CSharpControl,负责接收你给的信号指令;另一个叫CSharpDisplay,就像个小喇叭,告诉你信号现在是啥状态。这样一分工,它们的职责就很清楚了,以后维护起来也方便,想加点新功能也容易。

信号是怎么处理的:

我们靠CANoe的超能力,实时拿到信号的状态,然后有个定时器(就像个小闹钟,我们叫它tmrSignals),不停地检查信号有没有变,一变就更新到界面上。这样你就能随时知道系统啥情况了,用起来更顺手。

事件驱动是咋回事:

我们还用了个挺聪明的方法,就是事件驱动。比如说你点个按钮,或者信号变了,就会触发一些程序去处理这些事情。这样写代码就更灵活了,以后想加新功能也不费劲。

资源管理这块儿也很重要:

我们得确保用的资源,比如CANoe里的对象和定时器,用完了都得好好收起来,别占着地方。所以我们在控件不用的时候,重写了个Dispose方法,让它们都能被正确回收,这样就不会浪费内存了。

界面长啥样:

界面设计嘛,我们想着得让用户用着舒服。所以用了一些分组框,把控件都归类放好了,看起来就整齐多了。每个区域都有名字,一看就知道是干啥的。

以后还能怎么发展:

现在的设计已经挺好了,但未来还能更上一层楼。比如说,想加更多控制信号和显示的功能,或者把CANoe的其他超能力,比如记录和分析数据,也集成进来。

最后说说感受:

这个项目让我们学会了怎么用C#和CANoe API做个很厉害的用户控件,跟汽车电子系统玩得转。设计得好,不仅现在开发起来快,以后维护、升级也方便。以后啊,我们还要继续挖掘新技能,让用户体验和系统性能都更上一层楼!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2205289.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

探索血糖人工智能预测可穿戴设备

导言 论文地址&#xff1a;https://arxiv.org/abs/2404.12605 数字生物标志物是一种新型医疗指标&#xff0c;其数据来源于可穿戴设备和智能手机等数字设备收集的数据。与从传统生物样本中提取的病理标志物不同&#xff0c;数字生物标志物能提供行为模式、生理节奏和环境因素的…

DBeaver的安装与使用

文章目录 前言一、DBeaver 的安装二、DBeaver 的基本使用三、DBeaver 的高级功能四、使用小技巧五、总结 前言 DBeaver 是一款广泛应用的数据库管理工具&#xff0c;支持多种数据库系统。以下是它的安装与使用方法。 一、DBeaver 的安装 下载 DBeaver: 前往 DBeaver 官方网站…

Vue工程化结构环境安装及搭建教程 : 之nvm

vue需要的环境&#xff1a; node.js : Node.js和Vue.js通常会一起使用。Node.js作为后端服务器&#xff0c;处理服务器端的逻辑和数据访问&#xff0c;而Vue.js则负责前端用户界面的构建和交互。通过Ajax通信&#xff0c;Vue.js应用程序向Node.js服务器发送请求&#xff0c;并…

Collection 集合框架

Collection 集合框架 各类集合 Set TreeSet 基于红黑树实现&#xff0c;支持有序性操作&#xff0c;例如根据一个范围查找元素的操作。但是查找效率不如 HashSet&#xff0c;HashSet 查找的时间复杂度为 O(1)&#xff0c;TreeSet 则为 O(logN)。 HashSet 基于哈希表实现&…

Python入门笔记(四)

文章目录 第九章 集合set9.1 创建集合&#xff1a;set()、集合生成式9.2 集合性质9.3 一些函数&#xff1a;issubset()、issuperset()、isdisjoint()9.4 集合增加元素&#xff1a;add()、update()9.5 集合删除元素&#xff1a;remove()、discard()、pop()、clear()9.6 创建不能…

ELM分类预测 | MATLAB实现ELM极限学习机多特征分类预测(二分类)

分类预测 | MATLAB实现ELM极限学习机多特征分类预测(二分类) 目录 分类预测 | MATLAB实现ELM极限学习机多特征分类预测(二分类)效果一览基本介绍程序设计学习总结参考资料效果一览 训练集正确率Accuracy = 89%(445/500) 测试集正确率Accuracy = 86.9565%(60/69) 基本介绍 MATLA…

《RabbitMQ篇》消费者轮询消费消息

当有多个消费者都在同一个队列中拿取消息时&#xff0c;会轮询从队列中拿取消息消费。 RabbitMQUtil类为工具类&#xff0c;获取Channel。 import com.rabbitmq.client.Channel; import com.rabbitmq.client.Connection; import com.rabbitmq.client.ConnectionFactory;public…

基于SSM的线上学习网站【附源码】

基于SSM的线上学习网站&#xff08;源码L文说明文档&#xff09; 目录 4 系统设计 4.1 系统结构设计 4.2系统结构 4.3.数据库设计 4.3.1数据库实体 4.3.2数据库设计表 5系统详细实现 5.1 管理员模块的实现 5.1.1 学生信息管理 5.1.2 教…

亚马逊云科技生成式 AI 认证正式上线!

为了更好帮助大家在人工智能领域入门及快速成长&#xff0c;助力企业发掘优秀人工智能人才&#xff0c;亚马逊云科技推出 AWS Certified AI Practitioner 认证&#xff0c;涵盖人工智能领域的必备技能、前沿技术和实践经验。 通过该认证&#xff0c;你将掌握设计考虑、RAG&…

大傻工具提示:没有找到c:\windows\system32\msrd3x43.dll

解决办法&#xff1a; 1、不用理会它&#xff0c;对串口工具运行没有任何影响。就算你下载了也没用&#xff0c;依然会有提示。 2、右键以管理员身份运行就不报错了。

医学大模型微调·数据处理全流程:炼丹,是自我超越的方法

医学大模型微调数据处理全流程&#xff1a;炼丹&#xff0c;是自我超越的方法 数据清洗脚本数据标注数据核验转为微调格式随机化 数据清洗脚本 HTML标签移除 去除文本中的所有HTML标签&#xff0c;保留纯文本内容。 特殊字符处理 替换特殊数字符号&#xff08;如①②③&#x…

如何保护源代码?十种有效方法实现源代码防泄密

在数字化时代&#xff0c;源代码的安全保护对于企业来说至关重要。源代码不仅是企业技术创新的成果&#xff0c;更是其核心竞争力的体现。一旦源代码泄露&#xff0c;不仅可能导致企业丧失市场优势&#xff0c;还可能引发知识产权纠纷、增加竞争对手的市场竞争力&#xff0c;甚…

k8s 1.28.2 集群部署 MinIO 分布式集群

文章目录 [toc]MinIO 介绍MinIO 生产硬件要求MinIO 存储要求MinIO 内存要求MinIO 网络要求MinIO 部署架构分布式 MinIO复制的 MinIO 部署 MinIO创建目录节点打标签创建 namespace创建 pv创建 MinIO配置 ingress问题记录通过代理服务器访问 MinIO 的 Object Browser 界面一直显示…

用echarts画天气预报

如图 上代码 <template><div id"temp15day"></div> </template><script setup> import * as echarts from "echarts"; const initChart () > {const machart echarts.init(document.getElementById("temp15day&q…

如何选择最合适的华为云数据库:指南与建议

在数字化转型的浪潮中&#xff0c;选择合适的数据库是企业成功的关键。华为云提供了多种数据库服务&#xff0c;以满足不同业务需求。以下是九河云总结的一些指南和建议&#xff0c;帮助您选择最合适的华为云数据库。 1. 了解业务需求 在选择数据库之前&#xff0c;首先需要了…

西米:未来的支付还能做吗?

未来支付行业还能做吗&#xff1f;一直是在洗牌&#xff0c;一直让你有上场的机会&#xff0c;做一个行业&#xff0c;最好的时间是行业刚刚开始&#xff0c;市场相对空白&#xff0c;跑马圈地&#xff0c;广撒网&#xff0c;利用时差赚钱&#xff0c;这是最好的时间。 另外&a…

【Kubernets】容器网络基础二:通讲CNI(Container Network Interface)容器网络接口实现方案

文章目录 背景知识Underlay网络Overlay网络一、基本概念二、工作原理三、实现方案四、应用场景 两者对比示意图 CNI实现有哪些&#xff1f;FlannelFlannel 的工作原理Flannel 的主要组件数据传输机制总结 Calico一、架构基础二、核心组件与功能三、路由与数据包转发四、安全策略…

Java微信支付接入(4) - API V3 API字典和相关工具

1. API列表 Native下单 - Native支付 | 微信支付商户文档中心 (qq.com) 以下是微信提供的 Native 支付的相关 API 微信提供了详细的请求接口和参数 2.接口规则 概述 - 通用规则 | 微信支付商户文档中心 (qq.com) 微信支付 APIv3 使用 JSON 作为消息体的数据交换格式。 JSO…

jupyterlab的安装与使用攻略

官网链接 Project Jupyter | Home 1.第一步安装 打开控制台 使用pip工具安装 pip install jupyterlab 如图 2.安装成功后启动 jupyter lab 会自动启动它的web页面 然后就可以正常使用咯&#xff01;&#xff01; 如果需要更换浏览器访问 新开控制台执行下面命令 jupy…

PowerJob做定时任务调度

提示&#xff1a;文章写完后&#xff0c;目录可以自动生成&#xff0c;如何生成可参考右边的帮助文档 文章目录 前言一、区别对比二、使用步骤1. 定时任务类型2.PowerJob搭建与部署 前言 提示&#xff1a;这里可以添加本文要记录的大概内容&#xff1a; PowerJob是基于java开…