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

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

Description

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!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions