文件名称:SerialPortHelper.csproj
文件大小:2KB
文件格式:CSPROJ
更新时间:2024-08-16 15:37:56
c# SerialPort 串口通信 仪器通讯
public delegate void ListenerHandler(Object sender); static void Main(string[] args) { SerialPortHelper serial = new SerialPortHelper("COM1",9600); serial.DataReceived += new DataReceivedEventHandler(dataReceived); serial.ErrorMsg += new ErrorMsgEventHandler(ErrorReceived); serial.EndByte = 0; serial.WriteData("HI"); while (true) { string ret = ""; serial.SendCommand("Send", ref ret, 100, 1000); Console.WriteLine(ret); Thread.Sleep(500); } } private static void dataReceived(string dataReceived) { Console.WriteLine("zd:" + dataReceived); } private static void ErrorReceived(object msg) { Console.WriteLine(msg.ToString()); }