目前我有一个简单的工作窗体应用程序在Windows 7嵌入式上运行,与扫描仪串行对话。我希望切换到Windows 10 ioT平台,并能够在Windows 10 ioT企业版(Build版本14393)上运行相同的应用程序。当我尝试在Windows 10 ioT上运行相同的应用程序时,一旦我尝试打开串口开始通信,电脑就会挂断。但是,我可以使用USB转RS-232电缆建立串行通信,而不是使用相同的win form应用程序在PC上使用COM端口。
此外,尝试运行示例UWP串行应用程序here,它仍然没有检测到通过RS-232连接但是能够将USB连接到RS-232设备的任何扫描仪。
Windows 10上是否不支持RS-232通信?有什么我想念的吗?
以下是用于打开端口的代码段 (注意:COM端口的串行参数将填充到xml文件中的结构中):
//Structures
public struct SerialPortConfig
{
public string COMPortNumber { get; set; }
public string BaudRate { get; set; }
public string DataBits { get; set; }
public string Parity { get; set; }
public string StopBits { get; set; }
public string FlowControl { get; set; }
public string StringLength { get; set; }
public int CommInterval { get; set; }
public int TimeOut { get; set; }
public string TermChar { get; set; }
public string[] StartChar { get; set; }
public string Handshaking { get; set; }
public int ReadBufferSize { get; set; }
public int WriteBufferSize { get; set; }
public bool DTREnable { get; set; }
}
public SerialCommDriver(SerialPortConfig serialPortConfig)
{
COMPort = new SerialPort();
COMPort.PortName = "COM" + serialPortConfig.COMPortNumber;
COMPort.BaudRate = Convert.ToInt16(serialPortConfig.BaudRate);
COMPort.DataBits = Convert.ToInt16(serialPortConfig.DataBits);
if (serialPortConfig.Parity == "Odd")
COMPort.Parity = Parity.Odd;
else if (serialPortConfig.Parity == "Even")
COMPort.Parity = Parity.Even;
else if (serialPortConfig.Parity == "None")
COMPort.Parity = Parity.None;
else if (serialPortConfig.Parity == "Mark")
COMPort.Parity = Parity.Mark;
else if (serialPortConfig.Parity == "Space")
COMPort.Parity = Parity.Space;
if (serialPortConfig.StopBits == "1")
COMPort.StopBits = StopBits.One;
else if (serialPortConfig.StopBits == "1.5")
COMPort.StopBits = StopBits.OnePointFive;
else if (serialPortConfig.StopBits == "2")
COMPort.StopBits = StopBits.Two;
else if (serialPortConfig.StopBits == "None")
COMPort.StopBits = StopBits.None;
COMPort.ReadTimeout = serialPortConfig.TimeOut;
COMPort.NewLine = serialPortConfig.TermChar;
}
//End of Structures
private static SerialCommDriver.SerialPortConfig _SerialPortAConfig;
////Get COM port configuration from xml file
XmlNode node3 = document.SelectSingleNode("/LPN/ConfigScannerCOMPort");
_SerialPortAConfig.COMPortNumber =
node3.SelectSingleNode("COMPort").InnerText;
_SerialPortAConfig.BaudRate =
node3.SelectSingleNode("BaudRate").InnerText;
................................
................................
................................
_SerialPortA = new SerialCommDriver(_SerialPortAConfig);
//***********Subscribe to COM port events.
_SerialPortA.COMPort.DataReceived +=
SerialPortA_NewDataReceived;
public static void Start()
{
.........
.........
//Open COM ports.
try
{
_SerialPortA.OpenPort();
Debug_Log("Port from scanner (" +
_SerialPortA.COMPort.PortName + ") is open!",
_RunningAsService);
}
catch (Exception e)
{
Debug_Log("Unable to open required COM port(s). " +
e.ToString() + "", _RunningAsService);
Exit(_RunningAsService);
}
.......
.......
}
public bool OpenPort()
{
if (!COMPort.IsOpen)
COMPort.Open();
return COMPort.IsOpen;
}