欢迎来到天天文库
浏览记录
ID:42623486
大小:16.85 KB
页数:11页
时间:2019-09-19
《c# winform 串口调试助手》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、c#winform串口调试助手已调试通过,可以收发数据usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;usingSystem.IO.Ports;namespaceCGF串?口ú助ú手?{publicpartialclassCgfForm1:For
2、m{publicCgfForm1(){InitializeComponent();COMNUM.SelectedIndex=2;BaudRate.SelectedIndex=3;DataBit.SelectedIndex=3;StopBit.SelectedIndex=1;CheckBit.SelectedIndex=0;CharDisp.Checked=true;SendChar.Checked=true;CloseComm.Enabled=false;DataSend.Enabled=false;}privatevoidlabel7_Click(objectsender,Even
3、tArgse){}privatevoidOpenComm_Click(objectsender,EventArgse){serialPort1.Close();serialPort1.PortName=COMNUM.Text;serialPort1.BaudRate=Convert.ToInt32(BaudRate.Text);serialPort1.DataBits=Convert.ToInt32(DataBit.Text);intSPnum=4;SPnum=StopBit.SelectedIndex;switch(SPnum){case0:serialPort1.StopBits
4、=StopBits.None;break;case1:serialPort1.StopBits=StopBits.One;break;case2:serialPort1.StopBits=StopBits.OnePointFive;break;case3:serialPort1.StopBits=StopBits.Two;break;default:break;}SPnum=CheckBit.SelectedIndex;switch(SPnum){case0:serialPort1.Parity=Parity.None;break;case1:serialPort1.Parity=P
5、arity.Odd;break;case2:serialPort1.Parity=Parity.Even;break;default:break;}/***************异皑?常£处鋦理え?!?****************/try{serialPort1.Open();}catch(Exceptionex){MessageBox.Show("错洙?误ó:阰"+ex.Message);}/*****************************************/if(serialPort1.IsOpen){CloseComm.Enabled=true;DataS
6、end.Enabled=true;OpenComm.Enabled=false;COMNUM.Enabled=false;BaudRate.Enabled=false;DataBit.Enabled=false;StopBit.Enabled=false;CheckBit.Enabled=false;}}privatevoidCloseComm_Click(objectsender,EventArgse){try{serialPort1.Close();CloseComm.Enabled=false;DataSend.Enabled=false;OpenComm.Enabled=tr
7、ue;COMNUM.Enabled=true;BaudRate.Enabled=true;DataBit.Enabled=true;StopBit.Enabled=true;CheckBit.Enabled=true;}catch(Exceptionex){MessageBox.Show("错洙?误ó:阰"+ex.Message);CloseComm.Enabled=true;DataSend.Enabled=true;OpenComm.Enabled=f
此文档下载收益归作者所有