Files
IOT_SIM/samples/p2-t1-LED显示屏/Form1.cs
T
xuyueandClaude Opus 5.5 98be8331bc 第 0 阶段:教材项目 2 任务 1 在网页中原样运行
- runtime:仿真 WinForms 子集(Form、Button、Label、TextBox、ComboBox、
  GroupBox、Timer、MessageBox、界面线程消息循环、跨线程检查)、
  教材设备类库(DeviceCtrlHelper、LED 控件)、运行器(常驻编译服务 + 运行模式)
- server:Bun + Hono,WebSocket 会话,每次运行一个进程,消息转发
- web:Vue + Naive UI,WinForms 风格窗体渲染、MessageBox、实训台 LED 屏
- 端到端测试与 100 个程序并发的压力测试
- 教材逐任务摘要(docs/教材摘要)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 10:15:14 +08:00

56 lines
1.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;//调用系统串口资源类所在的命名空间
using DeviceCtrlLibrary;//调用外部设备控制资源类所在的命名空间
using WinFormsDeviceControlLibrary;//引用外部窗体类所在的命名空间
namespace LED显示屏
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btn_Open_Click(object sender, EventArgs e)
{
//在com_Port下拉列表中选中的项,作为当前串口
DeviceCtrlHelper.ledHelper.OpenLedCom(com_Port.Text);
}
private void btn_Send_Click(object sender, EventArgs e)
{
// 读txt_SendText控件的内容,保存在字符串变量res中
string res = DeviceCtrlHelper.ledHelper.SendLedString(txt_SendText.Text);
//判断字符串res是否为空
if (res.IndexOf("Error") >= 0)
{
MessageBox.Show(res); //出错提示
}
else
{
led.setLedText(res);//发送
}
}
private void com_Port_Click(object sender, EventArgs e)
{
//清空列表
com_Port.Items.Clear();
//加载所有可用的串口号到列表中
foreach (string item in SerialPort.GetPortNames())
{
com_Port.Items.Add(item);
}
}
}
}