项目 5 补齐:旧版线程 API(Suspend / Resume / Abort)与 ListBox

- 编译时把 Thread 的 Suspend / Resume / Abort、ThreadState、Sleep、new Thread 改写成平台的
  协作式实现:被挂起或终止的线程在 Sleep、后台改控件、调设备类库、弹提示框时停下或结束;
  ThreadStateException 等行为与 .NET Framework 一致;编辑器不再提示"已过时"
- ListBox:列表项、单选、SelectedIndexChanged 先于 Click、删除选中项后取消选中;
  ComboBox 与 ListBox 共用 ListControl 和列表项集合;设计器工具箱加"列表框"
- 评分规则的"包含"对列表框检查所有列表项
- 示例:项目 5 任务 2(烟雾,线程)、任务 3(推送灾情,二维数组、两个窗体、ListBox),
  参考答案修正书上直接 Abort 挂起线程、烟雾记成"发现火情"的问题
- 一直不换行的 Console 输出攒满 4096 字符先发出,避免占满内存
- 测试:旧版线程 API、ListBox 事件顺序、两个示例的端到端和评分测试

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
xuyueandClaude Opus 5.5 committed 2026-10-22 20:33:12 +08:00
1 parent 8a92354fe4
commit 91b39603a2
36 files changed
+1653 -105

No files matched your search

+146
View File
@@ -0,0 +1,146 @@
namespace 烟雾
{
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.lbl_port = new System.Windows.Forms.Label();
this.com_port = new System.Windows.Forms.ComboBox();
this.btn_open = new System.Windows.Forms.Button();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.txt_even = new System.Windows.Forms.TextBox();
this.lbl_even = new System.Windows.Forms.Label();
this.txt_time = new System.Windows.Forms.TextBox();
this.lbl_time = new System.Windows.Forms.Label();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// lbl_port
//
this.lbl_port.AutoSize = true;
this.lbl_port.Location = new System.Drawing.Point(53, 21);
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 = "串口";
//
// com_port
//
this.com_port.FormattingEnabled = true;
this.com_port.Location = new System.Drawing.Point(100, 18);
this.com_port.Name = "com_port";
this.com_port.Size = new System.Drawing.Size(121, 20);
this.com_port.TabIndex = 1;
//
// btn_open
//
this.btn_open.Location = new System.Drawing.Point(227, 16);
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);
//
// groupBox1
//
this.groupBox1.Controls.Add(this.txt_even);
this.groupBox1.Controls.Add(this.lbl_even);
this.groupBox1.Controls.Add(this.txt_time);
this.groupBox1.Controls.Add(this.lbl_time);
this.groupBox1.Location = new System.Drawing.Point(30, 63);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(286, 110);
this.groupBox1.TabIndex = 3;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "数据显示";
//
// txt_even
//
this.txt_even.Location = new System.Drawing.Point(70, 70);
this.txt_even.Name = "txt_even";
this.txt_even.Size = new System.Drawing.Size(133, 21);
this.txt_even.TabIndex = 3;
//
// lbl_even
//
this.lbl_even.AutoSize = true;
this.lbl_even.Location = new System.Drawing.Point(23, 73);
this.lbl_even.Name = "lbl_even";
this.lbl_even.Size = new System.Drawing.Size(29, 12);
this.lbl_even.TabIndex = 2;
this.lbl_even.Text = "事件";
//
// txt_time
//
this.txt_time.Location = new System.Drawing.Point(70, 34);
this.txt_time.Name = "txt_time";
this.txt_time.Size = new System.Drawing.Size(133, 21);
this.txt_time.TabIndex = 1;
//
// lbl_time
//
this.lbl_time.AutoSize = true;
this.lbl_time.Location = new System.Drawing.Point(23, 37);
this.lbl_time.Name = "lbl_time";
this.lbl_time.Size = new System.Drawing.Size(29, 12);
this.lbl_time.TabIndex = 0;
this.lbl_time.Text = "时间";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(342, 193);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.btn_open);
this.Controls.Add(this.com_port);
this.Controls.Add(this.lbl_port);
this.Name = "Form1";
this.Text = "烟雾";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing);
this.Load += new System.EventHandler(this.Form1_Load);
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label lbl_port;
private System.Windows.Forms.ComboBox com_port;
private System.Windows.Forms.Button btn_open;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.TextBox txt_even;
private System.Windows.Forms.Label lbl_even;
private System.Windows.Forms.TextBox txt_time;
private System.Windows.Forms.Label lbl_time;
}
}
+92
View File
@@ -0,0 +1,92 @@
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 System.Threading;//引用线程命名空间
namespace 烟雾
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
bool IsOpen = false;
bool IsFirst = true;//记录线程是否第一次打开
Thread thd;//定义Thread线程
private void Form1_Load(object sender, EventArgs e)
{
//用 foreach 循环把所有可用的串口号加入列表
foreach (string item in SerialPort.GetPortNames())
{
com_port.Items.Add(item);
}
thd = new Thread(GetData);//实例化线程,绑定线程运行方法
Control.CheckForIllegalCrossThreadCalls = false;//允许跨线程调用
}
private void GetData()
{
//线程运行方法,不断循环运行
while (true)
{
if (DeviceCtrlHelper.adam4150Helper.SetData().smokeValue)//判断烟雾状态,true为发现烟雾灾情,false为正常状态
{
txt_time.Text = DateTime.Now.ToString();
txt_even.Text = "发现烟情";
}
else
{
txt_time.Text = DateTime.Now.ToString();
txt_even.Text = "正常";
}
Thread.Sleep(2000);//线程休眠2s
}
}
private void btn_open_Click(object sender, EventArgs e)
{
IsOpen = !IsOpen;
if (IsOpen)
{
DeviceCtrlHelper.adam4150Helper.Open(com_port.Text);
btn_open.Text = "关闭";
if (IsFirst)
{
IsFirst = false;
thd.Start();//第一次打开时启动线程
}
else
{
thd.Resume();//继续已挂起的线程
}
}
else
{
DeviceCtrlHelper.adam4150Helper.Close();
btn_open.Text = "开启";
thd.Suspend();//挂起线程
}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
//挂起的线程不能直接终止,要先让它继续
if (thd.ThreadState == ThreadState.Suspended)
{
thd.Resume();
}
thd.Abort();//终止线程
}
}
}
+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 烟雾
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
+30
View File
@@ -0,0 +1,30 @@
# 评分规则:书上评价表的功能项。每项单独启动一次程序,按步骤操作,核对结果。
# 格式说明见 server/src/grading/checks.ts
- title: 按钮能打开串口、开启线程,更改按钮文字
steps:
- select: { control: com_port, item: COM3 }
- click: btn_open
- expect: { control: btn_open, text: 关闭, desc: 按钮文字变成"关闭" }
- expect: { control: txt_time, matches: '\d{1,2}:\d{2}', within: 5s, desc: 显示当前时间 }
- title: 能利用线程实时显示烟雾传感器数据
steps:
- select: { control: com_port, item: COM3 }
- click: btn_open
- board: { smoke: true }
- expect: { control: txt_even, contains: 发现烟情, within: 5s }
- board: { smoke: false }
- expect: { control: txt_even, contains: 正常, within: 5s }
- title: 再点按钮能关闭串口、挂起线程,再次打开时线程继续
steps:
- select: { control: com_port, item: COM3 }
- click: btn_open
- expect: { control: txt_time, matches: '\d{1,2}:\d{2}', within: 5s, desc: 显示当前时间 }
- click: btn_open
- expect: { control: btn_open, text: 开启, desc: 按钮文字变回"开启" }
- expect: { control: txt_time, unchanged: 5s, desc: 不再更新时间(线程应已挂起) }
- click: btn_open
- expect: { control: btn_open, text: 关闭, desc: 按钮文字变成"关闭" }
- board: { smoke: true }
- expect: { control: txt_even, contains: 发现烟情, within: 5s, desc: 继续显示烟雾数据(线程应已继续) }
+4
View File
@@ -0,0 +1,4 @@
{
"title": "项目5 任务2 采集烟雾传感器数据",
"source": "教材书 p98–101,界面取自配套参考工程,控件名按书上表格修改;关闭窗体时先让挂起的线程继续再终止(书上直接 Abort 挂起的线程会出错)"
}
+241
View File
@@ -0,0 +1,241 @@
namespace 火焰烟雾
{
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.led1 = new WinFormsDeviceControlLibrary.LED();
this.lbl_time = new System.Windows.Forms.Label();
this.txt_time = new System.Windows.Forms.TextBox();
this.txt_fire = new System.Windows.Forms.TextBox();
this.lbl_fire = new System.Windows.Forms.Label();
this.txt_smoke = new System.Windows.Forms.TextBox();
this.lbl_smoke = new System.Windows.Forms.Label();
this.lbl_Ledport = new System.Windows.Forms.Label();
this.com_ledPort = new System.Windows.Forms.ComboBox();
this.com_environmentPort = new System.Windows.Forms.ComboBox();
this.lbl_4150port = new System.Windows.Forms.Label();
this.btn_Open = new System.Windows.Forms.Button();
this.btn_get = new System.Windows.Forms.Button();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.OpenRecord = new System.Windows.Forms.Button();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.SuspendLayout();
//
// led1
//
this.led1.BackColor = System.Drawing.Color.Black;
this.led1.Location = new System.Drawing.Point(19, 0);
this.led1.Name = "led1";
this.led1.Size = new System.Drawing.Size(800, 130);
this.led1.TabIndex = 0;
//
// lbl_time
//
this.lbl_time.AutoSize = true;
this.lbl_time.Location = new System.Drawing.Point(62, 163);
this.lbl_time.Name = "lbl_time";
this.lbl_time.Size = new System.Drawing.Size(29, 12);
this.lbl_time.TabIndex = 1;
this.lbl_time.Text = "时间";
//
// txt_time
//
this.txt_time.Location = new System.Drawing.Point(109, 160);
this.txt_time.Name = "txt_time";
this.txt_time.Size = new System.Drawing.Size(174, 21);
this.txt_time.TabIndex = 2;
//
// txt_fire
//
this.txt_fire.Location = new System.Drawing.Point(109, 205);
this.txt_fire.Name = "txt_fire";
this.txt_fire.Size = new System.Drawing.Size(174, 21);
this.txt_fire.TabIndex = 4;
//
// lbl_fire
//
this.lbl_fire.AutoSize = true;
this.lbl_fire.Location = new System.Drawing.Point(62, 208);
this.lbl_fire.Name = "lbl_fire";
this.lbl_fire.Size = new System.Drawing.Size(29, 12);
this.lbl_fire.TabIndex = 3;
this.lbl_fire.Text = "火焰";
//
// txt_smoke
//
this.txt_smoke.Location = new System.Drawing.Point(109, 256);
this.txt_smoke.Name = "txt_smoke";
this.txt_smoke.Size = new System.Drawing.Size(174, 21);
this.txt_smoke.TabIndex = 6;
//
// lbl_smoke
//
this.lbl_smoke.AutoSize = true;
this.lbl_smoke.Location = new System.Drawing.Point(62, 259);
this.lbl_smoke.Name = "lbl_smoke";
this.lbl_smoke.Size = new System.Drawing.Size(29, 12);
this.lbl_smoke.TabIndex = 5;
this.lbl_smoke.Text = "烟雾";
//
// lbl_Ledport
//
this.lbl_Ledport.AutoSize = true;
this.lbl_Ledport.Location = new System.Drawing.Point(29, 26);
this.lbl_Ledport.Name = "lbl_Ledport";
this.lbl_Ledport.Size = new System.Drawing.Size(47, 12);
this.lbl_Ledport.TabIndex = 7;
this.lbl_Ledport.Text = "L E D";
//
// com_ledPort
//
this.com_ledPort.FormattingEnabled = true;
this.com_ledPort.Location = new System.Drawing.Point(88, 23);
this.com_ledPort.Name = "com_ledPort";
this.com_ledPort.Size = new System.Drawing.Size(121, 20);
this.com_ledPort.TabIndex = 8;
//
// com_environmentPort
//
this.com_environmentPort.FormattingEnabled = true;
this.com_environmentPort.Location = new System.Drawing.Point(88, 49);
this.com_environmentPort.Name = "com_environmentPort";
this.com_environmentPort.Size = new System.Drawing.Size(121, 20);
this.com_environmentPort.TabIndex = 10;
//
// lbl_4150port
//
this.lbl_4150port.AutoSize = true;
this.lbl_4150port.Location = new System.Drawing.Point(29, 52);
this.lbl_4150port.Name = "lbl_4150port";
this.lbl_4150port.Size = new System.Drawing.Size(53, 12);
this.lbl_4150port.TabIndex = 9;
this.lbl_4150port.Text = "环境采集";
//
// btn_Open
//
this.btn_Open.Location = new System.Drawing.Point(134, 85);
this.btn_Open.Name = "btn_Open";
this.btn_Open.Size = new System.Drawing.Size(75, 23);
this.btn_Open.TabIndex = 11;
this.btn_Open.Text = "开启";
this.btn_Open.UseVisualStyleBackColor = true;
this.btn_Open.Click += new System.EventHandler(this.btn_Open_Click);
//
// btn_get
//
this.btn_get.Location = new System.Drawing.Point(270, 20);
this.btn_get.Name = "btn_get";
this.btn_get.Size = new System.Drawing.Size(49, 117);
this.btn_get.TabIndex = 12;
this.btn_get.Text = "获取";
this.btn_get.UseVisualStyleBackColor = true;
this.btn_get.Click += new System.EventHandler(this.btn_get_Click);
//
// groupBox1
//
this.groupBox1.Controls.Add(this.OpenRecord);
this.groupBox1.Controls.Add(this.lbl_Ledport);
this.groupBox1.Controls.Add(this.btn_Open);
this.groupBox1.Controls.Add(this.com_ledPort);
this.groupBox1.Controls.Add(this.com_environmentPort);
this.groupBox1.Controls.Add(this.lbl_4150port);
this.groupBox1.Location = new System.Drawing.Point(447, 143);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(375, 150);
this.groupBox1.TabIndex = 13;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "配置";
//
// OpenRecord
//
this.OpenRecord.Location = new System.Drawing.Point(256, 23);
this.OpenRecord.Name = "OpenRecord";
this.OpenRecord.Size = new System.Drawing.Size(99, 25);
this.OpenRecord.TabIndex = 13;
this.OpenRecord.Text = "历史灾情信息";
this.OpenRecord.UseVisualStyleBackColor = true;
this.OpenRecord.Click += new System.EventHandler(this.OpenRecord_Click);
//
// groupBox2
//
this.groupBox2.Controls.Add(this.btn_get);
this.groupBox2.Location = new System.Drawing.Point(19, 136);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(402, 157);
this.groupBox2.TabIndex = 14;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "数据采集";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(834, 315);
this.Controls.Add(this.txt_smoke);
this.Controls.Add(this.lbl_smoke);
this.Controls.Add(this.txt_fire);
this.Controls.Add(this.lbl_fire);
this.Controls.Add(this.txt_time);
this.Controls.Add(this.lbl_time);
this.Controls.Add(this.led1);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.groupBox2);
this.Name = "Form1";
this.Text = "火焰烟雾";
this.Load += new System.EventHandler(this.Form1_Load);
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.groupBox2.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private WinFormsDeviceControlLibrary.LED led1;
private System.Windows.Forms.Label lbl_time;
private System.Windows.Forms.TextBox txt_time;
private System.Windows.Forms.TextBox txt_fire;
private System.Windows.Forms.Label lbl_fire;
private System.Windows.Forms.TextBox txt_smoke;
private System.Windows.Forms.Label lbl_smoke;
private System.Windows.Forms.Label lbl_Ledport;
private System.Windows.Forms.ComboBox com_ledPort;
private System.Windows.Forms.ComboBox com_environmentPort;
private System.Windows.Forms.Label lbl_4150port;
private System.Windows.Forms.Button btn_Open;
private System.Windows.Forms.Button btn_get;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.Button OpenRecord;
}
}
+94
View File
@@ -0,0 +1,94 @@
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;//引用设备控制库下的Model命名空间
namespace 火焰烟雾
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
ADAM4150ResModel ResModel;
bool IsOpen = false;
string LED_MSG = "";//存储LED显示屏所需发送的文字信息
private void Form1_Load(object sender, EventArgs e)
{
com_environmentPort.Items.Clear();
com_ledPort.Items.Clear();
//将系统串口名依次加入下拉列表框中,由于本题使用串口服务器,所以COM1计算机串口可不加入串口列表
for (int i = 0; i < SerialPort.GetPortNames().Length; i++)
{
//判断计算机的默认串口,将其排除
if (SerialPort.GetPortNames()[i].ToUpper() == "COM1")
{
continue;//跳出此次循环
}
com_environmentPort.Items.Add(SerialPort.GetPortNames()[i].ToString());
com_ledPort.Items.Add(SerialPort.GetPortNames()[i].ToString());
}
}
private void btn_Open_Click(object sender, EventArgs e)
{
IsOpen = !IsOpen;
if (IsOpen)
{
DeviceCtrlHelper.adam4150Helper.Open(com_environmentPort.Text);
DeviceCtrlHelper.ledHelper.OpenLedCom(com_ledPort.Text);
btn_Open.Text = "关闭";
}
else
{
DeviceCtrlHelper.adam4150Helper.Close();
btn_Open.Text = "开启";
}
}
private void btn_get_Click(object sender, EventArgs e)
{
ResModel = DeviceCtrlHelper.adam4150Helper.SetData();//获取数字量采集器ADAM 4150的最新数据
LED_MSG = "";
txt_time.Text = DateTime.Now.ToString();
txt_fire.Text = "正常";
txt_smoke.Text = "正常";
if (ResModel.fireValue)
{
txt_fire.Text = "发现火情";
LED_MSG += "发现火情";
RecordClass.record[RecordClass.recoudeindex, 0] = txt_time.Text;//记录灾情时间至数组
RecordClass.record[RecordClass.recoudeindex, 1] = " 发现火情";//记录灾情内容至数组
RecordClass.recoudeindex++;
}
if (ResModel.smokeValue)
{
txt_smoke.Text = "发现烟情";
LED_MSG += "发现烟情";
RecordClass.record[RecordClass.recoudeindex, 0] = txt_time.Text;//记录灾情时间至数组
RecordClass.record[RecordClass.recoudeindex, 1] = " 发现烟情";//记录灾情内容至数组
RecordClass.recoudeindex++;
}
string ResStr = DeviceCtrlHelper.ledHelper.SendLedString(LED_MSG);
if (!(ResStr.IndexOf("Error") >= 0))
led1.setLedText(ResStr);//推送灾情信息至LED显示屏
}
private void OpenRecord_Click(object sender, EventArgs e)
{
Form2 fr2 = new Form2();
fr2.Show();
}
}
}
+60
View File
@@ -0,0 +1,60 @@
namespace 火焰烟雾
{
partial class Form2
{
/// <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.lstbRecored = new System.Windows.Forms.ListBox();
this.SuspendLayout();
//
// lstbRecored
//
this.lstbRecored.FormattingEnabled = true;
this.lstbRecored.ItemHeight = 12;
this.lstbRecored.Location = new System.Drawing.Point(12, 26);
this.lstbRecored.Name = "lstbRecored";
this.lstbRecored.Size = new System.Drawing.Size(260, 148);
this.lstbRecored.TabIndex = 0;
//
// Form2
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 185);
this.Controls.Add(this.lstbRecored);
this.Name = "Form2";
this.Text = "历史灾情记录";
this.Load += new System.EventHandler(this.Form2_Load);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.ListBox lstbRecored;
}
}
+29
View File
@@ -0,0 +1,29 @@
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;
namespace 火焰烟雾
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
//把数组里记录的灾情信息逐条加入列表框
for (int i = 0; i < RecordClass.recoudeindex; i++)
{
lstbRecored.Items.Add(RecordClass.record[i, 0] + " " + RecordClass.record[i, 1]);
}
}
}
}
+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 火焰烟雾
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
+14
View File
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 火焰烟雾
{
class RecordClass
{
public static string[,] record = new string[50, 2];//定义一个二维数组,用于存储灾情信息的时间和内容
public static int recoudeindex = 0;//用于记录灾情信息的索引位置
}
}
+40
View File
@@ -0,0 +1,40 @@
# 评分规则:书上评价表的功能项。每项单独启动一次程序,按步骤操作,核对结果。
# 格式说明见 server/src/grading/checks.ts
- title: 能实时显示火焰、烟雾传感器数据
steps:
- select: { control: com_environmentPort, item: COM3 }
- select: { control: com_ledPort, item: COM5 }
- click: btn_Open
- expect: { control: btn_Open, text: 关闭, desc: 按钮文字变成"关闭" }
- board: { fire: true }
- click: btn_get
- expect: { control: txt_fire, contains: 发现火情 }
- expect: { control: txt_smoke, contains: 正常 }
- expect: { control: txt_time, matches: '\d{1,2}:\d{2}', desc: 显示当前时间 }
- board: { fire: false, smoke: true }
- click: btn_get
- expect: { control: txt_fire, contains: 正常 }
- expect: { control: txt_smoke, contains: 发现烟情 }
- title: 能正确推送灾情信息到 LED 屏
steps:
- select: { control: com_environmentPort, item: COM3 }
- select: { control: com_ledPort, item: COM5 }
- click: btn_Open
- board: { fire: true }
- click: btn_get
- expect: { led: 发现火情 }
- expect: { control: led1, ledText: 发现火情, desc: 窗体上的 LED 控件显示"发现火情" }
- title: 能利用数组存储灾情信息,在历史灾情窗体里显示
steps:
- select: { control: com_environmentPort, item: COM3 }
- select: { control: com_ledPort, item: COM5 }
- click: btn_Open
- board: { fire: true }
- click: btn_get
- board: { fire: false, smoke: true }
- click: btn_get
- click: OpenRecord
- expect: { control: lstbRecored, contains: 发现火情, desc: 列表里有"发现火情"的记录 }
- expect: { control: lstbRecored, contains: 发现烟情, desc: 列表里有"发现烟情"的记录 }
+4
View File
@@ -0,0 +1,4 @@
{
"title": "项目5 任务3 实时推送灾情信息",
"source": "教材书 p104–107,界面取自配套参考工程,控件名按书上表格修改;修正烟雾记成“发现火情”的错误,列表框按表5-7 命名为 lstbRecored"
}