前提
UnityとM5stackのBluetoothシリアル通信をしたいが、Unity側の
「System.IO.Ports is currently only supported on Windows」というエラーが解消できない
実現したいこと
- M5stackからシリアル通信でデータを送る
- 送信したデータをUnity側で受け取る
参考にしたサイト
- https://qiita.com/ZeniZeni/items/1d0e545259fbcd9381c8
- https://nn-hokuson.hatenablog.com/entry/2017/09/12/192024
上記サイトのサンプルコード通りに制作中、Arduino部分の制作は出来たが、Unity側からエラーが発生したため、次のサイトを参考にしました
Unityのバージョン
- Unity 2021.3.7f1
- Arduino 1.8.19
プログラム
public string portName; public int baurate; SerialPort serial; bool isLoop = true; void Start() { this.serial = new SerialPort(portName, baurate, Parity.None, 8, StopBits.One); try { this.serial.Open(); Scheduler.ThreadPool.Schedule(() => ReadData()).AddTo(this); } catch (Exception e) { Debug.Log("can not open serial port"); } } public void ReadData() { while (this.isLoop) { string message = this.serial.ReadLine(); Debug.Log(message); } } void OnDestroy() { this.isLoop = false; this.serial.Close(); }}
発生している問題・エラーメッセージ
Unityのプログラムが動作せず、エラーが発生しています
エラーメッセージ
PlatformNotSupportedException: System.IO.Ports is currently only supported on Windows.
試したこと
- ソース元のサイト通りのコード制作
- プロジェクトのプラットフォームをUWP(Universal Windows Platform)に変更
- プロジェクトごと作り直し、プラットフォーム変更

回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。