title: Problems with serial device communication in UWP
body: <p>I have a peculiar problem.</p>
  <p>I am trying to communicate with a peripheral unit that requires serial communication in a UWP project. I am using <code>Windows.Devices.SerialCommunication</code>.</p>
  <p>For purpose of demonstration, I made a new page that has two buttons, with two different click handlers. One for opening the port, and the other for sending messages to the peripheral.</p>
  <p>One handler is:</p>
  <pre><code>    SerialDevice device;
      
      private async void Button_Click_1(object sender, RoutedEventArgs e)
      {
           string selector = SerialDevice.GetDeviceSelector(&quot;COM7&quot;);
           DeviceInformationCollection devices = await DeviceInformation.FindAllAsync(selector);
               if (devices.Any())
               {
                   DeviceInformation deviceInfo = devices.First();
                   device = await SerialDevice.FromIdAsync(deviceInfo.Id);
                   //*********************
                   device.BaudRate = 9600;
                   device.DataBits = 8;
                   device.Parity = SerialParity.None;
                   device.StopBits = SerialStopBitCount.One;
                   device.ReadTimeout = device.WriteTimeout = TimeSpan.FromMilliseconds(1000);
                   device.Handshake = SerialHandshake.None;
               }
               _dataReader = new DataReader(device.InputStream);
               _dataWriter = new DataWriter(device.OutputStream);
      }
  </code></pre>
  <p>Peripheral has a red light on it when I enable the power supply. When the line above <code>//*********</code> is executed, the light is switched off. The peripheral doesn't respond to any messages then. When I stop the program, the light switches back on.</p>
  <p>I made a .NET Framework app that works perfectly. It is fully functional. I used <code>System.IO.Ports</code> there. I noticed something:</p>
  <p>If I extract and run only this part of the code in .NET Framework app:</p>
  <pre><code>SerialPort comPort = new SerialPort();            
  _ComPort.PortName = PortName;
  _ComPort.BaudRate = BaudRate;
  _ComPort.DataBits = 8;
  _ComPort.Parity = Parity.None;
  _ComPort.StopBits = StopBits.One;
  _ComPort.DataReceived += new SerialDataReceivedEventHandler(_ComPort_DataReceived);
  _ComPort.Open();
  </code></pre>
  <p>Nothing more.</p>
  <p>And run the UWP app again, the port opens perfectly, the lamp is red, and the device responds to messages. I can switch off the device, and initialize it from the UWP app as many times as I want to. When I restart my computer, I can't initialize the device from the UWP app again, (until I run the said block of code from .NET Framework app).</p>
  <p>If you want to know, the peripheral is Bill to Bill unit made by Suzo Happ.</p>
  <p>I didn't make any mistakes regarding property initialization in UWP.</p>