- 虚拟时钟:实训台时钟面板可拨时间、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>
127 lines
4.6 KiB
C#
127 lines
4.6 KiB
C#
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通道灯
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|