namespace 串口实例 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btnSend_Click(object sender, EventArgs e) { //手动发送 SendMsg(); } private void SendMsg() { this.serialPort1.Write(this.txtSend.Text); } #region 控制输入数字 private void ComboBox_TextUpdate(object sender, EventArgs e) { ComboBox cbo = sender as ComboBox; int n; if (!int.TryParse(cbo.Text, out n)) { cbo.Text = cbo.Text.Substring(0, cbo.Text.Length - 1); } else { if (n <= 0) { cbo.Text = cbo.Text.Substring(0, cbo.Text.Length - 1); } } } private void txtTime_TextChanged(object sender, EventArgs e) { TextBox text = sender as TextBox; int n; if (!int.TryParse(text.Text, out n)) { text.Text = text.Text.Substring(0, text.Text.Length - 1); } else { if (n <= 0) { text.Text = text.Text.Substring(0, text.Text.Length - 1); } else { this.timer1.Interval = n; } } } #endregion /// /// 清空显示文本框 /// /// /// private void btnClear_Click(object sender, EventArgs e) { this.txtRecive.Clear(); } private void timer1_Tick(object sender, EventArgs e) { SendMsg(); } private void cbtSend_CheckedChanged(object sender, EventArgs e) { CheckBox check = sender as CheckBox; if (check.Checked) { this.timer1.Start(); } else { this.timer1.Stop(); } } /// /// 接收返回的数据 /// /// /// private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e) { string a=""; if (this.cbkShow16.Checked) { //十六进制显示 a = this.serialPort1.ReadExisting(); } else { //字符串显示 byte[] by = new byte[this.serialPort1.BytesToRead]; this.serialPort1.Read(by, 0, this.serialPort1.BytesToRead); a = Encoding.ASCII.GetString(by); } this.txtRecive.AppendText(a); this.txtRecive.ScrollToCaret(); } private void Form1_Load(object sender, EventArgs e) { //加载 this.serialPort1.RtsEnable = true; button1_Click(this.btnOpen, null); } private void button1_Click(object sender, EventArgs e) { Button btn = sender as Button; if (btn.Text == "打开端口") { try { this.serialPort1.PortName = this.cboPortName.Text; this.serialPort1.BaudRate = Convert.ToInt32(this.cboRaudRate.Text); this.serialPort1.DataBits = Convert.ToInt32(this.cboDataBits.Text); this.serialPort1.ReceivedBytesThreshold = Convert.ToInt32(this.cboReceivedBytesThreshold.Text); this.serialPort1.Open(); btn.Text = "关闭端口"; } catch { MessageBox.Show("打开端口失败,请检查端口是否被占用."); } } else { this.serialPort1.Close(); btn.Text = "打开端口"; } } private void Form1_FormClosing(object sender, FormClosingEventArgs e) { try { this.serialPort1.Close(); } catch { } } } }
2022-05-17 15:17:21 52KB C# 串口 源码
1
mfc串口简单使用,代码包含注释
2022-05-14 20:51:11 153KB mfc c++ microsoft 开发语言
1
自动接收RFID设备发送的串口数据,其他串口设备也可以接收显示
2022-05-14 01:35:43 168KB RFID 串口,自动接收,c#
1
使用serialport类通过com串口读取ic卡数据
2022-05-14 01:15:44 48KB c# 串口读取ic卡
1
该代码是VS与串口之间通信的例子,C语言开发, 在该例子中,实现了 PC与通过串口与单片机之间的互通,供初学者参考
2022-05-13 17:41:30 339KB 串口 VS PC C++
1
Visual C++串口通信工程开发实例导航源代码: 第1章 串口实现双机互联 第2章 串口编程调试精灵 第3章 云台镜头控制系统 第4章 PC与PDA数据交互系统 第5章 GPS数据采集程序 第6章 楼宇自控系统 第7章 智能安防报警系统 第8章 语音自动应答系统
2022-05-13 13:48:47 3.83MB Visual C++ 串口编程
1
起因:学校运河杯报了个项目,制作一个天气预测的装置。我用arduino跑了BME280模块,用蓝牙模块实现两块arduino主从机透传。但是为了分析,还需要提取出数据。因此我用python写了个上位机程序,用pyserial模块实现arduiho和电脑的串口通讯,再用xlwt模块写入excel表格,用time模块获取时间作为excel的文件名。 import xlwt import time import serial #设置表格样式 def set_style(name,height,bold=False): style = xlwt.XFStyle() font = xlwt.Fon
2022-05-12 21:47:19 88KB arduino c ce
1
Qt6.2搭配QtDS,采用QML作为UI界面,C++与QML交互处理逻辑,开发的多功能串口助手,供学习使用
2022-05-12 09:08:04 80.16MB ui 串口通信 学习 QML
1
文件内为C#串口程序以及VS2019的工程文件,需要自己制作串口程序的,可以从我这里下载文件,然后使用VS进行修改,该串口程序以及将串口的所有设置进行了配置,使用者可以根据自己需要增减修改。
2022-05-11 22:58:22 837KB C#串口程序
1
工作中用到的一个串口通讯封装类,并在该封装基础上针对实时监控进一步封装,绝对比VS2005的串口控件要好用.直接上传源码
2022-05-11 16:38:40 7KB 串口 通讯 封装 C#
1