第 1 阶段:虚拟实训台,项目 2、3 的示例跑通

- 实训台状态由服务器统一保存:滑块和开关设定传感器读数,推给学生程序;
  学生程序控制的灯、继电器、LED 屏回写到实训台
- 网页按教材实训台布局图绘制实训台,传感器卡片上直接调节环境
- 新控件:CheckBox、RadioButton(事件顺序与 WinForms 一致),Lamp、Alarm
- 设备类库:串口未打开时控制无效,与实物一致
- 修正:列表属性序列化时数字被转成字符串
- 示例:项目 2 任务 2–3、项目 3 任务 1–2;网址参数 ?sample= 打开指定示例
- 测试:实训台单元测试,项目 2、3 的端到端测试

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
xuyueandClaude Opus 5.5 committed 2026-10-22 10:32:38 +08:00
1 parent 98be8331bc
commit 26104ae81e
38 files changed
+2346 -77

No files matched your search

+140
View File
@@ -0,0 +1,140 @@
namespace ZigBee路灯
{
partial class Form1
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.lamp1 = new WinFormsDeviceControlLibrary.Lamp();
this.rb_Open = new System.Windows.Forms.RadioButton();
this.rb_Close = new System.Windows.Forms.RadioButton();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.btn_open = new System.Windows.Forms.Button();
this.com_port = new System.Windows.Forms.ComboBox();
this.lbl_Lamp = new System.Windows.Forms.Label();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// lamp1
//
this.lamp1.BackColor = System.Drawing.Color.White;
this.lamp1.Location = new System.Drawing.Point(29, 28);
this.lamp1.Name = "lamp1";
this.lamp1.Size = new System.Drawing.Size(105, 185);
this.lamp1.TabIndex = 0;
//
// rb_Open
//
this.rb_Open.AutoSize = true;
this.rb_Open.Location = new System.Drawing.Point(29, 222);
this.rb_Open.Name = "rb_Open";
this.rb_Open.Size = new System.Drawing.Size(35, 16);
this.rb_Open.TabIndex = 1;
this.rb_Open.Text = "开";
this.rb_Open.UseVisualStyleBackColor = true;
this.rb_Open.CheckedChanged += new System.EventHandler(this.rb_Open_CheckedChanged);
//
// rb_Close
//
this.rb_Close.AutoSize = true;
this.rb_Close.Location = new System.Drawing.Point(99, 222);
this.rb_Close.Name = "rb_Close";
this.rb_Close.Size = new System.Drawing.Size(35, 16);
this.rb_Close.TabIndex = 2;
this.rb_Close.Text = "关";
this.rb_Close.UseVisualStyleBackColor = true;
this.rb_Close.CheckedChanged += new System.EventHandler(this.rb_Close_CheckedChanged);
//
// groupBox1
//
this.groupBox1.Controls.Add(this.btn_open);
this.groupBox1.Controls.Add(this.com_port);
this.groupBox1.Controls.Add(this.lbl_Lamp);
this.groupBox1.Location = new System.Drawing.Point(184, 50);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(238, 120);
this.groupBox1.TabIndex = 3;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "配置";
//
// btn_open
//
this.btn_open.Location = new System.Drawing.Point(145, 77);
this.btn_open.Name = "btn_open";
this.btn_open.Size = new System.Drawing.Size(75, 23);
this.btn_open.TabIndex = 2;
this.btn_open.Text = "打开";
this.btn_open.UseVisualStyleBackColor = true;
this.btn_open.Click += new System.EventHandler(this.btn_open_Click);
//
// com_port
//
this.com_port.FormattingEnabled = true;
this.com_port.Location = new System.Drawing.Point(90, 34);
this.com_port.Name = "com_port";
this.com_port.Size = new System.Drawing.Size(130, 20);
this.com_port.TabIndex = 1;
//
// lbl_Lamp
//
this.lbl_Lamp.AutoSize = true;
this.lbl_Lamp.Location = new System.Drawing.Point(21, 37);
this.lbl_Lamp.Name = "lbl_Lamp";
this.lbl_Lamp.Size = new System.Drawing.Size(29, 12);
this.lbl_Lamp.TabIndex = 0;
this.lbl_Lamp.Text = "路灯";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.White;
this.ClientSize = new System.Drawing.Size(442, 254);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.rb_Close);
this.Controls.Add(this.rb_Open);
this.Controls.Add(this.lamp1);
this.Name = "Form1";
this.Text = "ZigBee路灯";
this.Load += new System.EventHandler(this.Form1_Load);
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private WinFormsDeviceControlLibrary.Lamp lamp1;
private System.Windows.Forms.RadioButton rb_Open;
private System.Windows.Forms.RadioButton rb_Close;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Button btn_open;
private System.Windows.Forms.ComboBox com_port;
private System.Windows.Forms.Label lbl_Lamp;
}
}
+68
View File
@@ -0,0 +1,68 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Ports;
using DeviceCtrlLibrary;
namespace ZigBee路灯
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//控制开关灯
private void LampOnOff(int RelayNum, bool IsOpen)
{
DeviceCtrlHelper.zigBeeHelper.OnOff(RelayNum, IsOpen);
lamp1.OnOff(IsOpen);
}
private void Form1_Load(object sender, EventArgs e)
{
//清空列表
com_port.Items.Clear();
//加载所有可用的串口号到列表中
foreach (string item in SerialPort.GetPortNames())
{
com_port.Items.Add(item);
}
}
private void btn_open_Click(object sender, EventArgs e)
{
if (btn_open.Text.Equals("打开"))
{
//打开ZigBee协调器所在的串口
DeviceCtrlHelper.zigBeeHelper.Open(com_port.Text);
btn_open.Text = "关闭";
}
else if (btn_open.Text.Equals("关闭"))
{
//关闭串口
DeviceCtrlHelper.zigBeeHelper.Close();
btn_open.Text = "打开";
}
}
private void rb_Open_CheckedChanged(object sender, EventArgs e)
{
//开灯
LampOnOff(1, true);
}
private void rb_Close_CheckedChanged(object sender, EventArgs e)
{
//关灯
LampOnOff(1, false);
}
}
}
+22
View File
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ZigBee路灯
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
+4
View File
@@ -0,0 +1,4 @@
{
"title": "项目3 任务1 使用ZigBee技术控制路灯开关",
"source": "教材书 p53–56,按书上代码整理并修正印刷错误(控件名以书上表格和代码为准)"
}