2
如何列出所有可用com端口到我的電腦?如何通過asp.net 4獲得C#中所有可用Com端口的列表
我已經看到了幾個與.net 1.1有關的例子,所以我在遊蕩是不是一個更現代的方式去做這件事?
我有我的SerialPort稱爲serialPort
我從MSDN網站驗證碼:
// Get a list of serial port names.
string[] ports = SerialPort.GetPortNames();
Console.WriteLine("The following serial ports were found:");
// Display each port name to the console.
foreach(string port in ports)
{
Console.WriteLine(port);
}
它給我以下錯誤: 名稱「的SerialPort」難道不是在當前背景下
存在我試過把它改成小s,然後我得到這個錯誤:
Member 'System.IO.Ports.SerialPort.GetPortNames()' cannot be accessed with an instance reference; qualify it with a type name instead
嗯,「字符串[] =端口System.IO.Ports.SerialPort。 GetPortNames();」工作正常,並找出我的「COM1」端口 –
請檢查連接串行設備到您的Web服務器的智慧。這往往需要很長的電纜。 –