本帖最后由 xx232 于 2020-1-9 15:48 编辑
串口通信类,根据网上找的改的
因为跨线程,需要LOOM类。发布设置里要启动.net完整版,默认的.net standard不包含创口通信。
直接挂载或者自己手动new
void Start()
{
Serial s = new Serial();
s.OnConnectMsg += S_OnConnectMsg;
s.OnGetMsg += S_OnGetMsg;
s.Setup("COM1");
//或者 s.Setup("COM1", 9600, System.IO.Ports.Parity.None, 8, System.IO.Ports.StopBits.One);
}
private void S_OnGetMsg(object sender, MsgEvent e)
{
//byte[]
Debug.Log(System.Text.Encoding.UTF8.GetString(e.Data));
}
private void S_OnConnectMsg(object sender, ConnectEvent e)
{
switch (e.State)
{
case ConnectEvent.ConnectState.Connected:
break;
case ConnectEvent.ConnectState.ConnectErr:
break;
case ConnectEvent.ConnectState.ReadErr:
break;
default:
break;
}
Debug.Log(e.Msg);
}
|
|