0

目前,我有一个在嵌入式 Windows 7 上运行的简单工作 Windows 窗体应用程序,它与扫描仪进行串行通信。我希望切换到 Windows 10 物联网平台并能够在 Windows 10 物联网企业版(内部版本 14393)上运行相同的应用程序。当我尝试在 Windows 10 ioT 上运行相同的应用程序时,只要我尝试打开串行端口开始通信,电脑就会挂断。但是,我可以使用 USB 到 RS-232 电缆建立串行通信,而不是使用 PC 上的 COM 端口使用相同的 win 表单应用程序。

此外,尝试在此处运行示例 UWP 串行应用程序,它仍然没有检测到任何通过 RS-232 连接的扫描仪,但能够将 USB 连接到 RS-232 设备。

Windows 10 iot 不支持 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;
        }  
4

0 回答 0