このスレッドを発見したばかりで、自分の発見を追加するしかないと思いました。ランダムに、Mac でもこれについて心配しています。Windows と Linux (VS と Mono の両方) では、SerialPort.GetPortNames() は次のルールでリストを返します。
1) Windows は Com1、Com4 などの文字列のリストを返しますが、存在しないものはすべて欠落しています (USB シリアル アダプタは、接続されているプラグに基づいて常に COM 番号を取得しているようです)。私のシリアル ポート スキャナから:
Scanning COM1
Scanning COM4
Scanning Complete
2) Linux は、Linux ディストリビューションのコンパイラが有効にした可能性のあるすべての tty シリアル ポートを返します。これは約8つのポートのようで、開こうとすると例外がスローされます(私のシリアルポートスキャナーから:
Scanning /dev/ttyS0
Scanning /dev/ttyS1 Port FailedSystem.IO.IOException: I/O Error
at System.IO.Ports.SerialPortStream..ctor (System.String portName, Int32 baudRate, Int32 dataBits, Parity parity, StopBits stopBits, Boolean dtrEnable, Boolean rtsEnable, Handshake handshake, Int32 readTimeout, Int32 writeTimeout, Int32 readBufferSize, Int32 writeBufferSize) [0x00000]
at (wrapper remoting-invoke-with-check) System.IO.Ports.SerialPortStream:.ctor (string,int,int,System.IO.Ports.Parity,System.IO.Ports.StopBits,bool,bool,System.IO.Ports.Handshake,int,int,int,int)
at System.IO.Ports.SerialPort.Open () [0x00000]
at (wrapper remoting-invoke-with-check) System.IO.Ports.SerialPort:Open ()
at HSMScanner.Program.Main (System.String[] args) [0x00000]
Scanning /dev/ttyS2 Port FailedSystem.IO.IOException: I/O Error
at System.IO.Ports.SerialPortStream..ctor (System.String portName, Int32 baudRate, Int32 dataBits, Parity parity, StopBits stopBits, Boolean dtrEnable, Boolean rtsEnable, Handshake handshake, Int32 readTimeout, Int32 writeTimeout, Int32 readBufferSize, Int32 writeBufferSize) [0x00000]
at (wrapper remoting-invoke-with-check) System.IO.Ports.SerialPortStream:.ctor (string,int,int,System.IO.Ports.Parity,System.IO.Ports.StopBits,bool,bool,System.IO.Ports.Handshake,int,int,int,int)
at System.IO.Ports.SerialPort.Open () [0x00000]
at (wrapper remoting-invoke-with-check) System.IO.Ports.SerialPort:Open ()
at HSMScanner.Program.Main (System.String[] args) [0x00000]
Scanning /dev/ttyS3 Port FailedSystem.IO.IOException: I/O Error
at System.IO.Ports.SerialPortStream..ctor (System.String portName, Int32 baudRate, Int32 dataBits, Parity parity, StopBits stopBits, Boolean dtrEnable, Boolean rtsEnable, Handshake handshake, Int32 readTimeout, Int32 writeTimeout, Int32 readBufferSize, Int32 writeBufferSize) [0x00000]
at (wrapper remoting-invoke-with-check) System.IO.Ports.SerialPortStream:.ctor (string,int,int,System.IO.Ports.Parity,System.IO.Ports.StopBits,bool,bool,System.IO.Ports.Handshake,int,int,int,int)
at System.IO.Ports.SerialPort.Open () [0x00000]
at (wrapper remoting-invoke-with-check) System.IO.Ports.SerialPort:Open ()
at HSMScanner.Program.Main (System.String[] args) [0x00000]
3) マック...
ああ、ああ、ああ。Mac (USB シリアル ポートが接続され、ドライバーとすべてが正常な場合) は、GetPortNames() で何も返しません。なだ。/dev/tty を見ると、デバイスが接続されている場合にのみ追加のデバイスが表示され、残念ながら /dev/tty.usbserial-A7006Ro7 のような名前が付けられています。この名前をプログラムへの引数として使用し、その後に serial.open が続くようには見えません。効果があります。
もっと調べてみます。