脚本/功能 串口通信类 Serial port

本帖最后由 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);
    }


作者 xx232 发表于 2020-1-9 15:31:36

kuanyidairen

学习一下  看看效果!!!
发表于 2023-12-4 12:41:50
您需要登录后才可以回帖 登录 | 立即注册
xx232

关注0

粉丝5

发布5

热门作品推荐
glow
Abandoned Post Apocalyptic City Pack 适
glow
Nordic Medieval Tavern 适配UE5.1+北欧中
glow
Bones VOL.2 - Human Bones (Nanite + Low
glow
Stylized Viking Hut 适配UE5.5 风格化维京
glow
Ancient Ruins - VOL.1 (Nanite)适配UE5.1+
glow
Prismatiscape Interaction Plugin 1.04.01
glow
Stylized Greek Island II 适配UE5.5 风格
glow
Nanite Foliage - Wheat Field 适配UE5.1+
glow
AI Behavior Toolkit 1.9.0 适配UE5.5
glow
Cauldron FX VDB 适配UE5.4+魔法药水烟雾混