C#WinForm串口调试工具源码功能引见:运行本程序,在“发送数据”文本框中输入要传送的数据,单击【发送】按钮,将传送的数据发送到所选择的端口号中主要代码:privatevoidbtnOpenPort_Click(objectsender,EventArgse){if(!openState){openState=true;//已经打开btnOpenPort.Text="关闭串口";this.pictureBox.Image=global::SerialDemo.Properties.Resources.btnOk2;strPortName=cmbPort.Text;strBaudRate=cmbBaudRate.Text;strDataBits=cmbDataBits.Text;strStopBits=cmbStopBit.Text;sp.PortName=strPortName;sp.BaudRate=int.Parse(strBaudRate);sp.DataBits=int.Parse(strDataBits);sp.StopBits=(StopBits)int.Parse(strStopBits);sp.ReadTimeout=500;//打开sp.Open();sp.DataReceived+=newSerialDataReceivedEventHandler(sp_DataReceived);}else{openState=false;btnOpenPort.Text="打开串口";this.pictureBox.Image=global::SerialDemo.Properties.Resources.can1;sp.DataReceived-=newSerialDataReceivedEventHandler(sp_DataReceived);sp.Close();}}
1