|
|
@@ -2,6 +2,7 @@ using System;
|
|
|
using System.Windows.Forms;
|
|
|
using System.Drawing;
|
|
|
using CCDCount.DLL.CanBus;
|
|
|
+using CanTest;
|
|
|
|
|
|
namespace CanOpenSlaveTest
|
|
|
{
|
|
|
@@ -30,7 +31,8 @@ namespace CanOpenSlaveTest
|
|
|
private Button btnConfigureHeartbeat;
|
|
|
|
|
|
private TextBox txtLog;
|
|
|
-
|
|
|
+ private Label lblHeartbeat;
|
|
|
+ private System.ComponentModel.IContainer components;
|
|
|
private System.Windows.Forms.Timer m_updateTimer;
|
|
|
|
|
|
public SlaveTestForm()
|
|
|
@@ -57,126 +59,216 @@ namespace CanOpenSlaveTest
|
|
|
|
|
|
private void InitializeComponent()
|
|
|
{
|
|
|
+ this.components = new System.ComponentModel.Container();
|
|
|
+ this.grpDeviceInfo = new System.Windows.Forms.GroupBox();
|
|
|
+ this.lblNodeId = new System.Windows.Forms.Label();
|
|
|
+ this.lblState = new System.Windows.Forms.Label();
|
|
|
+ this.lblStatus = new System.Windows.Forms.Label();
|
|
|
+ this.grpControl = new System.Windows.Forms.GroupBox();
|
|
|
+ this.btnStart = new System.Windows.Forms.Button();
|
|
|
+ this.btnStop = new System.Windows.Forms.Button();
|
|
|
+ this.btnSendTpdo1 = new System.Windows.Forms.Button();
|
|
|
+ this.btnSendTpdo2 = new System.Windows.Forms.Button();
|
|
|
+ this.btnSendAllTpdos = new System.Windows.Forms.Button();
|
|
|
+ this.grpHeartbeat = new System.Windows.Forms.GroupBox();
|
|
|
+ this.lblHeartbeat = new System.Windows.Forms.Label();
|
|
|
+ this.nudHeartbeatTime = new System.Windows.Forms.NumericUpDown();
|
|
|
+ this.btnConfigureHeartbeat = new System.Windows.Forms.Button();
|
|
|
+ this.txtLog = new System.Windows.Forms.TextBox();
|
|
|
+ this.m_updateTimer = new System.Windows.Forms.Timer(this.components);
|
|
|
+ this.grpDeviceInfo.SuspendLayout();
|
|
|
+ this.grpControl.SuspendLayout();
|
|
|
+ this.grpHeartbeat.SuspendLayout();
|
|
|
+ ((System.ComponentModel.ISupportInitialize)(this.nudHeartbeatTime)).BeginInit();
|
|
|
+ this.SuspendLayout();
|
|
|
+ //
|
|
|
+ // grpDeviceInfo
|
|
|
+ //
|
|
|
+ this.grpDeviceInfo.Controls.Add(this.lblNodeId);
|
|
|
+ this.grpDeviceInfo.Controls.Add(this.lblState);
|
|
|
+ this.grpDeviceInfo.Controls.Add(this.lblStatus);
|
|
|
+ this.grpDeviceInfo.Location = new System.Drawing.Point(10, 10);
|
|
|
+ this.grpDeviceInfo.Name = "grpDeviceInfo";
|
|
|
+ this.grpDeviceInfo.Size = new System.Drawing.Size(380, 100);
|
|
|
+ this.grpDeviceInfo.TabIndex = 0;
|
|
|
+ this.grpDeviceInfo.TabStop = false;
|
|
|
+ this.grpDeviceInfo.Text = "设备信息";
|
|
|
+ //
|
|
|
+ // lblNodeId
|
|
|
+ //
|
|
|
+ this.lblNodeId.AutoSize = true;
|
|
|
+ this.lblNodeId.Location = new System.Drawing.Point(10, 25);
|
|
|
+ this.lblNodeId.Name = "lblNodeId";
|
|
|
+ this.lblNodeId.Size = new System.Drawing.Size(77, 15);
|
|
|
+ this.lblNodeId.TabIndex = 0;
|
|
|
+ this.lblNodeId.Text = "节点ID: -";
|
|
|
+ //
|
|
|
+ // lblState
|
|
|
+ //
|
|
|
+ this.lblState.AutoSize = true;
|
|
|
+ this.lblState.Location = new System.Drawing.Point(10, 50);
|
|
|
+ this.lblState.Name = "lblState";
|
|
|
+ this.lblState.Size = new System.Drawing.Size(61, 15);
|
|
|
+ this.lblState.TabIndex = 1;
|
|
|
+ this.lblState.Text = "状态: -";
|
|
|
+ //
|
|
|
+ // lblStatus
|
|
|
+ //
|
|
|
+ this.lblStatus.AutoSize = true;
|
|
|
+ this.lblStatus.Location = new System.Drawing.Point(10, 75);
|
|
|
+ this.lblStatus.Name = "lblStatus";
|
|
|
+ this.lblStatus.Size = new System.Drawing.Size(128, 15);
|
|
|
+ this.lblStatus.TabIndex = 2;
|
|
|
+ this.lblStatus.Text = "运行状态: 未启动";
|
|
|
+ //
|
|
|
+ // grpControl
|
|
|
+ //
|
|
|
+ this.grpControl.Controls.Add(this.btnStart);
|
|
|
+ this.grpControl.Controls.Add(this.btnStop);
|
|
|
+ this.grpControl.Controls.Add(this.btnSendTpdo1);
|
|
|
+ this.grpControl.Controls.Add(this.btnSendTpdo2);
|
|
|
+ this.grpControl.Controls.Add(this.btnSendAllTpdos);
|
|
|
+ this.grpControl.Location = new System.Drawing.Point(400, 10);
|
|
|
+ this.grpControl.Name = "grpControl";
|
|
|
+ this.grpControl.Size = new System.Drawing.Size(380, 100);
|
|
|
+ this.grpControl.TabIndex = 1;
|
|
|
+ this.grpControl.TabStop = false;
|
|
|
+ this.grpControl.Text = "控制";
|
|
|
+ //
|
|
|
+ // btnStart
|
|
|
+ //
|
|
|
+ this.btnStart.Location = new System.Drawing.Point(10, 25);
|
|
|
+ this.btnStart.Name = "btnStart";
|
|
|
+ this.btnStart.Size = new System.Drawing.Size(100, 30);
|
|
|
+ this.btnStart.TabIndex = 0;
|
|
|
+ this.btnStart.Text = "启动从站";
|
|
|
+ this.btnStart.Click += new System.EventHandler(this.BtnStart_Click);
|
|
|
+ //
|
|
|
+ // btnStop
|
|
|
+ //
|
|
|
+ this.btnStop.Enabled = false;
|
|
|
+ this.btnStop.Location = new System.Drawing.Point(120, 25);
|
|
|
+ this.btnStop.Name = "btnStop";
|
|
|
+ this.btnStop.Size = new System.Drawing.Size(100, 30);
|
|
|
+ this.btnStop.TabIndex = 1;
|
|
|
+ this.btnStop.Text = "停止从站";
|
|
|
+ this.btnStop.Click += new System.EventHandler(this.BtnStop_Click);
|
|
|
+ //
|
|
|
+ // btnSendTpdo1
|
|
|
+ //
|
|
|
+ this.btnSendTpdo1.Enabled = false;
|
|
|
+ this.btnSendTpdo1.Location = new System.Drawing.Point(10, 60);
|
|
|
+ this.btnSendTpdo1.Name = "btnSendTpdo1";
|
|
|
+ this.btnSendTpdo1.Size = new System.Drawing.Size(100, 30);
|
|
|
+ this.btnSendTpdo1.TabIndex = 2;
|
|
|
+ this.btnSendTpdo1.Text = "发送TPDO1";
|
|
|
+ this.btnSendTpdo1.Click += new System.EventHandler(this.BtnSendTpdo1_Click);
|
|
|
+ //
|
|
|
+ // btnSendTpdo2
|
|
|
+ //
|
|
|
+ this.btnSendTpdo2.Enabled = false;
|
|
|
+ this.btnSendTpdo2.Location = new System.Drawing.Point(120, 60);
|
|
|
+ this.btnSendTpdo2.Name = "btnSendTpdo2";
|
|
|
+ this.btnSendTpdo2.Size = new System.Drawing.Size(100, 30);
|
|
|
+ this.btnSendTpdo2.TabIndex = 3;
|
|
|
+ this.btnSendTpdo2.Text = "发送TPDO2";
|
|
|
+ this.btnSendTpdo2.Click += new System.EventHandler(this.BtnSendTpdo2_Click);
|
|
|
+ //
|
|
|
+ // btnSendAllTpdos
|
|
|
+ //
|
|
|
+ this.btnSendAllTpdos.Enabled = false;
|
|
|
+ this.btnSendAllTpdos.Location = new System.Drawing.Point(230, 60);
|
|
|
+ this.btnSendAllTpdos.Name = "btnSendAllTpdos";
|
|
|
+ this.btnSendAllTpdos.Size = new System.Drawing.Size(120, 30);
|
|
|
+ this.btnSendAllTpdos.TabIndex = 4;
|
|
|
+ this.btnSendAllTpdos.Text = "发送所有TPDO";
|
|
|
+ this.btnSendAllTpdos.Click += new System.EventHandler(this.BtnSendAllTpdos_Click);
|
|
|
+ //
|
|
|
+ // grpHeartbeat
|
|
|
+ //
|
|
|
+ this.grpHeartbeat.Controls.Add(this.lblHeartbeat);
|
|
|
+ this.grpHeartbeat.Controls.Add(this.nudHeartbeatTime);
|
|
|
+ this.grpHeartbeat.Controls.Add(this.btnConfigureHeartbeat);
|
|
|
+ this.grpHeartbeat.Location = new System.Drawing.Point(10, 120);
|
|
|
+ this.grpHeartbeat.Name = "grpHeartbeat";
|
|
|
+ this.grpHeartbeat.Size = new System.Drawing.Size(770, 60);
|
|
|
+ this.grpHeartbeat.TabIndex = 2;
|
|
|
+ this.grpHeartbeat.TabStop = false;
|
|
|
+ this.grpHeartbeat.Text = "心跳配置";
|
|
|
+ //
|
|
|
+ // lblHeartbeat
|
|
|
+ //
|
|
|
+ this.lblHeartbeat.AutoSize = true;
|
|
|
+ this.lblHeartbeat.Location = new System.Drawing.Point(10, 25);
|
|
|
+ this.lblHeartbeat.Name = "lblHeartbeat";
|
|
|
+ this.lblHeartbeat.Size = new System.Drawing.Size(107, 15);
|
|
|
+ this.lblHeartbeat.TabIndex = 0;
|
|
|
+ this.lblHeartbeat.Text = "心跳时间(ms):";
|
|
|
+ //
|
|
|
+ // nudHeartbeatTime
|
|
|
+ //
|
|
|
+ this.nudHeartbeatTime.Location = new System.Drawing.Point(110, 22);
|
|
|
+ this.nudHeartbeatTime.Maximum = new decimal(new int[] {
|
|
|
+ 10000,
|
|
|
+ 0,
|
|
|
+ 0,
|
|
|
+ 0});
|
|
|
+ this.nudHeartbeatTime.Name = "nudHeartbeatTime";
|
|
|
+ this.nudHeartbeatTime.Size = new System.Drawing.Size(100, 25);
|
|
|
+ this.nudHeartbeatTime.TabIndex = 1;
|
|
|
+ this.nudHeartbeatTime.Value = new decimal(new int[] {
|
|
|
+ 100,
|
|
|
+ 0,
|
|
|
+ 0,
|
|
|
+ 0});
|
|
|
+ //
|
|
|
+ // btnConfigureHeartbeat
|
|
|
+ //
|
|
|
+ this.btnConfigureHeartbeat.Enabled = false;
|
|
|
+ this.btnConfigureHeartbeat.Location = new System.Drawing.Point(220, 20);
|
|
|
+ this.btnConfigureHeartbeat.Name = "btnConfigureHeartbeat";
|
|
|
+ this.btnConfigureHeartbeat.Size = new System.Drawing.Size(100, 30);
|
|
|
+ this.btnConfigureHeartbeat.TabIndex = 2;
|
|
|
+ this.btnConfigureHeartbeat.Text = "配置心跳";
|
|
|
+ this.btnConfigureHeartbeat.Click += new System.EventHandler(this.BtnConfigureHeartbeat_Click);
|
|
|
+ //
|
|
|
+ // txtLog
|
|
|
+ //
|
|
|
+ this.txtLog.BackColor = System.Drawing.Color.White;
|
|
|
+ this.txtLog.Font = new System.Drawing.Font("微软雅黑", 9F);
|
|
|
+ this.txtLog.ForeColor = System.Drawing.Color.Black;
|
|
|
+ this.txtLog.Location = new System.Drawing.Point(10, 190);
|
|
|
+ this.txtLog.Multiline = true;
|
|
|
+ this.txtLog.Name = "txtLog";
|
|
|
+ this.txtLog.ReadOnly = true;
|
|
|
+ this.txtLog.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
|
|
|
+ this.txtLog.Size = new System.Drawing.Size(770, 360);
|
|
|
+ this.txtLog.TabIndex = 3;
|
|
|
+ //
|
|
|
+ // m_updateTimer
|
|
|
+ //
|
|
|
+ this.m_updateTimer.Enabled = true;
|
|
|
+ this.m_updateTimer.Interval = 500;
|
|
|
+ //
|
|
|
+ // SlaveTestForm
|
|
|
+ //
|
|
|
+ this.ClientSize = new System.Drawing.Size(782, 553);
|
|
|
+ this.Controls.Add(this.grpDeviceInfo);
|
|
|
+ this.Controls.Add(this.grpControl);
|
|
|
+ this.Controls.Add(this.grpHeartbeat);
|
|
|
+ this.Controls.Add(this.txtLog);
|
|
|
+ this.Name = "SlaveTestForm";
|
|
|
+ this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
|
|
this.Text = "CANopen从站设备测试";
|
|
|
- this.Size = new Size(800, 600);
|
|
|
- this.StartPosition = FormStartPosition.CenterScreen;
|
|
|
-
|
|
|
- // 设备信息组
|
|
|
- grpDeviceInfo = new GroupBox();
|
|
|
- grpDeviceInfo.Text = "设备信息";
|
|
|
- grpDeviceInfo.Location = new Point(10, 10);
|
|
|
- grpDeviceInfo.Size = new Size(380, 100);
|
|
|
-
|
|
|
- lblNodeId = new Label();
|
|
|
- lblNodeId.Text = "节点ID: -";
|
|
|
- lblNodeId.Location = new Point(10, 25);
|
|
|
- lblNodeId.AutoSize = true;
|
|
|
-
|
|
|
- lblState = new Label();
|
|
|
- lblState.Text = "状态: -";
|
|
|
- lblState.Location = new Point(10, 50);
|
|
|
- lblState.AutoSize = true;
|
|
|
-
|
|
|
- lblStatus = new Label();
|
|
|
- lblStatus.Text = "运行状态: 未启动";
|
|
|
- lblStatus.Location = new Point(10, 75);
|
|
|
- lblStatus.AutoSize = true;
|
|
|
-
|
|
|
- grpDeviceInfo.Controls.AddRange(new Control[] { lblNodeId, lblState, lblStatus });
|
|
|
-
|
|
|
- // 控制组
|
|
|
- grpControl = new GroupBox();
|
|
|
- grpControl.Text = "控制";
|
|
|
- grpControl.Location = new Point(400, 10);
|
|
|
- grpControl.Size = new Size(380, 100);
|
|
|
-
|
|
|
- btnStart = new Button();
|
|
|
- btnStart.Text = "启动从站";
|
|
|
- btnStart.Location = new Point(10, 25);
|
|
|
- btnStart.Size = new Size(100, 30);
|
|
|
- btnStart.Click += BtnStart_Click;
|
|
|
-
|
|
|
- btnStop = new Button();
|
|
|
- btnStop.Text = "停止从站";
|
|
|
- btnStop.Location = new Point(120, 25);
|
|
|
- btnStop.Size = new Size(100, 30);
|
|
|
- btnStop.Click += BtnStop_Click;
|
|
|
- btnStop.Enabled = false;
|
|
|
-
|
|
|
- btnSendTpdo1 = new Button();
|
|
|
- btnSendTpdo1.Text = "发送TPDO1";
|
|
|
- btnSendTpdo1.Location = new Point(10, 60);
|
|
|
- btnSendTpdo1.Size = new Size(100, 30);
|
|
|
- btnSendTpdo1.Click += BtnSendTpdo1_Click;
|
|
|
- btnSendTpdo1.Enabled = false;
|
|
|
-
|
|
|
- btnSendTpdo2 = new Button();
|
|
|
- btnSendTpdo2.Text = "发送TPDO2";
|
|
|
- btnSendTpdo2.Location = new Point(120, 60);
|
|
|
- btnSendTpdo2.Size = new Size(100, 30);
|
|
|
- btnSendTpdo2.Click += BtnSendTpdo2_Click;
|
|
|
- btnSendTpdo2.Enabled = false;
|
|
|
-
|
|
|
- btnSendAllTpdos = new Button();
|
|
|
- btnSendAllTpdos.Text = "发送所有TPDO";
|
|
|
- btnSendAllTpdos.Location = new Point(230, 60);
|
|
|
- btnSendAllTpdos.Size = new Size(120, 30);
|
|
|
- btnSendAllTpdos.Click += BtnSendAllTpdos_Click;
|
|
|
- btnSendAllTpdos.Enabled = false;
|
|
|
-
|
|
|
- grpControl.Controls.AddRange(new Control[] {
|
|
|
- btnStart, btnStop, btnSendTpdo1, btnSendTpdo2, btnSendAllTpdos
|
|
|
- });
|
|
|
-
|
|
|
- // 心跳配置组
|
|
|
- grpHeartbeat = new GroupBox();
|
|
|
- grpHeartbeat.Text = "心跳配置";
|
|
|
- grpHeartbeat.Location = new Point(10, 120);
|
|
|
- grpHeartbeat.Size = new Size(770, 60);
|
|
|
-
|
|
|
- Label lblHeartbeat = new Label();
|
|
|
- lblHeartbeat.Text = "心跳时间(ms):";
|
|
|
- lblHeartbeat.Location = new Point(10, 25);
|
|
|
- lblHeartbeat.AutoSize = true;
|
|
|
-
|
|
|
- nudHeartbeatTime = new NumericUpDown();
|
|
|
- nudHeartbeatTime.Location = new Point(110, 22);
|
|
|
- nudHeartbeatTime.Size = new Size(100, 25);
|
|
|
- nudHeartbeatTime.Minimum = 0;
|
|
|
- nudHeartbeatTime.Maximum = 10000;
|
|
|
- nudHeartbeatTime.Value = 100;
|
|
|
-
|
|
|
- btnConfigureHeartbeat = new Button();
|
|
|
- btnConfigureHeartbeat.Text = "配置心跳";
|
|
|
- btnConfigureHeartbeat.Location = new Point(220, 20);
|
|
|
- btnConfigureHeartbeat.Size = new Size(100, 30);
|
|
|
- btnConfigureHeartbeat.Click += BtnConfigureHeartbeat_Click;
|
|
|
- btnConfigureHeartbeat.Enabled = false;
|
|
|
-
|
|
|
- grpHeartbeat.Controls.AddRange(new Control[] { lblHeartbeat, nudHeartbeatTime, btnConfigureHeartbeat });
|
|
|
-
|
|
|
- // 日志显示
|
|
|
- txtLog = new TextBox();
|
|
|
- txtLog.Multiline = true;
|
|
|
- txtLog.ScrollBars = ScrollBars.Vertical;
|
|
|
- txtLog.ReadOnly = true;
|
|
|
- txtLog.Location = new Point(10, 190);
|
|
|
- txtLog.Size = new Size(770, 360);
|
|
|
- // 使用支持中文的字体(微软雅黑或宋体)
|
|
|
- txtLog.Font = new Font("Microsoft YaHei", 9);
|
|
|
- txtLog.ForeColor = Color.Black;
|
|
|
- txtLog.BackColor = Color.White;
|
|
|
-
|
|
|
- // 添加控件到窗体
|
|
|
- this.Controls.AddRange(new Control[] {
|
|
|
- grpDeviceInfo, grpControl, grpHeartbeat, txtLog
|
|
|
- });
|
|
|
-
|
|
|
- // 更新定时器
|
|
|
- m_updateTimer = new System.Windows.Forms.Timer();
|
|
|
- m_updateTimer.Interval = 500;
|
|
|
- m_updateTimer.Tick += UpdateTimer_Tick;
|
|
|
- m_updateTimer.Start();
|
|
|
+ this.grpDeviceInfo.ResumeLayout(false);
|
|
|
+ this.grpDeviceInfo.PerformLayout();
|
|
|
+ this.grpControl.ResumeLayout(false);
|
|
|
+ this.grpHeartbeat.ResumeLayout(false);
|
|
|
+ this.grpHeartbeat.PerformLayout();
|
|
|
+ ((System.ComponentModel.ISupportInitialize)(this.nudHeartbeatTime)).EndInit();
|
|
|
+ this.ResumeLayout(false);
|
|
|
+ this.PerformLayout();
|
|
|
+
|
|
|
}
|
|
|
|
|
|
private void BtnStart_Click(object sender, EventArgs e)
|