Skip to content

Instantly share code, notes, and snippets.

@baobao
Last active December 7, 2018 02:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baobao/ac6d0ad348f049c069f6096ef0b68e74 to your computer and use it in GitHub Desktop.
Save baobao/ac6d0ad348f049c069f6096ef0b68e74 to your computer and use it in GitHub Desktop.
using UnityEngine;
public class SerialSample : MonoBehaviour
{
private SerialPortWrapper _serialPort;
void Awake()
{
_serialPort = new SerialPortWrapper("/dev/cu.usbmodem14101", 9600);
}
private void OnDisable()
{
_serialPort.KillThread();
}
void OnGUI()
{
if (GUILayout.Button("n", GUILayout.Width(200f), GUILayout.Height(60f)))
{
// 文字列nを送信
_serialPort.Write("n");
}
if (GUILayout.Button("f", GUILayout.Width(200f), GUILayout.Height(60f)))
{
// 文字列fを送信
_serialPort.Write("f");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment