LoginSignup
0
1

More than 5 years have passed since last update.

unity > RS-232C > COMポートのリストアップ

Last updated at Posted at 2015-09-27
実装
Unity 5.1.3-f1 on MacOS X 10.8.5

その端末にどういうCOMポートが利用可能かのリストアップ

MainCameraScript.cs
using UnityEngine;
using System.Collections;
using System.IO.Ports;
using UnityEngine.UI;

public class MCscript : MonoBehaviour {

    public Text T_out;
    string s_outtext = "";

    void listAllPorts() {
        string [] ports = SerialPort.GetPortNames ();

        s_outtext = "";
        foreach (string port in ports) {
            s_outtext = s_outtext + System.Environment.NewLine + port;
            Debug.Log (port);
        }
    }

    void Start () {
        listAllPorts ();
    }

    void Update() {
        T_out.text = s_outtext;
    }

}

上記においてT_out.textへの出力をlistAllPorts()だけで実行するとWindows7実行時に画面に表示されなかった。
Update()内にテキスト出力を追加すると表示されるようになった。

Window7にて実行すると以下のようになった。

listcoms.jpg

COM5はUSBシリアルケーブルで追加したポート。

androidスマホでUSBシリアルケーブルを挿した時にCOMポートの表示がされるかの確認はUSBホストケーブルが届いてから。



(追記 2015/10/01)
USBホストケーブルが届いたのでandroidスマホ (304SH) にUSBシリアルケーブルを挿してみた。COMポートリストアッププログラムを実行しても何も表示されなかった。

USBシリアルケーブルには電源が行っている(LEDが点灯)しているが、他に何か設定しないといけないのだろうか。

一応、304SHはUSBホスト機能には対応しているようではある。

0
1
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
0
1