刚刚发现了这个线程,并认为我应该添加我的发现:随机,我也担心在 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 dosnt 似乎有什么影响。
更深入地研究它。