项目 7 情景控制:虚拟时钟、项目资源、Windows Media Player、TrackBar

- 虚拟时钟:实训台时钟面板可拨时间、1×/10×/60× 倍速、恢复真实时间;编译时把
  DateTime.Now / Today / UtcNow 改写成 SimClock;评分规则加 clock 步骤
- 项目资源(Properties.Resources):平台素材库(自绘开关图片、合成门铃声),"项目资源"对话框勾选,
  平台生成 Properties/Resources.Designer.cs;设计器图片框的"图片"属性可选资源;程序目录下的 Resources
  指向素材库;未添加资源时给中文提示
- Windows Media Player(AxWMPLib):设置 URL 自动播放、Ctlcontrols.play/stop,浏览器里播放声音,
  实训台加广播喇叭;编译时给窗体嵌空资源,OcxState 取到 null 不报错;图片和声音统一按内容缓存(blob)
- TrackBar:拖动、点轨道、方向键,先 ValueChanged 再 Scroll;设计器加"滑动条""媒体播放器"
- 评分规则加 value、media 检查;示例项目 7 任务 1–3(修正书上开关灯判断写反、漏填串口列表)
- 修正:Properties/ 下的资源类不当作窗体;带命名空间的 System.AppDomain.CurrentDomain.BaseDirectory 放行
- 测试:虚拟时钟、TrackBar、项目 7 示例评分、作业起点带资源类

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
xuyueandClaude Opus 5.5 committed 2026-10-23 14:11:05 +08:00
1 parent a9af26c2d6
commit eedf1aa2fb
66 files changed
+3538 -43

No files matched your search

+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 frm_control());
}
}
}
@@ -0,0 +1,24 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 项目资源(平台素材库)。在"项目资源"里添加或移除,不要手动修改这个文件。
// </auto-generated>
//------------------------------------------------------------------------------
namespace 教室情景模式.Properties {
/// <summary>
/// 项目资源:Properties.Resources.资源名
/// </summary>
internal class Resources {
/// <summary>开关:开</summary>
internal static System.Drawing.Bitmap switch_on {
get { return global::Sim.Host.ProjectResources.Image("switch_on.png"); }
}
/// <summary>开关:关</summary>
internal static System.Drawing.Bitmap switch_off {
get { return global::Sim.Host.ProjectResources.Image("switch_off.png"); }
}
}
}
+25
View File
@@ -0,0 +1,25 @@
# 评分规则:书上评价表的功能项。每项单独启动一次程序,按步骤操作,核对结果。
# 格式说明见 server/src/grading/checks.ts
- title: 能实时显示环境数据
steps:
- select: { control: com_import, item: COM2 }
- click: btn_apply
- expect: { control: btn_apply, text: 关闭, desc: 按钮文字变成"关闭" }
- board: { light: 600, temperature: 22, humidity: 48 }
- expect: { control: txt_light, text: '600', within: 5s }
- expect: { control: txt_temperature, text: '22', within: 5s }
- expect: { control: txt_humidity, text: '48', within: 5s }
- title: 能根据环境数据的变化实时控制智能设备
steps:
- select: { control: com_import, item: COM2 }
- click: btn_apply
- board: { light: 300, temperature: 22 }
- expect: { relay: 1, on: true, within: 5s, desc: 光照低于 400 时打开照明灯 }
- expect: { control: lamp, on: true, desc: 窗体上的灯亮 }
- board: { light: 900 }
- expect: { relay: 1, on: false, within: 5s, desc: 光照高于 800 时关闭照明灯 }
- board: { temperature: 33 }
- expect: { control: trb_airconditione, value: 26, within: 5s, desc: 温度高于 30℃ 时空调设为 26℃ }
- board: { temperature: 3 }
- expect: { control: trb_airconditione, value: 25, within: 5s, desc: 温度低于 5℃ 时空调设为 25℃ }
+4
View File
@@ -0,0 +1,4 @@
{
"title": "项目7 任务1 实现智慧教室",
"source": "教材书 p133–137,界面和代码取自配套参考工程(手动开关灯的判断书上写反了,参考工程是对的);开关图片来自平台素材库"
}
+350
View File
@@ -0,0 +1,350 @@
namespace 教室情景模式
{
partial class frm_control
{
/// <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.lbl_mode = new System.Windows.Forms.Label();
this.btn_apply = new System.Windows.Forms.Button();
this.grp_mode = new System.Windows.Forms.GroupBox();
this.grp_input = new System.Windows.Forms.GroupBox();
this.txt_temperature = new System.Windows.Forms.TextBox();
this.txt_humidity = new System.Windows.Forms.TextBox();
this.com_import = new System.Windows.Forms.ComboBox();
this.lbl_temperature = new System.Windows.Forms.Label();
this.txt_light = new System.Windows.Forms.TextBox();
this.lbl_import = new System.Windows.Forms.Label();
this.lbl_humidity = new System.Windows.Forms.Label();
this.lbl_light = new System.Windows.Forms.Label();
this.grp_status = new System.Windows.Forms.GroupBox();
this.pic_airconditioneStatus = new System.Windows.Forms.PictureBox();
this.lbl_airconditionmin = new System.Windows.Forms.Label();
this.lbl_airconditionmax = new System.Windows.Forms.Label();
this.trb_airconditione = new System.Windows.Forms.TrackBar();
this.lamp = new WinFormsDeviceControlLibrary.Lamp();
this.lbl_airconditione = new System.Windows.Forms.Label();
this.pic_lightsStatus = new System.Windows.Forms.PictureBox();
this.lbl_lights = new System.Windows.Forms.Label();
this.timer = new System.Windows.Forms.Timer(this.components);
this.grp_mode.SuspendLayout();
this.grp_input.SuspendLayout();
this.grp_status.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pic_airconditioneStatus)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.trb_airconditione)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pic_lightsStatus)).BeginInit();
this.SuspendLayout();
//
// lbl_mode
//
this.lbl_mode.AutoSize = true;
this.lbl_mode.Location = new System.Drawing.Point(109, 30);
this.lbl_mode.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.lbl_mode.Name = "lbl_mode";
this.lbl_mode.Size = new System.Drawing.Size(89, 12);
this.lbl_mode.TabIndex = 1;
this.lbl_mode.Text = "智慧教室将开启";
//
// btn_apply
//
this.btn_apply.Location = new System.Drawing.Point(285, 22);
this.btn_apply.Margin = new System.Windows.Forms.Padding(2);
this.btn_apply.Name = "btn_apply";
this.btn_apply.Size = new System.Drawing.Size(55, 28);
this.btn_apply.TabIndex = 2;
this.btn_apply.Text = "启用";
this.btn_apply.UseVisualStyleBackColor = true;
this.btn_apply.Click += new System.EventHandler(this.btn_apply_Click);
//
// grp_mode
//
this.grp_mode.Controls.Add(this.lbl_mode);
this.grp_mode.Controls.Add(this.btn_apply);
this.grp_mode.Location = new System.Drawing.Point(8, 8);
this.grp_mode.Margin = new System.Windows.Forms.Padding(2);
this.grp_mode.Name = "grp_mode";
this.grp_mode.Padding = new System.Windows.Forms.Padding(2);
this.grp_mode.Size = new System.Drawing.Size(396, 59);
this.grp_mode.TabIndex = 3;
this.grp_mode.TabStop = false;
this.grp_mode.Text = "模式选择";
//
// grp_input
//
this.grp_input.Controls.Add(this.txt_temperature);
this.grp_input.Controls.Add(this.txt_humidity);
this.grp_input.Controls.Add(this.com_import);
this.grp_input.Controls.Add(this.lbl_temperature);
this.grp_input.Controls.Add(this.txt_light);
this.grp_input.Controls.Add(this.lbl_import);
this.grp_input.Controls.Add(this.lbl_humidity);
this.grp_input.Controls.Add(this.lbl_light);
this.grp_input.Location = new System.Drawing.Point(8, 71);
this.grp_input.Margin = new System.Windows.Forms.Padding(2);
this.grp_input.Name = "grp_input";
this.grp_input.Padding = new System.Windows.Forms.Padding(2);
this.grp_input.Size = new System.Drawing.Size(133, 236);
this.grp_input.TabIndex = 4;
this.grp_input.TabStop = false;
this.grp_input.Text = "采集量";
//
// txt_temperature
//
this.txt_temperature.Location = new System.Drawing.Point(56, 113);
this.txt_temperature.Margin = new System.Windows.Forms.Padding(2);
this.txt_temperature.Name = "txt_temperature";
this.txt_temperature.Size = new System.Drawing.Size(65, 21);
this.txt_temperature.TabIndex = 3;
//
// txt_humidity
//
this.txt_humidity.Location = new System.Drawing.Point(57, 160);
this.txt_humidity.Margin = new System.Windows.Forms.Padding(2);
this.txt_humidity.Name = "txt_humidity";
this.txt_humidity.Size = new System.Drawing.Size(65, 21);
this.txt_humidity.TabIndex = 3;
//
// com_import
//
this.com_import.FormattingEnabled = true;
this.com_import.Location = new System.Drawing.Point(57, 20);
this.com_import.Margin = new System.Windows.Forms.Padding(2);
this.com_import.Name = "com_import";
this.com_import.Size = new System.Drawing.Size(65, 20);
this.com_import.TabIndex = 6;
//
// lbl_temperature
//
this.lbl_temperature.AutoSize = true;
this.lbl_temperature.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.lbl_temperature.Location = new System.Drawing.Point(22, 117);
this.lbl_temperature.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.lbl_temperature.Name = "lbl_temperature";
this.lbl_temperature.Size = new System.Drawing.Size(31, 12);
this.lbl_temperature.TabIndex = 1;
this.lbl_temperature.Text = "温度";
//
// txt_light
//
this.txt_light.Location = new System.Drawing.Point(57, 67);
this.txt_light.Margin = new System.Windows.Forms.Padding(2);
this.txt_light.Name = "txt_light";
this.txt_light.Size = new System.Drawing.Size(65, 21);
this.txt_light.TabIndex = 2;
//
// lbl_import
//
this.lbl_import.AutoSize = true;
this.lbl_import.Location = new System.Drawing.Point(23, 23);
this.lbl_import.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.lbl_import.Name = "lbl_import";
this.lbl_import.Size = new System.Drawing.Size(29, 12);
this.lbl_import.TabIndex = 1;
this.lbl_import.Text = "串口";
//
// lbl_humidity
//
this.lbl_humidity.AutoSize = true;
this.lbl_humidity.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.lbl_humidity.Location = new System.Drawing.Point(23, 163);
this.lbl_humidity.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.lbl_humidity.Name = "lbl_humidity";
this.lbl_humidity.Size = new System.Drawing.Size(31, 12);
this.lbl_humidity.TabIndex = 1;
this.lbl_humidity.Text = "湿度";
//
// lbl_light
//
this.lbl_light.AutoSize = true;
this.lbl_light.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.lbl_light.Location = new System.Drawing.Point(11, 70);
this.lbl_light.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.lbl_light.Name = "lbl_light";
this.lbl_light.Size = new System.Drawing.Size(44, 12);
this.lbl_light.TabIndex = 0;
this.lbl_light.Text = "光照度";
//
// grp_status
//
this.grp_status.Controls.Add(this.pic_airconditioneStatus);
this.grp_status.Controls.Add(this.lbl_airconditionmin);
this.grp_status.Controls.Add(this.lbl_airconditionmax);
this.grp_status.Controls.Add(this.trb_airconditione);
this.grp_status.Controls.Add(this.lamp);
this.grp_status.Controls.Add(this.lbl_airconditione);
this.grp_status.Controls.Add(this.pic_lightsStatus);
this.grp_status.Controls.Add(this.lbl_lights);
this.grp_status.Location = new System.Drawing.Point(145, 71);
this.grp_status.Margin = new System.Windows.Forms.Padding(2);
this.grp_status.Name = "grp_status";
this.grp_status.Padding = new System.Windows.Forms.Padding(2);
this.grp_status.Size = new System.Drawing.Size(259, 236);
this.grp_status.TabIndex = 5;
this.grp_status.TabStop = false;
this.grp_status.Text = "状态栏";
//
// pic_airconditioneStatus
//
this.pic_airconditioneStatus.Image = global::教室情景模式.Properties.Resources.switch_off;
this.pic_airconditioneStatus.Location = new System.Drawing.Point(58, 27);
this.pic_airconditioneStatus.Margin = new System.Windows.Forms.Padding(2);
this.pic_airconditioneStatus.Name = "pic_airconditioneStatus";
this.pic_airconditioneStatus.Size = new System.Drawing.Size(33, 17);
this.pic_airconditioneStatus.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.pic_airconditioneStatus.TabIndex = 6;
this.pic_airconditioneStatus.TabStop = false;
//
// lbl_airconditionmin
//
this.lbl_airconditionmin.AutoSize = true;
this.lbl_airconditionmin.Location = new System.Drawing.Point(10, 87);
this.lbl_airconditionmin.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.lbl_airconditionmin.Name = "lbl_airconditionmin";
this.lbl_airconditionmin.Size = new System.Drawing.Size(29, 12);
this.lbl_airconditionmin.TabIndex = 5;
this.lbl_airconditionmin.Text = "18℃";
//
// lbl_airconditionmax
//
this.lbl_airconditionmax.AutoSize = true;
this.lbl_airconditionmax.Location = new System.Drawing.Point(95, 87);
this.lbl_airconditionmax.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.lbl_airconditionmax.Name = "lbl_airconditionmax";
this.lbl_airconditionmax.Size = new System.Drawing.Size(29, 12);
this.lbl_airconditionmax.TabIndex = 5;
this.lbl_airconditionmax.Text = "32℃";
//
// trb_airconditione
//
this.trb_airconditione.Location = new System.Drawing.Point(12, 53);
this.trb_airconditione.Margin = new System.Windows.Forms.Padding(2);
this.trb_airconditione.Maximum = 32;
this.trb_airconditione.Minimum = 18;
this.trb_airconditione.Name = "trb_airconditione";
this.trb_airconditione.Size = new System.Drawing.Size(107, 45);
this.trb_airconditione.TabIndex = 4;
this.trb_airconditione.Value = 18;
//
// lamp
//
this.lamp.BackColor = System.Drawing.Color.Transparent;
this.lamp.Location = new System.Drawing.Point(139, 40);
this.lamp.Name = "lamp";
this.lamp.Size = new System.Drawing.Size(105, 180);
this.lamp.TabIndex = 3;
//
// lbl_airconditione
//
this.lbl_airconditione.AutoSize = true;
this.lbl_airconditione.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.lbl_airconditione.Location = new System.Drawing.Point(10, 27);
this.lbl_airconditione.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.lbl_airconditione.Name = "lbl_airconditione";
this.lbl_airconditione.Size = new System.Drawing.Size(31, 12);
this.lbl_airconditione.TabIndex = 2;
this.lbl_airconditione.Text = "空调";
//
// pic_lightsStatus
//
this.pic_lightsStatus.Image = global::教室情景模式.Properties.Resources.switch_off;
this.pic_lightsStatus.Location = new System.Drawing.Point(204, 19);
this.pic_lightsStatus.Margin = new System.Windows.Forms.Padding(2);
this.pic_lightsStatus.Name = "pic_lightsStatus";
this.pic_lightsStatus.Size = new System.Drawing.Size(33, 17);
this.pic_lightsStatus.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.pic_lightsStatus.TabIndex = 1;
this.pic_lightsStatus.TabStop = false;
this.pic_lightsStatus.Click += new System.EventHandler(this.pic_lightsStatus_Click);
//
// lbl_lights
//
this.lbl_lights.AutoSize = true;
this.lbl_lights.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.lbl_lights.Location = new System.Drawing.Point(161, 19);
this.lbl_lights.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.lbl_lights.Name = "lbl_lights";
this.lbl_lights.Size = new System.Drawing.Size(31, 12);
this.lbl_lights.TabIndex = 0;
this.lbl_lights.Text = "灯光";
//
// timer
//
this.timer.Interval = 2000;
this.timer.Tick += new System.EventHandler(this.timer_Tick);
//
// frm_control
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(417, 315);
this.Controls.Add(this.grp_status);
this.Controls.Add(this.grp_input);
this.Controls.Add(this.grp_mode);
this.Margin = new System.Windows.Forms.Padding(2);
this.Name = "frm_control";
this.Text = "智慧教室情景控制";
this.Load += new System.EventHandler(this.frm_control_Load);
this.grp_mode.ResumeLayout(false);
this.grp_mode.PerformLayout();
this.grp_input.ResumeLayout(false);
this.grp_input.PerformLayout();
this.grp_status.ResumeLayout(false);
this.grp_status.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pic_airconditioneStatus)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.trb_airconditione)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pic_lightsStatus)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Label lbl_mode;
private System.Windows.Forms.Button btn_apply;
private System.Windows.Forms.GroupBox grp_mode;
private System.Windows.Forms.GroupBox grp_input;
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_light;
private System.Windows.Forms.GroupBox grp_status;
private System.Windows.Forms.Label lbl_lights;
private System.Windows.Forms.TextBox txt_temperature;
private System.Windows.Forms.Label lbl_temperature;
private System.Windows.Forms.ComboBox com_import;
private System.Windows.Forms.Label lbl_import;
private System.Windows.Forms.Timer timer;
private System.Windows.Forms.PictureBox pic_lightsStatus;
private WinFormsDeviceControlLibrary.Lamp lamp;
private System.Windows.Forms.Label lbl_airconditionmin;
private System.Windows.Forms.Label lbl_airconditionmax;
private System.Windows.Forms.TrackBar trb_airconditione;
private System.Windows.Forms.Label lbl_airconditione;
private System.Windows.Forms.PictureBox pic_airconditioneStatus;
}
}
@@ -0,0 +1,126 @@
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;//引用系统IO端口库
using DeviceCtrlLibrary;//引用自定义设备控制库
using DeviceCtrlLibrary.Model;//引用自定义设备控制模型库
namespace 教室情景模式
{
public partial class frm_control : Form
{
bool IsOpen = false;//定义布尔变量记录串口打开情况,默认为false
bool IsLampOpen = false;//定义布尔变量记录电灯打开情况,默认为false
bool IsairconditioneOpen = false;//定义布尔变量记录空调打开情况,默认为false
ADAM4017ResModel ResModel;//创建4017接收数据模型
public frm_control()
{
InitializeComponent();
}
private void frm_control_Load(object sender, EventArgs e)
{
//将系统串口名依次加入下拉列表框中
foreach (string item in SerialPort.GetPortNames())
{
com_import.Items.Add(item);
}
}
private void btn_apply_Click(object sender, EventArgs e)
{
if (!IsOpen)//判断串口是否打开
{
DeviceCtrlHelper.adam4017Helper.Open(com_import.Text);//打开串口
DeviceCtrlHelper.adam4150Helper.Open(com_import.Text);//打开串口
btn_apply.Text = "关闭";//按钮btn_apply显示“关闭”
lbl_mode.Text = "智慧教室已开启";//标签lbl_mode显示“智慧教室已开启”
IsOpen = true;
timer.Start();//通过timer_Tick实时把采集到的数据显示出来,并判断是否需要开灯、关窗帘
}
else
{
DeviceCtrlHelper.adam4017Helper.Close();//关闭采集
DeviceCtrlHelper.adam4150Helper.Close();//关闭4150
timer.Stop();//停止数据采集与自动控制
btn_apply.Text = "启用";
lbl_mode.Text = "智慧教室将开启";
IsOpen = false;
}
}
private void timer_Tick(object sender, EventArgs e)
{
ResModel = DeviceCtrlHelper.adam4017Helper.SetData();//采集数据
//显示采集到的数据
txt_light.Text = ResModel.lightValue;
txt_temperature.Text = ResModel.temperatureValue;
txt_humidity.Text = ResModel.humidityValue;
if (Convert.ToInt16(ResModel.lightValue) < 400)//光照度过低则打开灯
{
pic_lightsStatus.Image = Properties.Resources.switch_on;
IsLampOpen = true;
lamp.OnOff(true);//打开界面灯
DeviceCtrlHelper.adam4150Helper.OnOff(1,true);//打开1通道灯
}
else if (Convert.ToInt16(ResModel.lightValue) > 800 )
{
pic_lightsStatus.Image = Properties.Resources.switch_off;
IsLampOpen = false;
lamp.OnOff(false);//关闭界面灯
DeviceCtrlHelper.adam4150Helper.OnOff(1, false);//关闭1通道灯
}
if (Convert.ToInt16(ResModel.temperatureValue) > 30 )
{
pic_airconditioneStatus.Image = Properties.Resources.switch_on;
IsairconditioneOpen = true;
trb_airconditione.Value = 26;
}
else if (Convert.ToInt16(ResModel.temperatureValue) < 5)
{
pic_airconditioneStatus.Image = Properties.Resources.switch_on;
IsairconditioneOpen = true;
trb_airconditione.Value = 25;
}
else
{
pic_airconditioneStatus.Image = Properties.Resources.switch_off;
IsairconditioneOpen = false;
trb_airconditione.Value = 18;
}
}
private void pic_lightsStatus_Click(object sender, EventArgs e)
{
if (IsLampOpen)
{
pic_lightsStatus.Image = Properties.Resources.switch_off;
IsLampOpen = false;
lamp.OnOff(false);
DeviceCtrlHelper.adam4150Helper.OnOff(1, false);//关闭1通道灯
}
else
{
pic_lightsStatus.Image = Properties.Resources.switch_on;
IsLampOpen = true;
lamp.OnOff(true);
DeviceCtrlHelper.adam4150Helper.OnOff(1, true);//打开1通道灯
}
}
}
}
+388
View File
@@ -0,0 +1,388 @@
namespace 寝室情景模式
{
partial class frm_control
{
/// <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();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frm_control));
this.grp_status = new System.Windows.Forms.GroupBox();
this.alarm1 = new WinFormsDeviceControlLibrary.Alarm();
this.lamp = new WinFormsDeviceControlLibrary.Lamp();
this.lbl_windowopen = new System.Windows.Forms.Label();
this.lbl_windowclose = new System.Windows.Forms.Label();
this.trb_curtain = new System.Windows.Forms.TrackBar();
this.lbl_boardcast = new System.Windows.Forms.Label();
this.lbl_curtain = new System.Windows.Forms.Label();
this.pic_boardcastStatus = new System.Windows.Forms.PictureBox();
this.lbl_lights = new System.Windows.Forms.Label();
this.grp_input = new System.Windows.Forms.GroupBox();
this.txt_temperature = new System.Windows.Forms.TextBox();
this.txt_humidity = new System.Windows.Forms.TextBox();
this.com_import = new System.Windows.Forms.ComboBox();
this.lbl_temperature = new System.Windows.Forms.Label();
this.txt_light = new System.Windows.Forms.TextBox();
this.lbl_import = new System.Windows.Forms.Label();
this.lbl_humidity = new System.Windows.Forms.Label();
this.lbl_light = new System.Windows.Forms.Label();
this.grp_mode = new System.Windows.Forms.GroupBox();
this.lbl_time = new System.Windows.Forms.Label();
this.txt_time = new System.Windows.Forms.TextBox();
this.lbl_mode = new System.Windows.Forms.Label();
this.btn_apply = new System.Windows.Forms.Button();
this.timer = new System.Windows.Forms.Timer(this.components);
this.axWindowsMediaPlayer1 = new AxWMPLib.AxWindowsMediaPlayer();
this.grp_status.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.trb_curtain)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pic_boardcastStatus)).BeginInit();
this.grp_input.SuspendLayout();
this.grp_mode.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.axWindowsMediaPlayer1)).BeginInit();
this.SuspendLayout();
//
// grp_status
//
this.grp_status.Controls.Add(this.alarm1);
this.grp_status.Controls.Add(this.lamp);
this.grp_status.Controls.Add(this.lbl_windowopen);
this.grp_status.Controls.Add(this.lbl_windowclose);
this.grp_status.Controls.Add(this.trb_curtain);
this.grp_status.Controls.Add(this.lbl_boardcast);
this.grp_status.Controls.Add(this.lbl_curtain);
this.grp_status.Controls.Add(this.pic_boardcastStatus);
this.grp_status.Controls.Add(this.lbl_lights);
this.grp_status.Location = new System.Drawing.Point(193, 97);
this.grp_status.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.grp_status.Name = "grp_status";
this.grp_status.Padding = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.grp_status.Size = new System.Drawing.Size(328, 286);
this.grp_status.TabIndex = 8;
this.grp_status.TabStop = false;
this.grp_status.Text = "状态栏";
//
// alarm1
//
this.alarm1.BackColor = System.Drawing.Color.White;
this.alarm1.Location = new System.Drawing.Point(37, 130);
this.alarm1.Margin = new System.Windows.Forms.Padding(5);
this.alarm1.Name = "alarm1";
this.alarm1.Size = new System.Drawing.Size(7, 6);
this.alarm1.TabIndex = 8;
//
// lamp
//
this.lamp.BackColor = System.Drawing.Color.White;
this.lamp.Location = new System.Drawing.Point(172, 48);
this.lamp.Margin = new System.Windows.Forms.Padding(5);
this.lamp.Name = "lamp";
this.lamp.Size = new System.Drawing.Size(148, 232);
this.lamp.TabIndex = 6;
//
// lbl_windowopen
//
this.lbl_windowopen.AutoSize = true;
this.lbl_windowopen.Location = new System.Drawing.Point(13, 101);
this.lbl_windowopen.Name = "lbl_windowopen";
this.lbl_windowopen.Size = new System.Drawing.Size(37, 15);
this.lbl_windowopen.TabIndex = 5;
this.lbl_windowopen.Text = "全开";
//
// lbl_windowclose
//
this.lbl_windowclose.AutoSize = true;
this.lbl_windowclose.Location = new System.Drawing.Point(127, 101);
this.lbl_windowclose.Name = "lbl_windowclose";
this.lbl_windowclose.Size = new System.Drawing.Size(37, 15);
this.lbl_windowclose.TabIndex = 5;
this.lbl_windowclose.Text = "全关";
//
// trb_curtain
//
this.trb_curtain.Location = new System.Drawing.Point(16, 59);
this.trb_curtain.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.trb_curtain.Name = "trb_curtain";
this.trb_curtain.Size = new System.Drawing.Size(143, 56);
this.trb_curtain.TabIndex = 4;
this.trb_curtain.Value = 10;
//
// lbl_boardcast
//
this.lbl_boardcast.AutoSize = true;
this.lbl_boardcast.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.lbl_boardcast.Location = new System.Drawing.Point(23, 186);
this.lbl_boardcast.Name = "lbl_boardcast";
this.lbl_boardcast.Size = new System.Drawing.Size(39, 15);
this.lbl_boardcast.TabIndex = 2;
this.lbl_boardcast.Text = "广播";
//
// lbl_curtain
//
this.lbl_curtain.AutoSize = true;
this.lbl_curtain.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.lbl_curtain.Location = new System.Drawing.Point(13, 34);
this.lbl_curtain.Name = "lbl_curtain";
this.lbl_curtain.Size = new System.Drawing.Size(39, 15);
this.lbl_curtain.TabIndex = 2;
this.lbl_curtain.Text = "窗帘";
//
// pic_boardcastStatus
//
this.pic_boardcastStatus.Enabled = false;
this.pic_boardcastStatus.Image = global::寝室情景模式.Properties.Resources.switch_off;
this.pic_boardcastStatus.Location = new System.Drawing.Point(105, 182);
this.pic_boardcastStatus.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.pic_boardcastStatus.Name = "pic_boardcastStatus";
this.pic_boardcastStatus.Size = new System.Drawing.Size(44, 21);
this.pic_boardcastStatus.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.pic_boardcastStatus.TabIndex = 1;
this.pic_boardcastStatus.TabStop = false;
//
// lbl_lights
//
this.lbl_lights.AutoSize = true;
this.lbl_lights.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.lbl_lights.Location = new System.Drawing.Point(235, 25);
this.lbl_lights.Name = "lbl_lights";
this.lbl_lights.Size = new System.Drawing.Size(39, 15);
this.lbl_lights.TabIndex = 0;
this.lbl_lights.Text = "灯光";
//
// grp_input
//
this.grp_input.Controls.Add(this.txt_temperature);
this.grp_input.Controls.Add(this.txt_humidity);
this.grp_input.Controls.Add(this.com_import);
this.grp_input.Controls.Add(this.lbl_temperature);
this.grp_input.Controls.Add(this.txt_light);
this.grp_input.Controls.Add(this.lbl_import);
this.grp_input.Controls.Add(this.lbl_humidity);
this.grp_input.Controls.Add(this.lbl_light);
this.grp_input.Location = new System.Drawing.Point(10, 97);
this.grp_input.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.grp_input.Name = "grp_input";
this.grp_input.Padding = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.grp_input.Size = new System.Drawing.Size(177, 238);
this.grp_input.TabIndex = 7;
this.grp_input.TabStop = false;
this.grp_input.Text = "采集量";
//
// txt_temperature
//
this.txt_temperature.Location = new System.Drawing.Point(75, 141);
this.txt_temperature.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.txt_temperature.Name = "txt_temperature";
this.txt_temperature.Size = new System.Drawing.Size(85, 25);
this.txt_temperature.TabIndex = 3;
//
// txt_humidity
//
this.txt_humidity.Location = new System.Drawing.Point(76, 200);
this.txt_humidity.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.txt_humidity.Name = "txt_humidity";
this.txt_humidity.Size = new System.Drawing.Size(85, 25);
this.txt_humidity.TabIndex = 3;
//
// com_import
//
this.com_import.FormattingEnabled = true;
this.com_import.Location = new System.Drawing.Point(76, 25);
this.com_import.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.com_import.Name = "com_import";
this.com_import.Size = new System.Drawing.Size(85, 23);
this.com_import.TabIndex = 6;
//
// lbl_temperature
//
this.lbl_temperature.AutoSize = true;
this.lbl_temperature.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.lbl_temperature.Location = new System.Drawing.Point(29, 146);
this.lbl_temperature.Name = "lbl_temperature";
this.lbl_temperature.Size = new System.Drawing.Size(39, 15);
this.lbl_temperature.TabIndex = 1;
this.lbl_temperature.Text = "温度";
//
// txt_light
//
this.txt_light.Location = new System.Drawing.Point(76, 84);
this.txt_light.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.txt_light.Name = "txt_light";
this.txt_light.Size = new System.Drawing.Size(85, 25);
this.txt_light.TabIndex = 2;
//
// lbl_import
//
this.lbl_import.AutoSize = true;
this.lbl_import.Location = new System.Drawing.Point(31, 29);
this.lbl_import.Name = "lbl_import";
this.lbl_import.Size = new System.Drawing.Size(37, 15);
this.lbl_import.TabIndex = 1;
this.lbl_import.Text = "串口";
//
// lbl_humidity
//
this.lbl_humidity.AutoSize = true;
this.lbl_humidity.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.lbl_humidity.Location = new System.Drawing.Point(31, 204);
this.lbl_humidity.Name = "lbl_humidity";
this.lbl_humidity.Size = new System.Drawing.Size(39, 15);
this.lbl_humidity.TabIndex = 1;
this.lbl_humidity.Text = "湿度";
//
// lbl_light
//
this.lbl_light.AutoSize = true;
this.lbl_light.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.lbl_light.Location = new System.Drawing.Point(15, 88);
this.lbl_light.Name = "lbl_light";
this.lbl_light.Size = new System.Drawing.Size(55, 15);
this.lbl_light.TabIndex = 0;
this.lbl_light.Text = "光照度";
//
// grp_mode
//
this.grp_mode.Controls.Add(this.lbl_time);
this.grp_mode.Controls.Add(this.txt_time);
this.grp_mode.Controls.Add(this.lbl_mode);
this.grp_mode.Controls.Add(this.btn_apply);
this.grp_mode.Location = new System.Drawing.Point(11, 10);
this.grp_mode.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.grp_mode.Name = "grp_mode";
this.grp_mode.Padding = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.grp_mode.Size = new System.Drawing.Size(511, 83);
this.grp_mode.TabIndex = 6;
this.grp_mode.TabStop = false;
this.grp_mode.Text = "模式选择";
//
// lbl_time
//
this.lbl_time.AutoSize = true;
this.lbl_time.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.lbl_time.Location = new System.Drawing.Point(68, 20);
this.lbl_time.Name = "lbl_time";
this.lbl_time.Size = new System.Drawing.Size(71, 15);
this.lbl_time.TabIndex = 9;
this.lbl_time.Text = "当前时间";
//
// txt_time
//
this.txt_time.Location = new System.Drawing.Point(145, 16);
this.txt_time.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.txt_time.Name = "txt_time";
this.txt_time.Size = new System.Drawing.Size(127, 25);
this.txt_time.TabIndex = 10;
//
// lbl_mode
//
this.lbl_mode.AutoSize = true;
this.lbl_mode.Location = new System.Drawing.Point(82, 54);
this.lbl_mode.Name = "lbl_mode";
this.lbl_mode.Size = new System.Drawing.Size(0, 15);
this.lbl_mode.TabIndex = 1;
//
// btn_apply
//
this.btn_apply.Location = new System.Drawing.Point(300, 16);
this.btn_apply.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.btn_apply.Name = "btn_apply";
this.btn_apply.Size = new System.Drawing.Size(129, 25);
this.btn_apply.TabIndex = 2;
this.btn_apply.Text = "开启情景模式";
this.btn_apply.UseVisualStyleBackColor = true;
this.btn_apply.Click += new System.EventHandler(this.btn_apply_Click);
//
// timer
//
this.timer.Interval = 1000;
this.timer.Tick += new System.EventHandler(this.timer_Tick);
//
// axWindowsMediaPlayer1
//
this.axWindowsMediaPlayer1.Enabled = true;
this.axWindowsMediaPlayer1.Location = new System.Drawing.Point(12, 345);
this.axWindowsMediaPlayer1.Name = "axWindowsMediaPlayer1";
this.axWindowsMediaPlayer1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axWindowsMediaPlayer1.OcxState")));
this.axWindowsMediaPlayer1.Size = new System.Drawing.Size(175, 38);
this.axWindowsMediaPlayer1.TabIndex = 9;
this.axWindowsMediaPlayer1.Visible = false;
//
// frm_control
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(539, 396);
this.Controls.Add(this.axWindowsMediaPlayer1);
this.Controls.Add(this.grp_status);
this.Controls.Add(this.grp_input);
this.Controls.Add(this.grp_mode);
this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.Name = "frm_control";
this.Text = "智慧寝室情景控制";
this.Load += new System.EventHandler(this.frm_control_Load);
this.grp_status.ResumeLayout(false);
this.grp_status.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.trb_curtain)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pic_boardcastStatus)).EndInit();
this.grp_input.ResumeLayout(false);
this.grp_input.PerformLayout();
this.grp_mode.ResumeLayout(false);
this.grp_mode.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.axWindowsMediaPlayer1)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.GroupBox grp_status;
private WinFormsDeviceControlLibrary.Lamp lamp;
private System.Windows.Forms.Label lbl_windowopen;
private System.Windows.Forms.Label lbl_windowclose;
private System.Windows.Forms.TrackBar trb_curtain;
private System.Windows.Forms.Label lbl_boardcast;
private System.Windows.Forms.Label lbl_curtain;
private System.Windows.Forms.PictureBox pic_boardcastStatus;
private System.Windows.Forms.Label lbl_lights;
private System.Windows.Forms.GroupBox grp_input;
private System.Windows.Forms.TextBox txt_temperature;
private System.Windows.Forms.TextBox txt_humidity;
private System.Windows.Forms.ComboBox com_import;
private System.Windows.Forms.Label lbl_temperature;
private System.Windows.Forms.TextBox txt_light;
private System.Windows.Forms.Label lbl_import;
private System.Windows.Forms.Label lbl_humidity;
private System.Windows.Forms.Label lbl_light;
private System.Windows.Forms.GroupBox grp_mode;
private System.Windows.Forms.Label lbl_mode;
private System.Windows.Forms.Button btn_apply;
private System.Windows.Forms.Label lbl_time;
private System.Windows.Forms.TextBox txt_time;
private System.Windows.Forms.Timer timer;
private WinFormsDeviceControlLibrary.Alarm alarm1;
private AxWMPLib.AxWindowsMediaPlayer axWindowsMediaPlayer1;
}
}
+163
View File
@@ -0,0 +1,163 @@
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;//引用系统IO端口库
using DeviceCtrlLibrary;//引用自定义设备控制库
using DeviceCtrlLibrary.Model;//引用自定义设备控制模型库
using System.Threading;//引用线程库
namespace 寝室情景模式
{
public partial class frm_control : Form
{
bool IsOpen = false;//定义布尔变量记录串口打开情况,默认为false
bool IsLampOopen = false;//定义布尔变量记录灯光打开情况,默认为false
bool IsBoardcastOpen = false;//定义布尔变量记录广播打开情况,默认为false
ADAM4017ResModel ResModel;//创建4017接收数据模型
DateTime now;
DateTime GetUp = DateTime.Today.AddHours(6.75);//6:45起床时间
DateTime ClassBegin = DateTime.Today.AddHours(7.5);//7:30上课开始时间
DateTime ClassEnd = DateTime.Today.AddHours(21.0);//21:00上课结束时间
DateTime Sleep = DateTime.Today.AddHours(22.0);//22:00睡觉时间
public frm_control()
{
InitializeComponent();
}
private void frm_control_Load(object sender, EventArgs e)
{
com_import.Items.Clear();
//将系统串口名依次加入下拉列表框中
foreach (string item in SerialPort.GetPortNames())
{
com_import.Items.Add(item);
}
}
private void btn_apply_Click(object sender, EventArgs e)
{
if (!IsOpen)
{
IsOpen = true;
btn_apply.Text = "停止情景模式";
DeviceCtrlHelper.adam4017Helper.Open(com_import.Text);
DeviceCtrlHelper.adam4150Helper.Open(com_import.Text);
timer.Start();
}
else
{
btn_apply.Text = "开启情景模式";
timer.Stop();
IsOpen = false;
DeviceCtrlHelper.adam4017Helper.Close();
DeviceCtrlHelper.adam4150Helper.Close();
}
}
private void CheckMode()//切换各个模式
{
if (now >= GetUp && now < ClassBegin)
{
lbl_mode.Text = "智慧寝室正处于起床模式";
if (IsLampOopen == false)
{
IsLampOopen = true;
DeviceCtrlHelper.adam4150Helper.OnOff(1, true);
lamp.OnOff(true);
}
if (IsBoardcastOpen == false)
{
IsBoardcastOpen = true;
Thread playthd = new Thread(PlayMp3);
playthd.Start();
}
trb_curtain.Value = 5;
}
else if (now >= ClassBegin && now < ClassEnd)
{
lbl_mode.Text = "智慧寝室正处于上课模式";
if (IsLampOopen == true)
{
IsLampOopen = false;
DeviceCtrlHelper.adam4150Helper.OnOff(1, false);
lamp.OnOff(false);
}
if (IsBoardcastOpen == true)
{
IsBoardcastOpen = false;
pic_boardcastStatus.Image = Properties.Resources.switch_off;
}
trb_curtain.Value = 0;
}
else if (now >= ClassEnd && now < Sleep)
{
lbl_mode.Text = "智慧寝室正处于回寝模式";
if (IsLampOopen == false)
{
IsLampOopen = true;
DeviceCtrlHelper.adam4150Helper.OnOff(1, true);
lamp.OnOff(true);
}
if (IsBoardcastOpen == false)
{
IsBoardcastOpen = true;
Thread playthd = new Thread(PlayMp3);
playthd.Start();
}
trb_curtain.Value = 10;
}
else
{
lbl_mode.Text = "智慧寝室正处于熄灯模式";
if (IsLampOopen == true)
{
IsLampOopen = false;
DeviceCtrlHelper.adam4150Helper.OnOff(1, false);
lamp.OnOff(false);
}
if (IsBoardcastOpen == true)
{
IsBoardcastOpen = false;
pic_boardcastStatus.Image = Properties.Resources.switch_off;
}
trb_curtain.Value = 10;
}
}
private void timer_Tick(object sender, EventArgs e)
{
now = DateTime.Now;
txt_time.Text = now.ToString("HH:mm:ss");//显示时间
ResModel = DeviceCtrlHelper.adam4017Helper.SetData();//采集数据
//显示采集到的数据
txt_light.Text = ResModel.lightValue;//ResModel.airPressureValue
txt_temperature.Text = ResModel.temperatureValue;//ResModel.airQualityValue
txt_humidity.Text = ResModel.humidityValue;//ResModel.CO2Value
CheckMode();
}
private void PlayMp3()//播放mp3音乐
{
pic_boardcastStatus.Image = Properties.Resources.switch_on;
axWindowsMediaPlayer1.URL = System.AppDomain.CurrentDomain.BaseDirectory + "//Resources//ring.mp3";
axWindowsMediaPlayer1.Ctlcontrols.play();
Thread.Sleep(4000);
pic_boardcastStatus.Image = Properties.Resources.switch_off;
}
}
}
+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 frm_control());
}
}
}
@@ -0,0 +1,29 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 项目资源(平台素材库)。在"项目资源"里添加或移除,不要手动修改这个文件。
// </auto-generated>
//------------------------------------------------------------------------------
namespace 寝室情景模式.Properties {
/// <summary>
/// 项目资源:Properties.Resources.资源名
/// </summary>
internal class Resources {
/// <summary>开关:开</summary>
internal static System.Drawing.Bitmap switch_on {
get { return global::Sim.Host.ProjectResources.Image("switch_on.png"); }
}
/// <summary>开关:关</summary>
internal static System.Drawing.Bitmap switch_off {
get { return global::Sim.Host.ProjectResources.Image("switch_off.png"); }
}
/// <summary>铃声</summary>
internal static byte[] ring {
get { return global::Sim.Host.ProjectResources.Bytes("ring.mp3"); }
}
}
}
+31
View File
@@ -0,0 +1,31 @@
# 评分规则:书上评价表的功能项。每项单独启动一次程序,按步骤操作,核对结果。
# 情景模式按时刻切换:用 clock 拨实训台的虚拟时钟(今天的某个时刻)。格式说明见 server/src/grading/checks.ts
- title: 能实时显示环境数据
steps:
- select: { control: com_import, item: COM2 }
- click: btn_apply
- expect: { control: btn_apply, text: 停止情景模式, desc: 按钮文字变成"停止情景模式" }
- board: { light: 650, temperature: 23, humidity: 51 }
- expect: { control: txt_light, text: '650', within: 5s }
- expect: { control: txt_temperature, text: '23', within: 5s }
- expect: { control: txt_time, matches: '^\d{2}:\d{2}:\d{2}$', desc: 显示当前时间 }
- title: 能根据时间段的变化判断寝室情景实时控制智能设备
steps:
- clock: '06:50:00'
- select: { control: com_import, item: COM2 }
- click: btn_apply
- expect: { control: lbl_mode, contains: 起床模式, within: 5s, desc: 6:50 是起床模式 }
- expect: { relay: 1, on: true, desc: 起床模式打开灯光 }
- expect: { control: trb_curtain, value: 5, desc: 起床模式窗帘半开 }
- expect: { media: ring.mp3, desc: 起床模式广播播放铃声 }
- clock: '08:00:00'
- expect: { control: lbl_mode, contains: 上课模式, within: 5s, desc: 8:00 是上课模式 }
- expect: { relay: 1, on: false, desc: 上课模式关闭灯光 }
- expect: { control: trb_curtain, value: 0, desc: 上课模式窗帘全开 }
- clock: '21:30:00'
- expect: { control: lbl_mode, contains: 回寝模式, within: 5s, desc: 21:30 是回寝模式 }
- expect: { control: trb_curtain, value: 10, desc: 回寝模式关窗帘 }
- clock: '23:00:00'
- expect: { control: lbl_mode, contains: 熄灯模式, within: 5s, desc: 23:00 是熄灯模式 }
- expect: { relay: 1, on: false, desc: 熄灯模式关闭灯光 }
+4
View File
@@ -0,0 +1,4 @@
{
"title": "项目7 任务2 实现智慧寝室",
"source": "教材书 p141–145,界面和代码取自配套参考工程;开关图片和铃声来自平台素材库。按时刻切换情景模式:在实训台的时钟上拨时间"
}
+611
View File
@@ -0,0 +1,611 @@
namespace 会议室情景模式
{
partial class frm_control
{
/// <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.grp_status = new System.Windows.Forms.GroupBox();
this.lbl_subMicrophone = new System.Windows.Forms.Label();
this.lbl_mainMicrophone = new System.Windows.Forms.Label();
this.lamp = new WinFormsDeviceControlLibrary.Lamp();
this.lbl_curtainopen = new System.Windows.Forms.Label();
this.lbl_curtainclose = new System.Windows.Forms.Label();
this.trb_curtain = new System.Windows.Forms.TrackBar();
this.lbl_microphone = new System.Windows.Forms.Label();
this.lbl_curtain = new System.Windows.Forms.Label();
this.pic_lightsStatus = new System.Windows.Forms.PictureBox();
this.pic_subMicrophone = new System.Windows.Forms.PictureBox();
this.pic_mainMicrophone = new System.Windows.Forms.PictureBox();
this.lbl_lights = new System.Windows.Forms.Label();
this.grp_input = new System.Windows.Forms.GroupBox();
this.lbl_camera = new System.Windows.Forms.Label();
this.txt_camera = new System.Windows.Forms.TextBox();
this.txt_temperature = new System.Windows.Forms.TextBox();
this.txt_airQuality = new System.Windows.Forms.TextBox();
this.txt_humidity = new System.Windows.Forms.TextBox();
this.com_import = new System.Windows.Forms.ComboBox();
this.lbl_temperature = new System.Windows.Forms.Label();
this.txt_airPressure = new System.Windows.Forms.TextBox();
this.txt_light = new System.Windows.Forms.TextBox();
this.lbl_import = new System.Windows.Forms.Label();
this.lbl_airQuality = new System.Windows.Forms.Label();
this.lbl_airPressure = new System.Windows.Forms.Label();
this.lbl_humidity = new System.Windows.Forms.Label();
this.lbl_light = new System.Windows.Forms.Label();
this.grp_mode = new System.Windows.Forms.GroupBox();
this.com_mode = new System.Windows.Forms.ComboBox();
this.lbl_second = new System.Windows.Forms.Label();
this.lbl_minute = new System.Windows.Forms.Label();
this.lbl_hour = new System.Windows.Forms.Label();
this.lbl_time = new System.Windows.Forms.Label();
this.txt_second = new System.Windows.Forms.TextBox();
this.txt_minute = new System.Windows.Forms.TextBox();
this.txt_hour = new System.Windows.Forms.TextBox();
this.chk_record = new System.Windows.Forms.CheckBox();
this.lbl_mode = new System.Windows.Forms.Label();
this.btn_exit = new System.Windows.Forms.Button();
this.btn_reserve = new System.Windows.Forms.Button();
this.timer = new System.Windows.Forms.Timer(this.components);
this.grp_status.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.trb_curtain)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pic_lightsStatus)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pic_subMicrophone)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pic_mainMicrophone)).BeginInit();
this.grp_input.SuspendLayout();
this.grp_mode.SuspendLayout();
this.SuspendLayout();
//
// grp_status
//
this.grp_status.Controls.Add(this.lbl_subMicrophone);
this.grp_status.Controls.Add(this.lbl_mainMicrophone);
this.grp_status.Controls.Add(this.lamp);
this.grp_status.Controls.Add(this.lbl_curtainopen);
this.grp_status.Controls.Add(this.lbl_curtainclose);
this.grp_status.Controls.Add(this.trb_curtain);
this.grp_status.Controls.Add(this.lbl_microphone);
this.grp_status.Controls.Add(this.lbl_curtain);
this.grp_status.Controls.Add(this.pic_lightsStatus);
this.grp_status.Controls.Add(this.pic_subMicrophone);
this.grp_status.Controls.Add(this.pic_mainMicrophone);
this.grp_status.Controls.Add(this.lbl_lights);
this.grp_status.Location = new System.Drawing.Point(145, 100);
this.grp_status.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.grp_status.Name = "grp_status";
this.grp_status.Padding = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.grp_status.Size = new System.Drawing.Size(294, 270);
this.grp_status.TabIndex = 11;
this.grp_status.TabStop = false;
this.grp_status.Text = "状态栏";
//
// lbl_subMicrophone
//
this.lbl_subMicrophone.AutoSize = true;
this.lbl_subMicrophone.Location = new System.Drawing.Point(113, 140);
this.lbl_subMicrophone.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.lbl_subMicrophone.Name = "lbl_subMicrophone";
this.lbl_subMicrophone.Size = new System.Drawing.Size(17, 12);
this.lbl_subMicrophone.TabIndex = 7;
this.lbl_subMicrophone.Text = "客";
//
// lbl_mainMicrophone
//
this.lbl_mainMicrophone.AutoSize = true;
this.lbl_mainMicrophone.Location = new System.Drawing.Point(64, 140);
this.lbl_mainMicrophone.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.lbl_mainMicrophone.Name = "lbl_mainMicrophone";
this.lbl_mainMicrophone.Size = new System.Drawing.Size(17, 12);
this.lbl_mainMicrophone.TabIndex = 7;
this.lbl_mainMicrophone.Text = "主";
//
// lamp
//
this.lamp.BackColor = System.Drawing.Color.White;
this.lamp.Location = new System.Drawing.Point(175, 65);
this.lamp.Name = "lamp";
this.lamp.Size = new System.Drawing.Size(104, 177);
this.lamp.TabIndex = 6;
//
// lbl_curtainopen
//
this.lbl_curtainopen.AutoSize = true;
this.lbl_curtainopen.Location = new System.Drawing.Point(10, 74);
this.lbl_curtainopen.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.lbl_curtainopen.Name = "lbl_curtainopen";
this.lbl_curtainopen.Size = new System.Drawing.Size(29, 12);
this.lbl_curtainopen.TabIndex = 5;
this.lbl_curtainopen.Text = "全开";
//
// lbl_curtainclose
//
this.lbl_curtainclose.AutoSize = true;
this.lbl_curtainclose.Location = new System.Drawing.Point(95, 74);
this.lbl_curtainclose.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.lbl_curtainclose.Name = "lbl_curtainclose";
this.lbl_curtainclose.Size = new System.Drawing.Size(29, 12);
this.lbl_curtainclose.TabIndex = 5;
this.lbl_curtainclose.Text = "全关";
//
// trb_curtain
//
this.trb_curtain.Location = new System.Drawing.Point(12, 47);
this.trb_curtain.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.trb_curtain.Name = "trb_curtain";
this.trb_curtain.Size = new System.Drawing.Size(107, 45);
this.trb_curtain.TabIndex = 4;
this.trb_curtain.Value = 10;
//
// lbl_microphone
//
this.lbl_microphone.AutoSize = true;
this.lbl_microphone.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.lbl_microphone.Location = new System.Drawing.Point(10, 121);
this.lbl_microphone.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.lbl_microphone.Name = "lbl_microphone";
this.lbl_microphone.Size = new System.Drawing.Size(31, 12);
this.lbl_microphone.TabIndex = 2;
this.lbl_microphone.Text = "话筒";
//
// lbl_curtain
//
this.lbl_curtain.AutoSize = true;
this.lbl_curtain.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.lbl_curtain.Location = new System.Drawing.Point(10, 35);
this.lbl_curtain.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.lbl_curtain.Name = "lbl_curtain";
this.lbl_curtain.Size = new System.Drawing.Size(31, 12);
this.lbl_curtain.TabIndex = 2;
this.lbl_curtain.Text = "窗帘";
//
// pic_lightsStatus
//
this.pic_lightsStatus.Image = global::会议室情景模式.Properties.Resources.switch_off;
this.pic_lightsStatus.Location = new System.Drawing.Point(211, 35);
this.pic_lightsStatus.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.pic_lightsStatus.Name = "pic_lightsStatus";
this.pic_lightsStatus.Size = new System.Drawing.Size(33, 17);
this.pic_lightsStatus.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.pic_lightsStatus.TabIndex = 1;
this.pic_lightsStatus.TabStop = false;
this.pic_lightsStatus.Click += new System.EventHandler(this.pic_lightsStatus_Click);
//
// pic_subMicrophone
//
this.pic_subMicrophone.Image = global::会议室情景模式.Properties.Resources.switch_off;
this.pic_subMicrophone.Location = new System.Drawing.Point(105, 118);
this.pic_subMicrophone.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.pic_subMicrophone.Name = "pic_subMicrophone";
this.pic_subMicrophone.Size = new System.Drawing.Size(33, 17);
this.pic_subMicrophone.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.pic_subMicrophone.TabIndex = 1;
this.pic_subMicrophone.TabStop = false;
this.pic_subMicrophone.Click += new System.EventHandler(this.pic_subMicrophone_Click);
//
// pic_mainMicrophone
//
this.pic_mainMicrophone.Image = global::会议室情景模式.Properties.Resources.switch_off;
this.pic_mainMicrophone.Location = new System.Drawing.Point(57, 118);
this.pic_mainMicrophone.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.pic_mainMicrophone.Name = "pic_mainMicrophone";
this.pic_mainMicrophone.Size = new System.Drawing.Size(33, 17);
this.pic_mainMicrophone.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.pic_mainMicrophone.TabIndex = 1;
this.pic_mainMicrophone.TabStop = false;
this.pic_mainMicrophone.Click += new System.EventHandler(this.pic_mainMicrophone_Click);
//
// lbl_lights
//
this.lbl_lights.AutoSize = true;
this.lbl_lights.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.lbl_lights.Location = new System.Drawing.Point(213, 21);
this.lbl_lights.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.lbl_lights.Name = "lbl_lights";
this.lbl_lights.Size = new System.Drawing.Size(31, 12);
this.lbl_lights.TabIndex = 0;
this.lbl_lights.Text = "灯光";
//
// grp_input
//
this.grp_input.Controls.Add(this.lbl_camera);
this.grp_input.Controls.Add(this.txt_camera);
this.grp_input.Controls.Add(this.txt_temperature);
this.grp_input.Controls.Add(this.txt_airQuality);
this.grp_input.Controls.Add(this.txt_humidity);
this.grp_input.Controls.Add(this.com_import);
this.grp_input.Controls.Add(this.lbl_temperature);
this.grp_input.Controls.Add(this.txt_airPressure);
this.grp_input.Controls.Add(this.txt_light);
this.grp_input.Controls.Add(this.lbl_import);
this.grp_input.Controls.Add(this.lbl_airQuality);
this.grp_input.Controls.Add(this.lbl_airPressure);
this.grp_input.Controls.Add(this.lbl_humidity);
this.grp_input.Controls.Add(this.lbl_light);
this.grp_input.Location = new System.Drawing.Point(8, 100);
this.grp_input.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.grp_input.Name = "grp_input";
this.grp_input.Padding = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.grp_input.Size = new System.Drawing.Size(133, 270);
this.grp_input.TabIndex = 10;
this.grp_input.TabStop = false;
this.grp_input.Text = "采集量";
//
// lbl_camera
//
this.lbl_camera.AutoSize = true;
this.lbl_camera.Location = new System.Drawing.Point(26, 222);
this.lbl_camera.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.lbl_camera.Name = "lbl_camera";
this.lbl_camera.Size = new System.Drawing.Size(77, 12);
this.lbl_camera.TabIndex = 8;
this.lbl_camera.Text = "摄像头IP地址";
//
// txt_camera
//
this.txt_camera.Location = new System.Drawing.Point(19, 244);
this.txt_camera.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.txt_camera.Name = "txt_camera";
this.txt_camera.Size = new System.Drawing.Size(95, 21);
this.txt_camera.TabIndex = 9;
this.txt_camera.Text = "192.168.14.131";
//
// txt_temperature
//
this.txt_temperature.Location = new System.Drawing.Point(62, 80);
this.txt_temperature.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.txt_temperature.Name = "txt_temperature";
this.txt_temperature.Size = new System.Drawing.Size(65, 21);
this.txt_temperature.TabIndex = 3;
//
// txt_airQuality
//
this.txt_airQuality.Location = new System.Drawing.Point(62, 190);
this.txt_airQuality.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.txt_airQuality.Name = "txt_airQuality";
this.txt_airQuality.Size = new System.Drawing.Size(65, 21);
this.txt_airQuality.TabIndex = 3;
//
// txt_humidity
//
this.txt_humidity.Location = new System.Drawing.Point(62, 117);
this.txt_humidity.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.txt_humidity.Name = "txt_humidity";
this.txt_humidity.Size = new System.Drawing.Size(65, 21);
this.txt_humidity.TabIndex = 3;
//
// com_import
//
this.com_import.FormattingEnabled = true;
this.com_import.Location = new System.Drawing.Point(57, 13);
this.com_import.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.com_import.Name = "com_import";
this.com_import.Size = new System.Drawing.Size(65, 20);
this.com_import.TabIndex = 6;
//
// lbl_temperature
//
this.lbl_temperature.AutoSize = true;
this.lbl_temperature.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.lbl_temperature.Location = new System.Drawing.Point(30, 83);
this.lbl_temperature.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.lbl_temperature.Name = "lbl_temperature";
this.lbl_temperature.Size = new System.Drawing.Size(31, 12);
this.lbl_temperature.TabIndex = 1;
this.lbl_temperature.Text = "温度";
//
// txt_airPressure
//
this.txt_airPressure.Location = new System.Drawing.Point(62, 153);
this.txt_airPressure.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.txt_airPressure.Name = "txt_airPressure";
this.txt_airPressure.Size = new System.Drawing.Size(65, 21);
this.txt_airPressure.TabIndex = 2;
//
// txt_light
//
this.txt_light.Location = new System.Drawing.Point(62, 43);
this.txt_light.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.txt_light.Name = "txt_light";
this.txt_light.Size = new System.Drawing.Size(65, 21);
this.txt_light.TabIndex = 2;
//
// lbl_import
//
this.lbl_import.AutoSize = true;
this.lbl_import.Location = new System.Drawing.Point(23, 17);
this.lbl_import.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.lbl_import.Name = "lbl_import";
this.lbl_import.Size = new System.Drawing.Size(29, 12);
this.lbl_import.TabIndex = 1;
this.lbl_import.Text = "串口";
//
// lbl_airQuality
//
this.lbl_airQuality.AutoSize = true;
this.lbl_airQuality.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.lbl_airQuality.Location = new System.Drawing.Point(5, 193);
this.lbl_airQuality.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.lbl_airQuality.Name = "lbl_airQuality";
this.lbl_airQuality.Size = new System.Drawing.Size(57, 12);
this.lbl_airQuality.TabIndex = 1;
this.lbl_airQuality.Text = "空气质量";
//
// lbl_airPressure
//
this.lbl_airPressure.AutoSize = true;
this.lbl_airPressure.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.lbl_airPressure.Location = new System.Drawing.Point(30, 157);
this.lbl_airPressure.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.lbl_airPressure.Name = "lbl_airPressure";
this.lbl_airPressure.Size = new System.Drawing.Size(31, 12);
this.lbl_airPressure.TabIndex = 0;
this.lbl_airPressure.Text = "气压";
//
// lbl_humidity
//
this.lbl_humidity.AutoSize = true;
this.lbl_humidity.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.lbl_humidity.Location = new System.Drawing.Point(30, 120);
this.lbl_humidity.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.lbl_humidity.Name = "lbl_humidity";
this.lbl_humidity.Size = new System.Drawing.Size(31, 12);
this.lbl_humidity.TabIndex = 1;
this.lbl_humidity.Text = "湿度";
//
// lbl_light
//
this.lbl_light.AutoSize = true;
this.lbl_light.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.lbl_light.Location = new System.Drawing.Point(17, 47);
this.lbl_light.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.lbl_light.Name = "lbl_light";
this.lbl_light.Size = new System.Drawing.Size(44, 12);
this.lbl_light.TabIndex = 0;
this.lbl_light.Text = "光照度";
//
// grp_mode
//
this.grp_mode.Controls.Add(this.com_mode);
this.grp_mode.Controls.Add(this.lbl_second);
this.grp_mode.Controls.Add(this.lbl_minute);
this.grp_mode.Controls.Add(this.lbl_hour);
this.grp_mode.Controls.Add(this.lbl_time);
this.grp_mode.Controls.Add(this.txt_second);
this.grp_mode.Controls.Add(this.txt_minute);
this.grp_mode.Controls.Add(this.txt_hour);
this.grp_mode.Controls.Add(this.chk_record);
this.grp_mode.Controls.Add(this.lbl_mode);
this.grp_mode.Controls.Add(this.btn_exit);
this.grp_mode.Controls.Add(this.btn_reserve);
this.grp_mode.Location = new System.Drawing.Point(8, 8);
this.grp_mode.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.grp_mode.Name = "grp_mode";
this.grp_mode.Padding = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.grp_mode.Size = new System.Drawing.Size(431, 88);
this.grp_mode.TabIndex = 9;
this.grp_mode.TabStop = false;
this.grp_mode.Text = "模式选择";
//
// com_mode
//
this.com_mode.FormattingEnabled = true;
this.com_mode.Location = new System.Drawing.Point(191, 53);
this.com_mode.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.com_mode.Name = "com_mode";
this.com_mode.Size = new System.Drawing.Size(61, 20);
this.com_mode.TabIndex = 12;
this.com_mode.Text = "会议";
//
// lbl_second
//
this.lbl_second.AutoSize = true;
this.lbl_second.Location = new System.Drawing.Point(127, 57);
this.lbl_second.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.lbl_second.Name = "lbl_second";
this.lbl_second.Size = new System.Drawing.Size(65, 12);
this.lbl_second.TabIndex = 11;
this.lbl_second.Text = "秒将会有场";
//
// lbl_minute
//
this.lbl_minute.AutoSize = true;
this.lbl_minute.Location = new System.Drawing.Point(91, 57);
this.lbl_minute.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.lbl_minute.Name = "lbl_minute";
this.lbl_minute.Size = new System.Drawing.Size(17, 12);
this.lbl_minute.TabIndex = 11;
this.lbl_minute.Text = "分";
//
// lbl_hour
//
this.lbl_hour.AutoSize = true;
this.lbl_hour.Location = new System.Drawing.Point(56, 57);
this.lbl_hour.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.lbl_hour.Name = "lbl_hour";
this.lbl_hour.Size = new System.Drawing.Size(17, 12);
this.lbl_hour.TabIndex = 11;
this.lbl_hour.Text = "时";
//
// lbl_time
//
this.lbl_time.AutoSize = true;
this.lbl_time.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.lbl_time.Location = new System.Drawing.Point(17, 27);
this.lbl_time.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.lbl_time.Name = "lbl_time";
this.lbl_time.Size = new System.Drawing.Size(126, 12);
this.lbl_time.TabIndex = 9;
this.lbl_time.Text = "当前时间:00:00:00";
//
// txt_second
//
this.txt_second.Location = new System.Drawing.Point(109, 53);
this.txt_second.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.txt_second.Name = "txt_second";
this.txt_second.Size = new System.Drawing.Size(19, 21);
this.txt_second.TabIndex = 10;
this.txt_second.Text = "00";
//
// txt_minute
//
this.txt_minute.Location = new System.Drawing.Point(73, 53);
this.txt_minute.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.txt_minute.Name = "txt_minute";
this.txt_minute.Size = new System.Drawing.Size(19, 21);
this.txt_minute.TabIndex = 10;
this.txt_minute.Text = "20";
//
// txt_hour
//
this.txt_hour.Location = new System.Drawing.Point(38, 53);
this.txt_hour.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.txt_hour.Name = "txt_hour";
this.txt_hour.Size = new System.Drawing.Size(19, 21);
this.txt_hour.TabIndex = 10;
this.txt_hour.Text = "13";
//
// chk_record
//
this.chk_record.AutoSize = true;
this.chk_record.Location = new System.Drawing.Point(344, 26);
this.chk_record.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.chk_record.Name = "chk_record";
this.chk_record.Size = new System.Drawing.Size(72, 16);
this.chk_record.TabIndex = 3;
this.chk_record.Text = "拍照记录";
this.chk_record.UseVisualStyleBackColor = true;
//
// lbl_mode
//
this.lbl_mode.AutoSize = true;
this.lbl_mode.Location = new System.Drawing.Point(162, 27);
this.lbl_mode.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.lbl_mode.Name = "lbl_mode";
this.lbl_mode.Size = new System.Drawing.Size(149, 12);
this.lbl_mode.TabIndex = 1;
this.lbl_mode.Text = "智慧会议室未开启情景模式";
//
// btn_exit
//
this.btn_exit.Location = new System.Drawing.Point(345, 49);
this.btn_exit.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.btn_exit.Name = "btn_exit";
this.btn_exit.Size = new System.Drawing.Size(51, 27);
this.btn_exit.TabIndex = 2;
this.btn_exit.Text = "退出";
this.btn_exit.UseVisualStyleBackColor = true;
this.btn_exit.Click += new System.EventHandler(this.btn_exit_Click);
//
// btn_reserve
//
this.btn_reserve.Location = new System.Drawing.Point(277, 49);
this.btn_reserve.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.btn_reserve.Name = "btn_reserve";
this.btn_reserve.Size = new System.Drawing.Size(51, 27);
this.btn_reserve.TabIndex = 2;
this.btn_reserve.Text = "预约";
this.btn_reserve.UseVisualStyleBackColor = true;
this.btn_reserve.Click += new System.EventHandler(this.btn_reserve_Click);
//
// timer
//
this.timer.Interval = 1000;
this.timer.Tick += new System.EventHandler(this.timer_Tick);
//
// frm_control
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(447, 376);
this.Controls.Add(this.grp_status);
this.Controls.Add(this.grp_input);
this.Controls.Add(this.grp_mode);
this.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.Name = "frm_control";
this.Text = "智慧会议室情景模式";
this.Load += new System.EventHandler(this.frm_control_Load);
this.grp_status.ResumeLayout(false);
this.grp_status.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.trb_curtain)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pic_lightsStatus)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pic_subMicrophone)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pic_mainMicrophone)).EndInit();
this.grp_input.ResumeLayout(false);
this.grp_input.PerformLayout();
this.grp_mode.ResumeLayout(false);
this.grp_mode.PerformLayout();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.GroupBox grp_status;
private WinFormsDeviceControlLibrary.Lamp lamp;
private System.Windows.Forms.Label lbl_curtainopen;
private System.Windows.Forms.Label lbl_curtainclose;
private System.Windows.Forms.TrackBar trb_curtain;
private System.Windows.Forms.Label lbl_microphone;
private System.Windows.Forms.Label lbl_curtain;
private System.Windows.Forms.PictureBox pic_lightsStatus;
private System.Windows.Forms.PictureBox pic_mainMicrophone;
private System.Windows.Forms.Label lbl_lights;
private System.Windows.Forms.GroupBox grp_input;
private System.Windows.Forms.TextBox txt_temperature;
private System.Windows.Forms.TextBox txt_humidity;
private System.Windows.Forms.ComboBox com_import;
private System.Windows.Forms.Label lbl_temperature;
private System.Windows.Forms.TextBox txt_light;
private System.Windows.Forms.Label lbl_import;
private System.Windows.Forms.Label lbl_humidity;
private System.Windows.Forms.Label lbl_light;
private System.Windows.Forms.GroupBox grp_mode;
private System.Windows.Forms.Label lbl_time;
private System.Windows.Forms.TextBox txt_hour;
private System.Windows.Forms.CheckBox chk_record;
private System.Windows.Forms.Label lbl_mode;
private System.Windows.Forms.Button btn_reserve;
private System.Windows.Forms.TextBox txt_airQuality;
private System.Windows.Forms.TextBox txt_airPressure;
private System.Windows.Forms.Label lbl_airQuality;
private System.Windows.Forms.Label lbl_airPressure;
private System.Windows.Forms.ComboBox com_mode;
private System.Windows.Forms.Label lbl_second;
private System.Windows.Forms.Label lbl_minute;
private System.Windows.Forms.Label lbl_hour;
private System.Windows.Forms.TextBox txt_second;
private System.Windows.Forms.TextBox txt_minute;
private System.Windows.Forms.Timer timer;
private System.Windows.Forms.Button btn_exit;
private System.Windows.Forms.Label lbl_subMicrophone;
private System.Windows.Forms.Label lbl_mainMicrophone;
private System.Windows.Forms.PictureBox pic_subMicrophone;
private System.Windows.Forms.Label lbl_camera;
private System.Windows.Forms.TextBox txt_camera;
}
}
+200
View File
@@ -0,0 +1,200 @@
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;//引用系统IO库
using System.IO.Ports;//引用系统IO端口库
using DeviceCtrlLibrary;//引用自定义设备控制库
using DeviceCtrlLibrary.Model;//引用自定义设备控制模型库
namespace 会议室情景模式
{
public partial class frm_control : Form
{
bool IsLightsOpen = false;//定义布尔变量记录电灯打开情况,默认为false
bool IsmainMicrophoneOpen = false;//定义布尔变量记录主麦克风打开情况,默认为false
bool IssubMicrophoneOpen = false;//定义布尔变量记录客麦克风打开情况,默认为false
bool IsInitialized = false;//定义布尔变量记录情景模式是否初始化,默认为false
ADAM4017ResModel ResModel;//创建4017接收数据模型
DateTime now;//定义时间变量记录现在的时间
DateTime reserve=DateTime.Now.AddDays(1) ;//定义时间变量记录预约的时间,默认为明天,防止初始值小于当前时间的假预约情况
Image ReadImage = null;//定义图片变量记录拍摄的图片,默认为空
public frm_control()
{
InitializeComponent();
}
private void frm_control_Load(object sender, EventArgs e)
{
com_import.Items.Clear();
com_mode.Items.Clear();
//将系统串口名依次加入下拉列表框中
foreach (string item in SerialPort.GetPortNames())
{
com_import.Items.Add(item);
}
com_mode.Items.Add("会议");
com_mode.Items.Add("讨论");
com_mode.Items.Add("展示");
timer.Start();
//判断拍照保存文件夹是否存在,若无则先创建
if (!Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + "Camera/"))
Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "Camera/");
DeviceCtrlHelper.ipCameraHelper.ImageRead += ipCameraHelper_ImageRead;
}
private void btn_reserve_Click(object sender, EventArgs e)
{
reserve = DateTime.Today.AddHours(Convert.ToInt16(txt_hour.Text));//设定预约时间
reserve = reserve.AddMinutes(Convert.ToInt16(txt_minute.Text));
reserve = reserve.AddSeconds(Convert.ToInt16(txt_second.Text));
}
void ipCameraHelper_ImageRead(ImageReadEvenArgs e)
{
ReadImage = e.img;
}
private void ChooseMode()
{
lbl_mode.Text = "智慧会议室已开启" + com_mode.Text + "模式";
switch (com_mode.Text)
{
case "会议":
pic_lightsStatus.Image = Properties.Resources.switch_on;//转换灯光图片
lamp.OnOff(true);//开启界面灯光
DeviceCtrlHelper.adam4150Helper.OnOff(1,true);//打开1通道灯
trb_curtain.Value = 0;//打开窗帘
pic_mainMicrophone.Image = Properties.Resources.switch_on;//打开主麦
pic_subMicrophone.Image = Properties.Resources.switch_off;//关闭客麦
break;
case "讨论":
pic_lightsStatus.Image = Properties.Resources.switch_on;//转换灯光图片
lamp.OnOff(true);//开启界面灯光
DeviceCtrlHelper.adam4150Helper.OnOff(1,true);//打开1通道灯
trb_curtain.Value = 0;//打开窗帘
pic_mainMicrophone.Image = Properties.Resources.switch_on;//打开主麦
pic_subMicrophone.Image = Properties.Resources.switch_on;//打开客麦
break;
case "展示":
pic_lightsStatus.Image = Properties.Resources.switch_on;//转换灯光图片
lamp.OnOff(true);//开启界面灯光
DeviceCtrlHelper.adam4150Helper.OnOff(1, true);//打开1通道灯
trb_curtain.Value = 10;//关闭窗帘
pic_mainMicrophone.Image = Properties.Resources.switch_on;//打开主麦
pic_subMicrophone.Image = Properties.Resources.switch_off;//关闭主麦
break;
}
}
private void timer_Tick(object sender, EventArgs e)
{
DeviceCtrlHelper.adam4017Helper.Open(com_import.Text);
DeviceCtrlHelper.adam4150Helper.Open(com_import.Text);
now = DateTime.Now;
lbl_time.Text = now.ToString("HH:mm:ss");//显示时间
ResModel = DeviceCtrlHelper.adam4017Helper.SetData();//采集数据
//显示采集到的数据
txt_light.Text = ResModel.lightValue;
txt_temperature.Text = ResModel.temperatureValue;
txt_humidity.Text = ResModel.humidityValue;
txt_airPressure.Text = ResModel.airPressureValue;
txt_airQuality.Text = ResModel.airQualityValue;
//模式判断
if (now >= reserve)
{
if (!IsInitialized)
{
ChooseMode();//进入选择的模式
if (chk_record.Checked)
{
DeviceCtrlHelper.ipCameraHelper.Open(txt_camera.Text, "admin", "");//初始化视频监控参数
DeviceCtrlHelper.ipCameraHelper.Start();//开启视频监控
}
IsInitialized = true;
}
if (now.Second == 0 && now.Minute % 5 == 0)//每次分钟数被5整除,秒钟数为00拍照,实现每隔5分钟拍照存储
{
if (ReadImage != null)
{
ReadImage.Save(AppDomain.CurrentDomain.BaseDirectory + "Camera/" + DateTime.Now.ToString("yyyyMMdd_HH mm ss") + ".jpg");
}
}
}
}
private void pic_lightsStatus_Click(object sender, EventArgs e)
{//电灯可以手动开关
if (IsLightsOpen)
{
lamp.OnOff(false);
pic_lightsStatus.Image = Properties.Resources.switch_off;
DeviceCtrlHelper.adam4150Helper.OnOff(1, false);//关闭1通道灯
IsLightsOpen = false;
}
else
{
lamp.OnOff(true);
pic_lightsStatus.Image = Properties.Resources.switch_on;
DeviceCtrlHelper.adam4150Helper.OnOff(1, true);//关闭1通道灯
IsLightsOpen = true;
}
}
private void pic_subMicrophone_Click(object sender, EventArgs e)
{//客麦可以手动开关
if (IssubMicrophoneOpen)
{
pic_subMicrophone.Image = Properties.Resources.switch_off;
IssubMicrophoneOpen = false;
}
else
{
pic_subMicrophone.Image = Properties.Resources.switch_on;
IssubMicrophoneOpen = true;
}
}
private void btn_exit_Click(object sender, EventArgs e)
{
timer.Stop();
reserve = DateTime.Today.AddDays(1);
chk_record.Enabled = false;
pic_lightsStatus.Image = Properties.Resources.switch_off;//转换灯光图片
lamp.OnOff(false);//关闭界面灯光
DeviceCtrlHelper.adam4150Helper.OnOff(1, false);//关闭1通道灯
trb_curtain.Value = 0;//关闭窗帘
pic_mainMicrophone.Image = Properties.Resources.switch_off;//关闭主麦
pic_subMicrophone.Image = Properties.Resources.switch_off;//关闭客麦
IsInitialized = false;//初始化状态
DeviceCtrlHelper.adam4150Helper.Close();
DeviceCtrlHelper.adam4017Helper.Close();//关闭串口
DeviceCtrlHelper.ipCameraHelper.Stop();//关闭视频监控
}
private void pic_mainMicrophone_Click(object sender, EventArgs e)
{//主麦可以手动开关
if (IsmainMicrophoneOpen)
{
pic_mainMicrophone.Image = Properties.Resources.switch_off;
IsmainMicrophoneOpen = false;
}
else
{
pic_mainMicrophone.Image = Properties.Resources.switch_on;
IsmainMicrophoneOpen = true;
}
}
}
}
+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 frm_control());
}
}
}
@@ -0,0 +1,24 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 项目资源(平台素材库)。在"项目资源"里添加或移除,不要手动修改这个文件。
// </auto-generated>
//------------------------------------------------------------------------------
namespace 会议室情景模式.Properties {
/// <summary>
/// 项目资源:Properties.Resources.资源名
/// </summary>
internal class Resources {
/// <summary>开关:开</summary>
internal static System.Drawing.Bitmap switch_on {
get { return global::Sim.Host.ProjectResources.Image("switch_on.png"); }
}
/// <summary>开关:关</summary>
internal static System.Drawing.Bitmap switch_off {
get { return global::Sim.Host.ProjectResources.Image("switch_off.png"); }
}
}
}
+23
View File
@@ -0,0 +1,23 @@
# 评分规则:书上评价表的功能项。每项单独启动一次程序,按步骤操作,核对结果。
# 预约时刻用 clock 拨实训台的虚拟时钟。格式说明见 server/src/grading/checks.ts
- title: 能实时显示环境数据
steps:
- select: { control: com_import, item: COM2 }
- board: { light: 640, temperature: 24, airQuality: 88 }
- expect: { control: txt_light, text: '640', within: 5s }
- expect: { control: txt_temperature, text: '24', within: 5s }
- expect: { control: txt_airQuality, text: '88', within: 5s }
- title: 能根据预约时间控制智能设备
steps:
- clock: '13:19:54'
- select: { control: com_import, item: COM2 }
- select: { control: com_mode, item: 讨论 }
- text: { control: txt_hour, value: '13' }
- text: { control: txt_minute, value: '20' }
- text: { control: txt_second, value: '00' }
- click: btn_reserve
- expect: { relay: 1, on: false, desc: 预约时间(13:20:00)没到时不开灯 }
- expect: { control: lbl_mode, contains: 讨论模式, within: 15s, desc: 到了预约时间开启讨论模式 }
- expect: { relay: 1, on: true, desc: 讨论模式打开灯光 }
- expect: { control: trb_curtain, value: 0, desc: 讨论模式打开窗帘 }
+4
View File
@@ -0,0 +1,4 @@
{
"title": "项目7 任务3 实现智慧会议室",
"source": "教材书 p148–153,界面和代码取自配套参考工程;补上书上漏写的填充串口列表。预约时刻:在实训台的时钟上拨时间"
}