I am C# programmer and using VS 2022, with .NET Framework is no problem using System.IO.Ports.SerialPort
in order to use .GetPortNames()
for collect available serial port list.
for example;
ComboBox CMS = new ComboBox();
string[] comlist = System.IO.SerialPort.GetPortNames();
CMS.Items.Clear();
//ComboBox item add if serial port is exist
if (comlist.Length > 0) CMS.Items.AddRange(comlist);
However, this code is not working on .NET 6.0.
System.IO
is exist but .Ports
does not. So Ports.SerialPort... all removed.
How can I get Serial Ports list with .NET 6.0? I've searched and google a lot but can't find solution.
Try adding the System.IO.Ports
NuGet package:
<PackageReference Include="System.IO.Ports" Version="7.0.0" />
Also note that the fully qualified name is System.IO.Ports.SerialPort
, not System.IO.SerialPort