欢迎来到天天文库
浏览记录
ID:57536581
大小:542.30 KB
页数:14页
时间:2020-08-27
《串口调试助手源代码.pdf》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、精品文档串口调试助手预源代码usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;usingSystem.IO;usingSystem.IO.Ports;usingSystem
2、.Threading;usingDevExpress.XtraEditors;usingSystem.Text.RegularExpressions;namespaceWindowsFormsApplication3{publicpartialclassForm1:XtraForm{SerialPortsp1=newSerialPort();intFlag=0;intStateChanged=0;1欢迎下载。精品文档intStateChanged_Ascii=1;intStateChanged_16=0;st
3、ringTemp=null;stringTemp_memoSend=null;privatevoidmemoSend_EditValueChanged(objectsender,EventArgse){}publicForm1(){InitializeComponent();sp1.DataReceived+=sp1_DataReceived;}privatevoidForm1_Load(objectsender,EventArgse){this.MaximizeBox=false;//检查是否有串口stri
4、ng[]str=SerialPort.GetPortNames();if(str==null){MessageBox.Show("本机没有串口!","error");return;}//添加串口项目foreach(stringportinSystem.IO.Ports.SerialPort.GetPortNames()){cbSerial.Properties.Items.Add(port);}//串口设置默认选择项cbSerial.SelectedIndex=0;Control.CheckForIllega
5、lCrossThreadCalls=false;sp1.DataReceived+=newSerialDataReceivedEventHandler(sp1_DataReceived);//订阅委托}privatevoidcomboBoxEdit1_SelectedIndexChanged(objectsender,EventArgs2欢迎下载。精品文档e){}privatevoidOpenSerial_Click(objectsender,EventArgse){sp1.Close();//SerialP
6、ortsp1=newSerialPort();if(!sp1.IsOpen)//串口是关闭的,设置参数,打开串口{try{//获取串口号stringserialName=cbSerial.SelectedItem.ToString();sp1.PortName=serialName;//设置各参数stringstrBaudRate=cbBaudRate.Text;stringstrDateBits=cbDataBits.Text;stringstrStopBits=cbStop.Text;sp1.BaudRa
7、te=Convert.ToInt32(strBaudRate);//波特率sp1.DataBits=Convert.ToInt32(strDateBits);//数据位switch(cbStop.Text)//停止位{case"1":sp1.StopBits=StopBits.One;break;case"1.5":sp1.StopBits=StopBits.One;break;case"2":sp1.StopBits=StopBits.Two;break;default:MessageBox.Show("E
8、rror:参数不正确!","Error");break;}switch(cbParity.Text)//校验位{case"无":sp1.Parity=Parity.None;break;case"奇校验":sp1.Parity=Parity.Odd;break;3欢迎下载。精品文档case"偶校验":sp1.Parity=Parity.Even;break;default:MessageBox.Sh
此文档下载收益归作者所有