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
VC串口编程例程 并有一个基于MSCOMM控件的实例程序 适合初学者
2022-05-06 14:08:40 4.07MB VC 串口 实例 控件
1
VC++串口编程实例源代码 代码主要包括以下8章: 第1章 串口实现双机互联 第2章 串口编程调试精灵 第3章 云台镜头控制系统 第4章 PC与PDA数据交互系统 第5章 GPS数据采集程序 第6章 楼宇自控系统 第7章 智能安防报警系统 第8章 语音自动应答系统
2022-04-04 15:10:58 3.45MB VC++ 串口 实例 编程
1
Qt5 串口通信
2022-03-10 00:32:32 34KB Qt5 串口
1
网上淘的几个串口实例 还不错 可以看看
2022-02-20 19:28:34 207KB labview 串口实例
1
Visual Basic串口通信及编程实例
2022-01-02 19:57:51 9.93MB VB串口 实例
1
OMRON串口通讯实例
2021-10-13 16:01:58 1.64MB OMRON 串口通信 串口 实例
1
Android 连接多个通用USB转串口实例, 实现多串口的发送与接收 参考:https://github.com/mik3y/usb-serial-for-android
2021-09-01 17:19:45 2.76MB USB转串
1
linux串编程实例源码,实现串口的基本配置和通过配置文件修改串口配置,在工程中稍微修改即可使用,去掉重复工作代码.
2021-07-24 15:41:10 3KB linux 串口实例
1
PIC12F1822的UART功能配置,保证可用
2021-07-19 17:19:43 89KB pic 12f1822 串口 1822
1