csharp https://gist.github.com/baobao/80ace64f7ffdf1d42ff3fe5ea8b44c6cのサンプル

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp https://gist.github.com/baobao/80ace64f7ffdf1d42ff3fe5ea8b44c6cのサンプル相关的知识,希望对你有一定的参考价值。

using UnityEngine;
using System.Collections;

public class SerialPortTest : MonoBehaviour
{
    public string PortName = "/dev/cu.usbmodem1412";
    private const int BaudRate = 115200;
    private SerialPortWrapper _serialPortWrapper;

    void OnEnable()
    {
        if (_serialPortWrapper != null)
        {
            _serialPortWrapper.KillThread();
        }
        
        _serialPortWrapper = new SerialPortWrapper(PortName, BaudRate);
        _serialPortWrapper.onMessageCallback = OnMessage;
    }
    
    void OnDisable()
    {
        if (_serialPortWrapper != null)
        {
            _serialPortWrapper.KillThread();
            _serialPortWrapper = null;
        }
    }

    void OnMessage(string msg)
    {
        if (string.IsNullOrEmpty(msg) == false)
        {
            // メッセージを受け取ったらなにかする
            Debug.Log(msg + " / " + msg.Length);
        }
    }
}

以上是关于csharp https://gist.github.com/baobao/80ace64f7ffdf1d42ff3fe5ea8b44c6cのサンプル的主要内容,如果未能解决你的问题,请参考以下文章