asp.net 窗口应用 serialPort DataReceived 无法触发问题 虚拟串口可以读写 实际的不可以触发
privatevoidForm1_Load(objectsender,EventArgse){comboBox1.Items.AddRange(System.IO.Por...
private void Form1_Load(object sender, EventArgs e)
{
comboBox1.Items.AddRange(System.IO.Ports.SerialPort.GetPortNames());
port1 = new System.IO.Ports.SerialPort("COM3");
port1.BaudRate = 9600;//波特率
port1.Parity = Parity.None;//无奇偶校验位
port1.StopBits = StopBits.One;//两个停止位
port1.DataBits = 8;
port1.ReceivedBytesThreshold = 1;
port1.DtrEnable = true;
port1.RtsEnable = true;
port1.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(port1_DataReceived);
port1.Open();
}
private void port1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
MessageBox.Show("COM3数据返回!", "系统提示");
}
private void button4_Click(object sender, EventArgs e)
{
byte[] crcbuf = new Byte[] { 01, 03, 00, 08, 00, 02, 45, (byte)0xc9 };
port1.Write(crcbuf, 0, crcbuf.Length);
} 展开
{
comboBox1.Items.AddRange(System.IO.Ports.SerialPort.GetPortNames());
port1 = new System.IO.Ports.SerialPort("COM3");
port1.BaudRate = 9600;//波特率
port1.Parity = Parity.None;//无奇偶校验位
port1.StopBits = StopBits.One;//两个停止位
port1.DataBits = 8;
port1.ReceivedBytesThreshold = 1;
port1.DtrEnable = true;
port1.RtsEnable = true;
port1.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(port1_DataReceived);
port1.Open();
}
private void port1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
MessageBox.Show("COM3数据返回!", "系统提示");
}
private void button4_Click(object sender, EventArgs e)
{
byte[] crcbuf = new Byte[] { 01, 03, 00, 08, 00, 02, 45, (byte)0xc9 };
port1.Write(crcbuf, 0, crcbuf.Length);
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询