Skip to content
This repository has been archived by the owner on Jan 30, 2019. It is now read-only.

SerialUART: Unable to change StopBits to "SerialStopBitCount.Two" #515

Open
ArthurOliveiraBR opened this issue Aug 24, 2017 · 1 comment

Comments

@ArthurOliveiraBR
Copy link

Hi folks,

I've tried to modify the "SerialSample" to use two stop bits instead of the default configuration in a RaspberryPI 3 Model B and any value different from "SerialStopBitCount.One" throws an exception as below:

'serialPort.StopBits = SerialStopBitCount.Two' threw an exception of type 'System.ArgumentException' Data: {System.Collections.ListDictionaryInternal} HResult: -2147024809 HelpLink: null InnerException: null Message: "Value does not fall within the expected range." ParamName: null Source: "Windows" StackTrace: " at Windows.Devices.SerialCommunication.SerialDevice.put_StopBits(SerialStopBitCount value)"

My understanding is that it's not allowing any "non-zero' value (SerialStopBitCount.One = 0, SerialStopBitCount.OnePointFive = 1 and SerialStopBitCount.Two = 2).

Anyone else have faced the same issue before?
Can someone try to reproduce it?

Entire function source code as reference:

private async void comPortInput_Click(object sender, RoutedEventArgs e)
        {
            try
            {
               string aqs = SerialDevice.GetDeviceSelector("UART0");                   /* Find the selector string for the serial device   */
                var dis = await DeviceInformation.FindAllAsync(aqs);                    /* Find the serial device with our selector string  */
                serialPort = await SerialDevice.FromIdAsync(dis[0].Id);                  /* Create an serial device with our selected device */

                if (serialPort == null) return;

                // Disable the 'Connect' button 
                comPortInput.IsEnabled = false;

                // Configure serial settings
                serialPort.WriteTimeout = TimeSpan.FromMilliseconds(1000);
                serialPort.ReadTimeout = TimeSpan.FromMilliseconds(1000);
                serialPort.BaudRate = 38400;
                serialPort.Parity = SerialParity.None;
                serialPort.StopBits = SerialStopBitCount.Two;  // THIS LINE THROWS AN EXCEPTION
                serialPort.DataBits = 8;
                serialPort.Handshake = SerialHandshake.None;

                // Display configured settings
                status.Text = "Serial port configured successfully: ";
                status.Text += serialPort.BaudRate + "-";
                status.Text += serialPort.DataBits + "-";
                status.Text += serialPort.Parity.ToString() + "-";
                status.Text += serialPort.StopBits;

                // Set the RcvdText field to invoke the TextChanged callback
                // The callback launches an async Read task to wait for data
                rcvdText.Text = "Waiting for data...";

                // Create cancellation token object to close I/O operations when closing the device
                ReadCancellationTokenSource = new CancellationTokenSource();

                // Enable 'WRITE' button to allow sending data
                sendTextButton.IsEnabled = true;

                Listen();
            }
            catch (Exception ex)
            {
                status.Text = ex.Message;
                comPortInput.IsEnabled = true;
                sendTextButton.IsEnabled = false;
            }
        }

Thanks in advance!

@Apflkuacha
Copy link

Apflkuacha commented Sep 19, 2017

I also encountered this problem, this is most probably a bug (or unsupported feature) in Windows IoT

Edit: it is possible to set it on external devices (USB - Serial converters)
At the internal serial port it isn't possible to set StopBits.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants