1

Currently I have a simple working windows form application running on windows 7 embedded that talks serially with a scanner. I wish to switch over to windows 10 ioT platform and be able to run the same application on windows 10 ioT enterprise (Build version 14393 ). As I tried running the same application on windows 10 ioT, the pc hangs up as soon as I try to open a serial port to start communication. However I am able to establish serial communication using a USB to RS-232 cable instead of using a COM Port on the PC using the same win form application.

Further, a tried running a sample UWP serial application here , which still did not detect any scanners connected over RS-232 but was able to connect a USB to RS-232 device.

Is RS-232 communication not supported on windows 10 iot ? Is there anything that I am missing ?

Here is the code snippet used to open ports (Note: Serial parameters for the COM Port are populated to the structure from an xml file):

            //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;
        }  
pum1115
  • 67
  • 6
  • Windows 10 handles RS-232 communication the same as Windows 7. My guess is you have it setup correctly on your Windows 7 machines and something isn't setup correctly on the Windows 10 machines. You can add a `Try` `Catch` block around your serialport.Open() command and see what specific error is being thrown. (`MessageBox.Show(e.message);`) The Serial port COM # most likely won't be the same. The port hanging up suggests you are opening the wrong COM port. Make sure you are opening the right COM port. Check your device manager. – Baddack Jun 04 '18 at 20:01
  • Agree with @Baddack - I've had no trouble with RS-232 communication coming from Win7 to Win10. Post the code where you are opening COM ports and maybe then we can identify the problem. – jaredbaszler Jun 05 '18 at 13:54
  • Thank you for your response. I do have a try catch around serialport.Open() and I don't see any exceptions. The windows 10 PC just hangs up as it executes serialport.Open(). Now if I unplug the RS232 cable while its hung up, it returns back its normal operation. – pum1115 Jun 05 '18 at 13:58
  • What are your timeouts set to? Could it be timing out? – Baddack Jun 05 '18 at 22:04
  • @ppatel I test with [System.IO.Ports.SerialPort sample](https://msdn.microsoft.com/en-us/library/system.io.ports.serialport(v=vs.110).aspx#Examples) in a console app on Windows 10 Desktop, it works. Can you test that sample on your Windows 10 IoT Enterprise device? BTW, the Windows.Devices.SerialCommunication used in UWP only support [Serial-to-USB adapters and internal USB to serial bridge chips](https://learn.microsoft.com/en-us/uwp/api/Windows.Devices.SerialCommunication). – Rita Han Jun 06 '18 at 05:42
  • @Baddack Tiemouts are set to 1 sec. I tried to increase it further to 5 sec but no change. – pum1115 Jun 06 '18 at 20:41
  • @RitaHan-MSFT I tried the sample app too on win 10 iot and it doesn't work either – pum1115 Jun 06 '18 at 20:43
  • Try running it as an administrator. – Baddack Jun 06 '18 at 22:25
  • @Baddack Yes I have tried running it as an administrator too but no difference. Also I have tried many other serial communication apps that have been working on windows 7 absolutely fine but doesn't work on windows 10. An app as simple as just opening a port and reading incoming data doesn't work either. For all the apps it hangs at serialport.Open() on win 10. – pum1115 Jun 07 '18 at 12:46
  • @ppatel AFAIK, the Windows 10 IoT Enterprise 2016 LTSB should support RS-232. Did you test the sample code on the same computer with different OS? – Fei Xue Jun 08 '18 at 01:05
  • @ppatel Would you minding also sharing the hardware specification and driver information? – Fei Xue Jun 11 '18 at 00:33

0 Answers0