我有 vs 2012,我想要 2 获取计算机的所有串行端口,为此我编写了代码
// com = AutomationFactory.CreateObject("ComInterOp_SeeLevel828_Utility");
com = AutomationFactory.GetObject("InteropComObjects.IO.Ports.SerialPort");
dynamic count = com.GetDeviceCount();
StringBuilder sb = new StringBuilder();
List<dynamic> devices = new List<dynamic>();
for (int i = 1; i <= 9; i++)
{
devices.Add("COM" + i);
}
for (int i = 0; i < count; i++)
{
devices.Add(com.GetDevice(i));
}
cmdSerial.ItemsSource = devices;
但我在这条线上遇到了错误
com = AutomationFactory.GetObject("InteropComObjects.IO.Ports.SerialPort");
因为没有找到为指定 ProgID 注册的对象。