第 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:
1 parent
98be8331bc
commit
26104ae81e
38 files changed
+2346
-77
No files matched your search
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace 模拟量采集
|
||||
{
|
||||
static class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// 应用程序的主入口点。
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
Application.Run(new frm_analog());
|
||||
}
|
||||
}
|
||||
}
|
||||
+193
@@ -0,0 +1,193 @@
|
||||
namespace 模拟量采集
|
||||
{
|
||||
partial class frm_analog
|
||||
{
|
||||
/// <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.grp_show = new System.Windows.Forms.GroupBox();
|
||||
this.btn_get = new System.Windows.Forms.Button();
|
||||
this.txt_humidity = new System.Windows.Forms.TextBox();
|
||||
this.txt_temperature = new System.Windows.Forms.TextBox();
|
||||
this.txt_light = new System.Windows.Forms.TextBox();
|
||||
this.lbl_humidity = new System.Windows.Forms.Label();
|
||||
this.lbl_temperature = new System.Windows.Forms.Label();
|
||||
this.lbl_light = new System.Windows.Forms.Label();
|
||||
this.grp_config = new System.Windows.Forms.GroupBox();
|
||||
this.btn_Open = new System.Windows.Forms.Button();
|
||||
this.com_port = new System.Windows.Forms.ComboBox();
|
||||
this.lbl_port = new System.Windows.Forms.Label();
|
||||
this.grp_show.SuspendLayout();
|
||||
this.grp_config.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// grp_show
|
||||
//
|
||||
this.grp_show.Controls.Add(this.btn_get);
|
||||
this.grp_show.Controls.Add(this.txt_humidity);
|
||||
this.grp_show.Controls.Add(this.txt_temperature);
|
||||
this.grp_show.Controls.Add(this.txt_light);
|
||||
this.grp_show.Controls.Add(this.lbl_humidity);
|
||||
this.grp_show.Controls.Add(this.lbl_temperature);
|
||||
this.grp_show.Controls.Add(this.lbl_light);
|
||||
this.grp_show.Location = new System.Drawing.Point(12, 12);
|
||||
this.grp_show.Name = "grp_show";
|
||||
this.grp_show.Size = new System.Drawing.Size(260, 126);
|
||||
this.grp_show.TabIndex = 0;
|
||||
this.grp_show.TabStop = false;
|
||||
this.grp_show.Text = "数据显示";
|
||||
//
|
||||
// btn_get
|
||||
//
|
||||
this.btn_get.Location = new System.Drawing.Point(209, 24);
|
||||
this.btn_get.Name = "btn_get";
|
||||
this.btn_get.Size = new System.Drawing.Size(39, 83);
|
||||
this.btn_get.TabIndex = 6;
|
||||
this.btn_get.Text = "获取";
|
||||
this.btn_get.UseVisualStyleBackColor = true;
|
||||
this.btn_get.Click += new System.EventHandler(this.btn_get_Click);
|
||||
//
|
||||
// txt_humidity
|
||||
//
|
||||
this.txt_humidity.Location = new System.Drawing.Point(83, 86);
|
||||
this.txt_humidity.Name = "txt_humidity";
|
||||
this.txt_humidity.Size = new System.Drawing.Size(100, 21);
|
||||
this.txt_humidity.TabIndex = 5;
|
||||
//
|
||||
// txt_temperature
|
||||
//
|
||||
this.txt_temperature.Location = new System.Drawing.Point(83, 54);
|
||||
this.txt_temperature.Name = "txt_temperature";
|
||||
this.txt_temperature.Size = new System.Drawing.Size(100, 21);
|
||||
this.txt_temperature.TabIndex = 4;
|
||||
//
|
||||
// txt_light
|
||||
//
|
||||
this.txt_light.Location = new System.Drawing.Point(83, 24);
|
||||
this.txt_light.Name = "txt_light";
|
||||
this.txt_light.Size = new System.Drawing.Size(100, 21);
|
||||
this.txt_light.TabIndex = 3;
|
||||
//
|
||||
// lbl_humidity
|
||||
//
|
||||
this.lbl_humidity.AutoSize = true;
|
||||
this.lbl_humidity.Location = new System.Drawing.Point(20, 89);
|
||||
this.lbl_humidity.Name = "lbl_humidity";
|
||||
this.lbl_humidity.Size = new System.Drawing.Size(29, 12);
|
||||
this.lbl_humidity.TabIndex = 2;
|
||||
this.lbl_humidity.Text = "湿度";
|
||||
//
|
||||
// lbl_temperature
|
||||
//
|
||||
this.lbl_temperature.AutoSize = true;
|
||||
this.lbl_temperature.Location = new System.Drawing.Point(20, 57);
|
||||
this.lbl_temperature.Name = "lbl_temperature";
|
||||
this.lbl_temperature.Size = new System.Drawing.Size(29, 12);
|
||||
this.lbl_temperature.TabIndex = 1;
|
||||
this.lbl_temperature.Text = "温度";
|
||||
//
|
||||
// lbl_light
|
||||
//
|
||||
this.lbl_light.AutoSize = true;
|
||||
this.lbl_light.Location = new System.Drawing.Point(20, 27);
|
||||
this.lbl_light.Name = "lbl_light";
|
||||
this.lbl_light.Size = new System.Drawing.Size(41, 12);
|
||||
this.lbl_light.TabIndex = 0;
|
||||
this.lbl_light.Text = "光照度";
|
||||
//
|
||||
// grp_config
|
||||
//
|
||||
this.grp_config.Controls.Add(this.btn_Open);
|
||||
this.grp_config.Controls.Add(this.com_port);
|
||||
this.grp_config.Controls.Add(this.lbl_port);
|
||||
this.grp_config.Location = new System.Drawing.Point(12, 144);
|
||||
this.grp_config.Name = "grp_config";
|
||||
this.grp_config.Size = new System.Drawing.Size(260, 100);
|
||||
this.grp_config.TabIndex = 1;
|
||||
this.grp_config.TabStop = false;
|
||||
this.grp_config.Text = "配置";
|
||||
//
|
||||
// btn_Open
|
||||
//
|
||||
this.btn_Open.Location = new System.Drawing.Point(149, 59);
|
||||
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(105, 33);
|
||||
this.com_port.Name = "com_port";
|
||||
this.com_port.Size = new System.Drawing.Size(119, 20);
|
||||
this.com_port.TabIndex = 1;
|
||||
//
|
||||
// lbl_port
|
||||
//
|
||||
this.lbl_port.AutoSize = true;
|
||||
this.lbl_port.Location = new System.Drawing.Point(44, 36);
|
||||
this.lbl_port.Name = "lbl_port";
|
||||
this.lbl_port.Size = new System.Drawing.Size(29, 12);
|
||||
this.lbl_port.TabIndex = 0;
|
||||
this.lbl_port.Text = "串口";
|
||||
//
|
||||
// frm_analog
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(284, 262);
|
||||
this.Controls.Add(this.grp_config);
|
||||
this.Controls.Add(this.grp_show);
|
||||
this.Name = "frm_analog";
|
||||
this.Text = "模拟量采集";
|
||||
this.Load += new System.EventHandler(this.frm_analog_Load);
|
||||
this.grp_show.ResumeLayout(false);
|
||||
this.grp_show.PerformLayout();
|
||||
this.grp_config.ResumeLayout(false);
|
||||
this.grp_config.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.GroupBox grp_show;
|
||||
private System.Windows.Forms.Button btn_get;
|
||||
private System.Windows.Forms.TextBox txt_humidity;
|
||||
private System.Windows.Forms.TextBox txt_temperature;
|
||||
private System.Windows.Forms.TextBox txt_light;
|
||||
private System.Windows.Forms.Label lbl_humidity;
|
||||
private System.Windows.Forms.Label lbl_temperature;
|
||||
private System.Windows.Forms.Label lbl_light;
|
||||
private System.Windows.Forms.GroupBox grp_config;
|
||||
private System.Windows.Forms.Button btn_Open;
|
||||
private System.Windows.Forms.ComboBox com_port;
|
||||
private System.Windows.Forms.Label lbl_port;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
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;
|
||||
using DeviceCtrlLibrary.Model;
|
||||
|
||||
namespace 模拟量采集
|
||||
{
|
||||
public partial class frm_analog : Form
|
||||
{
|
||||
public frm_analog()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
bool IsOpen = false;
|
||||
ADAM4017ResModel ResModel;
|
||||
|
||||
private void frm_analog_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 (!IsOpen)
|
||||
{
|
||||
//打开模拟量采集器所在的串口
|
||||
DeviceCtrlHelper.adam4017Helper.Open(com_port.Text);
|
||||
btn_Open.Text = "关闭";
|
||||
IsOpen = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
//关闭串口
|
||||
DeviceCtrlHelper.adam4017Helper.Close();
|
||||
btn_Open.Text = "开启";
|
||||
IsOpen = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void btn_get_Click(object sender, EventArgs e)
|
||||
{
|
||||
//获取传感器数值
|
||||
ResModel = DeviceCtrlHelper.adam4017Helper.SetData();
|
||||
txt_light.Text = ResModel.lightValue;
|
||||
txt_humidity.Text = ResModel.humidityValue;
|
||||
txt_temperature.Text = ResModel.temperatureValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"title": "项目2 任务2 实时采集温度、湿度和光照度数据",
|
||||
"source": "教材书 p36–39,按书上代码整理并修正印刷错误(控件名以书上表格和代码为准)"
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace LED推送模拟量
|
||||
{
|
||||
static class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// 应用程序的主入口点。
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
Application.Run(new frm_LED());
|
||||
}
|
||||
}
|
||||
}
|
||||
+227
@@ -0,0 +1,227 @@
|
||||
namespace LED推送模拟量
|
||||
{
|
||||
partial class frm_LED
|
||||
{
|
||||
/// <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.led = new WinFormsDeviceControlLibrary.LED();
|
||||
this.grp_show = new System.Windows.Forms.GroupBox();
|
||||
this.btn_get = new System.Windows.Forms.Button();
|
||||
this.txt_temperature = new System.Windows.Forms.TextBox();
|
||||
this.txt_humidity = new System.Windows.Forms.TextBox();
|
||||
this.txt_light = new System.Windows.Forms.TextBox();
|
||||
this.lbl_humidity = new System.Windows.Forms.Label();
|
||||
this.lbl_temperature = new System.Windows.Forms.Label();
|
||||
this.lbl_light = new System.Windows.Forms.Label();
|
||||
this.grp_config = new System.Windows.Forms.GroupBox();
|
||||
this.com_ledPort = new System.Windows.Forms.ComboBox();
|
||||
this.lbl_ledPort = new System.Windows.Forms.Label();
|
||||
this.btn_open = new System.Windows.Forms.Button();
|
||||
this.com_adamPort = new System.Windows.Forms.ComboBox();
|
||||
this.lbl_adamPort = new System.Windows.Forms.Label();
|
||||
this.grp_show.SuspendLayout();
|
||||
this.grp_config.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// led
|
||||
//
|
||||
this.led.BackColor = System.Drawing.Color.Black;
|
||||
this.led.Location = new System.Drawing.Point(19, 0);
|
||||
this.led.Name = "led";
|
||||
this.led.Size = new System.Drawing.Size(800, 130);
|
||||
this.led.TabIndex = 0;
|
||||
//
|
||||
// grp_show
|
||||
//
|
||||
this.grp_show.Controls.Add(this.btn_get);
|
||||
this.grp_show.Controls.Add(this.txt_temperature);
|
||||
this.grp_show.Controls.Add(this.txt_humidity);
|
||||
this.grp_show.Controls.Add(this.txt_light);
|
||||
this.grp_show.Controls.Add(this.lbl_humidity);
|
||||
this.grp_show.Controls.Add(this.lbl_temperature);
|
||||
this.grp_show.Controls.Add(this.lbl_light);
|
||||
this.grp_show.Location = new System.Drawing.Point(19, 156);
|
||||
this.grp_show.Name = "grp_show";
|
||||
this.grp_show.Size = new System.Drawing.Size(370, 200);
|
||||
this.grp_show.TabIndex = 1;
|
||||
this.grp_show.TabStop = false;
|
||||
this.grp_show.Text = "数据显示";
|
||||
//
|
||||
// btn_get
|
||||
//
|
||||
this.btn_get.Location = new System.Drawing.Point(287, 47);
|
||||
this.btn_get.Name = "btn_get";
|
||||
this.btn_get.Size = new System.Drawing.Size(51, 103);
|
||||
this.btn_get.TabIndex = 6;
|
||||
this.btn_get.Text = "获取";
|
||||
this.btn_get.UseVisualStyleBackColor = true;
|
||||
this.btn_get.Click += new System.EventHandler(this.btn_get_Click);
|
||||
//
|
||||
// txt_temperature
|
||||
//
|
||||
this.txt_temperature.Location = new System.Drawing.Point(105, 85);
|
||||
this.txt_temperature.Name = "txt_temperature";
|
||||
this.txt_temperature.Size = new System.Drawing.Size(147, 21);
|
||||
this.txt_temperature.TabIndex = 4;
|
||||
//
|
||||
// txt_humidity
|
||||
//
|
||||
this.txt_humidity.Location = new System.Drawing.Point(105, 129);
|
||||
this.txt_humidity.Name = "txt_humidity";
|
||||
this.txt_humidity.Size = new System.Drawing.Size(147, 21);
|
||||
this.txt_humidity.TabIndex = 5;
|
||||
//
|
||||
// txt_light
|
||||
//
|
||||
this.txt_light.Location = new System.Drawing.Point(105, 47);
|
||||
this.txt_light.Name = "txt_light";
|
||||
this.txt_light.Size = new System.Drawing.Size(147, 21);
|
||||
this.txt_light.TabIndex = 3;
|
||||
//
|
||||
// lbl_humidity
|
||||
//
|
||||
this.lbl_humidity.AutoSize = true;
|
||||
this.lbl_humidity.Location = new System.Drawing.Point(43, 132);
|
||||
this.lbl_humidity.Name = "lbl_humidity";
|
||||
this.lbl_humidity.Size = new System.Drawing.Size(29, 12);
|
||||
this.lbl_humidity.TabIndex = 2;
|
||||
this.lbl_humidity.Text = "湿度";
|
||||
//
|
||||
// lbl_temperature
|
||||
//
|
||||
this.lbl_temperature.AutoSize = true;
|
||||
this.lbl_temperature.Location = new System.Drawing.Point(43, 88);
|
||||
this.lbl_temperature.Name = "lbl_temperature";
|
||||
this.lbl_temperature.Size = new System.Drawing.Size(29, 12);
|
||||
this.lbl_temperature.TabIndex = 1;
|
||||
this.lbl_temperature.Text = "温度";
|
||||
//
|
||||
// lbl_light
|
||||
//
|
||||
this.lbl_light.AutoSize = true;
|
||||
this.lbl_light.Location = new System.Drawing.Point(43, 50);
|
||||
this.lbl_light.Name = "lbl_light";
|
||||
this.lbl_light.Size = new System.Drawing.Size(41, 12);
|
||||
this.lbl_light.TabIndex = 0;
|
||||
this.lbl_light.Text = "光照度";
|
||||
//
|
||||
// grp_config
|
||||
//
|
||||
this.grp_config.Controls.Add(this.com_ledPort);
|
||||
this.grp_config.Controls.Add(this.lbl_ledPort);
|
||||
this.grp_config.Controls.Add(this.btn_open);
|
||||
this.grp_config.Controls.Add(this.com_adamPort);
|
||||
this.grp_config.Controls.Add(this.lbl_adamPort);
|
||||
this.grp_config.Location = new System.Drawing.Point(449, 156);
|
||||
this.grp_config.Name = "grp_config";
|
||||
this.grp_config.Size = new System.Drawing.Size(370, 200);
|
||||
this.grp_config.TabIndex = 2;
|
||||
this.grp_config.TabStop = false;
|
||||
this.grp_config.Text = "配置";
|
||||
//
|
||||
// com_ledPort
|
||||
//
|
||||
this.com_ledPort.FormattingEnabled = true;
|
||||
this.com_ledPort.Location = new System.Drawing.Point(127, 84);
|
||||
this.com_ledPort.Name = "com_ledPort";
|
||||
this.com_ledPort.Size = new System.Drawing.Size(121, 20);
|
||||
this.com_ledPort.TabIndex = 3;
|
||||
//
|
||||
// lbl_ledPort
|
||||
//
|
||||
this.lbl_ledPort.AutoSize = true;
|
||||
this.lbl_ledPort.Location = new System.Drawing.Point(48, 87);
|
||||
this.lbl_ledPort.Name = "lbl_ledPort";
|
||||
this.lbl_ledPort.Size = new System.Drawing.Size(47, 12);
|
||||
this.lbl_ledPort.TabIndex = 2;
|
||||
this.lbl_ledPort.Text = "LED串口";
|
||||
//
|
||||
// btn_open
|
||||
//
|
||||
this.btn_open.Location = new System.Drawing.Point(173, 121);
|
||||
this.btn_open.Name = "btn_open";
|
||||
this.btn_open.Size = new System.Drawing.Size(75, 23);
|
||||
this.btn_open.TabIndex = 4;
|
||||
this.btn_open.Text = "开启";
|
||||
this.btn_open.UseVisualStyleBackColor = true;
|
||||
this.btn_open.Click += new System.EventHandler(this.btn_open_Click);
|
||||
//
|
||||
// com_adamPort
|
||||
//
|
||||
this.com_adamPort.FormattingEnabled = true;
|
||||
this.com_adamPort.Location = new System.Drawing.Point(127, 41);
|
||||
this.com_adamPort.Name = "com_adamPort";
|
||||
this.com_adamPort.Size = new System.Drawing.Size(121, 20);
|
||||
this.com_adamPort.TabIndex = 1;
|
||||
//
|
||||
// lbl_adamPort
|
||||
//
|
||||
this.lbl_adamPort.AutoSize = true;
|
||||
this.lbl_adamPort.Location = new System.Drawing.Point(46, 44);
|
||||
this.lbl_adamPort.Name = "lbl_adamPort";
|
||||
this.lbl_adamPort.Size = new System.Drawing.Size(65, 12);
|
||||
this.lbl_adamPort.TabIndex = 0;
|
||||
this.lbl_adamPort.Text = "模拟量串口";
|
||||
//
|
||||
// frm_LED
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(834, 380);
|
||||
this.Controls.Add(this.grp_config);
|
||||
this.Controls.Add(this.grp_show);
|
||||
this.Controls.Add(this.led);
|
||||
this.Name = "frm_LED";
|
||||
this.Text = "LED推送模拟量";
|
||||
this.Load += new System.EventHandler(this.frm_LED_Load);
|
||||
this.grp_show.ResumeLayout(false);
|
||||
this.grp_show.PerformLayout();
|
||||
this.grp_config.ResumeLayout(false);
|
||||
this.grp_config.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private WinFormsDeviceControlLibrary.LED led;
|
||||
private System.Windows.Forms.GroupBox grp_show;
|
||||
private System.Windows.Forms.Button btn_get;
|
||||
private System.Windows.Forms.TextBox txt_temperature;
|
||||
private System.Windows.Forms.TextBox txt_humidity;
|
||||
private System.Windows.Forms.TextBox txt_light;
|
||||
private System.Windows.Forms.Label lbl_humidity;
|
||||
private System.Windows.Forms.Label lbl_temperature;
|
||||
private System.Windows.Forms.Label lbl_light;
|
||||
private System.Windows.Forms.GroupBox grp_config;
|
||||
private System.Windows.Forms.ComboBox com_ledPort;
|
||||
private System.Windows.Forms.Label lbl_ledPort;
|
||||
private System.Windows.Forms.Button btn_open;
|
||||
private System.Windows.Forms.ComboBox com_adamPort;
|
||||
private System.Windows.Forms.Label lbl_adamPort;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
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;
|
||||
using DeviceCtrlLibrary.Model;
|
||||
|
||||
namespace LED推送模拟量
|
||||
{
|
||||
public partial class frm_LED : Form
|
||||
{
|
||||
public frm_LED()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
bool IsOpen = false;
|
||||
ADAM4017ResModel ResModel;
|
||||
String LED_MSG = "";
|
||||
|
||||
private void frm_LED_Load(object sender, EventArgs e)
|
||||
{
|
||||
//清空列表
|
||||
com_adamPort.Items.Clear();
|
||||
com_ledPort.Items.Clear();
|
||||
//加载所有可用的串口号到列表中
|
||||
foreach (string item in SerialPort.GetPortNames())
|
||||
{
|
||||
com_adamPort.Items.Add(item);
|
||||
com_ledPort.Items.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
private void btn_open_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (!IsOpen)
|
||||
{
|
||||
//打开模拟量采集器和LED显示屏所在的串口
|
||||
DeviceCtrlHelper.adam4017Helper.Open(com_adamPort.Text);
|
||||
DeviceCtrlHelper.ledHelper.OpenLedCom(com_ledPort.Text);
|
||||
btn_open.Text = "关闭";
|
||||
IsOpen = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
//关闭串口
|
||||
DeviceCtrlHelper.adam4017Helper.Close();
|
||||
DeviceCtrlHelper.ledHelper.Close();
|
||||
btn_open.Text = "开启";
|
||||
IsOpen = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void btn_get_Click(object sender, EventArgs e)
|
||||
{
|
||||
LED_MSG = "";
|
||||
//获取传感器数值
|
||||
ResModel = DeviceCtrlHelper.adam4017Helper.SetData();
|
||||
txt_light.Text = ResModel.lightValue;
|
||||
txt_humidity.Text = ResModel.humidityValue;
|
||||
txt_temperature.Text = ResModel.temperatureValue;
|
||||
//拼接要推送的环境信息
|
||||
LED_MSG += ("当前环境信息" + " " + "光照度:" + ResModel.lightValue + "lx温度:" + ResModel.temperatureValue + "℃湿度:" + ResModel.humidityValue + "%");
|
||||
//推送到LED显示屏
|
||||
String Res = DeviceCtrlHelper.ledHelper.SendLedString(LED_MSG);
|
||||
if (!(Res.IndexOf("Error") >= 0))
|
||||
{
|
||||
led.setLedText(Res);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"title": "项目2 任务3 在LED显示屏中显示环境数据",
|
||||
"source": "教材书 p42–45,按书上代码整理并修正印刷错误(控件名以书上表格和代码为准)"
|
||||
}
|
||||
Generated
+140
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"title": "项目3 任务1 使用ZigBee技术控制路灯开关",
|
||||
"source": "教材书 p53–56,按书上代码整理并修正印刷错误(控件名以书上表格和代码为准)"
|
||||
}
|
||||
+182
@@ -0,0 +1,182 @@
|
||||
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.components = new System.ComponentModel.Container();
|
||||
this.lamp1 = new WinFormsDeviceControlLibrary.Lamp();
|
||||
this.btn_lampOpen = new System.Windows.Forms.Button();
|
||||
this.btn_lampClose = new System.Windows.Forms.Button();
|
||||
this.groupBox1 = new System.Windows.Forms.GroupBox();
|
||||
this.ch_bodyInfrared = new System.Windows.Forms.CheckBox();
|
||||
this.com_environment = new System.Windows.Forms.ComboBox();
|
||||
this.lbl_environment = new System.Windows.Forms.Label();
|
||||
this.btn_open = new System.Windows.Forms.Button();
|
||||
this.com_lamp = new System.Windows.Forms.ComboBox();
|
||||
this.lbl_lamp = new System.Windows.Forms.Label();
|
||||
this.timer1 = new System.Windows.Forms.Timer(this.components);
|
||||
this.groupBox1.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// lamp1
|
||||
//
|
||||
this.lamp1.BackColor = System.Drawing.Color.White;
|
||||
this.lamp1.Location = new System.Drawing.Point(32, 22);
|
||||
this.lamp1.Name = "lamp1";
|
||||
this.lamp1.Size = new System.Drawing.Size(105, 185);
|
||||
this.lamp1.TabIndex = 0;
|
||||
//
|
||||
// btn_lampOpen
|
||||
//
|
||||
this.btn_lampOpen.Location = new System.Drawing.Point(32, 213);
|
||||
this.btn_lampOpen.Name = "btn_lampOpen";
|
||||
this.btn_lampOpen.Size = new System.Drawing.Size(33, 23);
|
||||
this.btn_lampOpen.TabIndex = 1;
|
||||
this.btn_lampOpen.Text = "开";
|
||||
this.btn_lampOpen.UseVisualStyleBackColor = true;
|
||||
this.btn_lampOpen.Click += new System.EventHandler(this.btn_lampOpen_Click);
|
||||
//
|
||||
// btn_lampClose
|
||||
//
|
||||
this.btn_lampClose.Location = new System.Drawing.Point(104, 213);
|
||||
this.btn_lampClose.Name = "btn_lampClose";
|
||||
this.btn_lampClose.Size = new System.Drawing.Size(33, 23);
|
||||
this.btn_lampClose.TabIndex = 2;
|
||||
this.btn_lampClose.Text = "关";
|
||||
this.btn_lampClose.UseVisualStyleBackColor = true;
|
||||
this.btn_lampClose.Click += new System.EventHandler(this.btn_lampClose_Click);
|
||||
//
|
||||
// groupBox1
|
||||
//
|
||||
this.groupBox1.Controls.Add(this.ch_bodyInfrared);
|
||||
this.groupBox1.Controls.Add(this.com_environment);
|
||||
this.groupBox1.Controls.Add(this.lbl_environment);
|
||||
this.groupBox1.Controls.Add(this.btn_open);
|
||||
this.groupBox1.Controls.Add(this.com_lamp);
|
||||
this.groupBox1.Controls.Add(this.lbl_lamp);
|
||||
this.groupBox1.Location = new System.Drawing.Point(193, 58);
|
||||
this.groupBox1.Name = "groupBox1";
|
||||
this.groupBox1.Size = new System.Drawing.Size(238, 126);
|
||||
this.groupBox1.TabIndex = 3;
|
||||
this.groupBox1.TabStop = false;
|
||||
this.groupBox1.Text = "配置";
|
||||
//
|
||||
// ch_bodyInfrared
|
||||
//
|
||||
this.ch_bodyInfrared.AutoSize = true;
|
||||
this.ch_bodyInfrared.Location = new System.Drawing.Point(25, 81);
|
||||
this.ch_bodyInfrared.Name = "ch_bodyInfrared";
|
||||
this.ch_bodyInfrared.Size = new System.Drawing.Size(72, 16);
|
||||
this.ch_bodyInfrared.TabIndex = 4;
|
||||
this.ch_bodyInfrared.Text = "人体开关";
|
||||
this.ch_bodyInfrared.UseVisualStyleBackColor = true;
|
||||
this.ch_bodyInfrared.Click += new System.EventHandler(this.ch_bodyInfrared_Click);
|
||||
//
|
||||
// com_environment
|
||||
//
|
||||
this.com_environment.FormattingEnabled = true;
|
||||
this.com_environment.Location = new System.Drawing.Point(90, 51);
|
||||
this.com_environment.Name = "com_environment";
|
||||
this.com_environment.Size = new System.Drawing.Size(130, 20);
|
||||
this.com_environment.TabIndex = 3;
|
||||
//
|
||||
// lbl_environment
|
||||
//
|
||||
this.lbl_environment.AutoSize = true;
|
||||
this.lbl_environment.Location = new System.Drawing.Point(23, 54);
|
||||
this.lbl_environment.Name = "lbl_environment";
|
||||
this.lbl_environment.Size = new System.Drawing.Size(53, 12);
|
||||
this.lbl_environment.TabIndex = 2;
|
||||
this.lbl_environment.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 = 5;
|
||||
this.btn_open.Text = "打开";
|
||||
this.btn_open.UseVisualStyleBackColor = true;
|
||||
this.btn_open.Click += new System.EventHandler(this.btn_open_Click);
|
||||
//
|
||||
// com_lamp
|
||||
//
|
||||
this.com_lamp.FormattingEnabled = true;
|
||||
this.com_lamp.Location = new System.Drawing.Point(90, 26);
|
||||
this.com_lamp.Name = "com_lamp";
|
||||
this.com_lamp.Size = new System.Drawing.Size(130, 20);
|
||||
this.com_lamp.TabIndex = 1;
|
||||
//
|
||||
// lbl_lamp
|
||||
//
|
||||
this.lbl_lamp.AutoSize = true;
|
||||
this.lbl_lamp.Location = new System.Drawing.Point(21, 29);
|
||||
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 = "路灯";
|
||||
//
|
||||
// timer1
|
||||
//
|
||||
this.timer1.Interval = 5000;
|
||||
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
|
||||
//
|
||||
// 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(477, 249);
|
||||
this.Controls.Add(this.groupBox1);
|
||||
this.Controls.Add(this.btn_lampClose);
|
||||
this.Controls.Add(this.btn_lampOpen);
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private WinFormsDeviceControlLibrary.Lamp lamp1;
|
||||
private System.Windows.Forms.Button btn_lampOpen;
|
||||
private System.Windows.Forms.Button btn_lampClose;
|
||||
private System.Windows.Forms.GroupBox groupBox1;
|
||||
private System.Windows.Forms.CheckBox ch_bodyInfrared;
|
||||
private System.Windows.Forms.ComboBox com_environment;
|
||||
private System.Windows.Forms.Label lbl_environment;
|
||||
private System.Windows.Forms.Button btn_open;
|
||||
private System.Windows.Forms.ComboBox com_lamp;
|
||||
private System.Windows.Forms.Label lbl_lamp;
|
||||
private System.Windows.Forms.Timer timer1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
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 Form1_Load(object sender, EventArgs e)
|
||||
{
|
||||
//清空列表
|
||||
com_lamp.Items.Clear();
|
||||
com_environment.Items.Clear();
|
||||
//加载所有可用的串口号到列表中
|
||||
foreach (string item in SerialPort.GetPortNames())
|
||||
{
|
||||
com_lamp.Items.Add(item);
|
||||
com_environment.Items.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
//控制开关灯
|
||||
private void LampOnOff(int RelayNum, bool IsOpen)
|
||||
{
|
||||
DeviceCtrlHelper.zigBeeHelper.OnOff(RelayNum, IsOpen);
|
||||
lamp1.OnOff(IsOpen);
|
||||
}
|
||||
|
||||
private void btn_open_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (btn_open.Text.Equals("打开"))
|
||||
{
|
||||
//打开ZigBee协调器所在的串口
|
||||
DeviceCtrlHelper.zigBeeHelper.Open(com_lamp.Text);
|
||||
btn_open.Text = "关闭";
|
||||
}
|
||||
else if (btn_open.Text.Equals("关闭"))
|
||||
{
|
||||
//关闭串口
|
||||
DeviceCtrlHelper.zigBeeHelper.Close();
|
||||
btn_open.Text = "打开";
|
||||
}
|
||||
}
|
||||
|
||||
private void ch_bodyInfrared_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (ch_bodyInfrared.Checked)
|
||||
{
|
||||
//打开数字量采集器所在的串口,启动定时检测
|
||||
DeviceCtrlHelper.adam4150Helper.Open(com_environment.Text);
|
||||
timer1.Start();
|
||||
btn_lampOpen.Enabled = false;
|
||||
btn_lampClose.Enabled = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
DeviceCtrlHelper.adam4150Helper.Close();
|
||||
timer1.Stop();
|
||||
btn_lampOpen.Enabled = true;
|
||||
btn_lampClose.Enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void btn_lampOpen_Click(object sender, EventArgs e)
|
||||
{
|
||||
LampOnOff(1, true);
|
||||
}
|
||||
|
||||
private void btn_lampClose_Click(object sender, EventArgs e)
|
||||
{
|
||||
LampOnOff(1, false);
|
||||
}
|
||||
|
||||
//时间控件实时判断是否感应到人,如果感应到人则开路灯,否则关闭
|
||||
private void timer1_Tick(object sender, EventArgs e)
|
||||
{
|
||||
if (DeviceCtrlHelper.adam4150Helper.SetData().bodyInfraredValue)
|
||||
LampOnOff(1, true);
|
||||
else
|
||||
LampOnOff(1, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"title": "项目3 任务2 实现人体红外传感器和路灯联动",
|
||||
"source": "教材书 p58–61,按书上代码整理并修正印刷错误(控件名以书上表格和代码为准)"
|
||||
}
|
||||
Reference in new issue
Block a user