SerialPort.GetPortNames メソッド
アセンブリ: System (system.dll 内)



GetPortNames によって返されるポート名の順序が指定されていません。
GetPortNames メソッドを使用して、有効なシリアル ポート名のリストを現在のコンピュータに照会します。たとえば、このメソッドを使用して、COM1 と COM2 が現在のコンピュータの有効なシリアル ポートかどうかを確認できます。
Windows 98 環境では、ポート名はシステム レジストリ (HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM) から取得されます。レジストリ内のデータが古い、または誤っている場合、GetPortNames メソッドは不正なデータを返します。

GetPortNames メソッドを使用して、コンソールにシリアル ポート名を表示するコード例を次に示します。
Imports System Imports System.IO.Ports Module SerialPortExample Sub Main() ' Get a list of serial port names. Dim ports As String() = SerialPort.GetPortNames() Console.WriteLine("The following serial ports were found:") ' Display each port name to the console. Dim port As String For Each port In ports Console.WriteLine(port) Next port Console.ReadLine() End Sub End Module
using System; using System.IO.Ports; namespace SerialPortExample { class SerialPortExample { public static void Main() { // 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); } Console.ReadLine(); } } }
#using <System.dll> using namespace System; using namespace System::IO::Ports; using namespace System::ComponentModel; void main() { array<String^>^ serialPorts = nullptr; try { // Get a list of serial port names. serialPorts = SerialPort::GetPortNames(); } catch (Win32Exception^ ex) { Console::WriteLine(ex->Message); } Console::WriteLine("The following serial ports were found:"); // Display each port name to the console. for each(String^ port in serialPorts) { Console::WriteLine(port); } }

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からSerialPort.GetPortNames メソッドを検索する場合は、下記のリンクをクリックしてください。

- SerialPort.GetPortNames メソッドのページへのリンク