使用c#提供的serialport类操作串口,串口的配置和回调函数的声明定义如下:
private SerialPort _EPL1023DAObj
_EPL1023DAObj.PortName = EPL1023DA_SerialPortNameCombox.Text;
_EPL1023DAObj.BaudRate = int.Parse(EPL1023DA_SerialPortBaudRateCombox.Text);
_EPL1023DAObj.DataBits = int.Parse(EPL1023DA_SerialPortDataBitCombox.Text);
switch (EPL1023DA_SerialPortStopBitCombox.SelectedIndex)
{
case 0:
_EPL1023DAObj.StopBits = StopBits.One;
break;
case 1:
_EPL1023DAObj.StopBits = StopBits.OnePointFive;
break;
case 2:
_EPL1023DAObj.StopBits = StopBits.Two;
break;
}
_EPL1023DAObj.Encoding = Encoding.GetEncoding("UTF-8");
_EPL1023DAObj.DataReceived += _EPL1023DASession_DataReceived;
private void _EPL1023DASession_DataReceived(object sender,