3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

unity > RS-232C > 受信が成功しない

Last updated at Posted at 2015-09-21
動作確認
Unity 5.1.3-f1 on MacOS X 10.8.5

UnityからRS-232C通信をしようとしている。
送信はできたが、受信がどうもできない。

現状、1文字の受信はできたが、それ以降の受信をしようとすると.exeで実行中のソフトが落ちる。

以下のようなものを試したが全部ダメだった。

  • コルーチン
  • スレッド
  • デリゲート

以下のサイトの方がUnityでシリアル通信をしている。ファイルもあるので、このあたりを詳しく見ていくのがいいのだろうか。
http://www.dyadica.co.uk/unity3d-serialport-script

.BytesToRead > NullReference

.BytesToRead を呼びに行ったときにNullReferenceになるようだ。

参考

2008年から直っていない不具合のようだ。 Monoで発生しているとのこと。
この理由により .BytesToReadは使えそうにない。


## やはり受信しない

(追記 2015/09/22)

その後、以下のサイトからUnityファイルを取得して、ビルドしたものをWindowsで動かしてみた。
http://www.dyadica.co.uk/unity3d-serialport-script

Unity5で開くとupgradeのメッセージが出てきたので、upgradeでプロジェクトを開いてビルドした。

PrefabをSceneに追加し、GUITextを2つ追加(comStatusとrawData用)し、SerialPort GameObjectのスクリプトに関連付けした。

COM3, 9600bpsで設定し、Windowsで動かしたのが以下の通り。

Win8x64pro.jpg

ポートはOpenできたが、COM4からCOM3への通信がまったく受信されていないようだ。設定でThreadingとCoroutineが選択できるが、どちらでも同じく受信しない。

Unity4で動いていたものがUnity5でダメになったのかもしれない。


以下に成功例を掲載した。

3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?