This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment