界面主要是点击按钮实现控制器输入变化的监听
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace RS232Demo
{
public partial class Form1 : Form
{
SerialPort port = new SerialPort();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Thread commTh = new Thread(RunCommon);
commTh.Start();
}
private void RunCommon() {
RS232Control rs232 = new RS232Control();
rs232.Open();
while (true)
{
rs232.WriteData();
Thread.Sleep(50);
}
}
}
}
RS232工具类

该博客介绍了如何通过SerialPort类实现串口通信,特别是针对开灯关灯控制的输入输出操作。内容包括界面设计,监听按钮事件,以及RS232通信的实现细节。
最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



