ms-iot / rpi-iotcore

Windows 10 IoT Core Board Support Package for Raspberry Pi
http://www.windowsondevices.com/
MIT License
124 stars 58 forks source link

Windows 10 IoT Core Serial Communication problem (Property of the parity (none, even, odd) is not changing.) #62

Open IntelliSenseIoT opened 4 years ago

IntelliSenseIoT commented 4 years ago

Problem:

Property of the parity (none, even, odd) is not changing. We tried with the Baudrate also, it is working.

Information about environment and app:

Code:

    private async Task<CommonFunctions.Result> opencomport(string DeviceId)
    {
        CommonFunctions.Result res = new CommonFunctions.Result();
        try
        {
            foreach (var oneport in ComDeviceList)
            {
                if (oneport.ComDeviceId == DeviceId && oneport.PortOpen == false)
                {
                    oneport.serialPort = await SerialDevice.FromIdAsync(DeviceId);
                    if (oneport.serialPort == null)
                    {
                        res.Success = false;
                        res.ErrorMessage = "SerialPort object is null!";
                        return res;
                    }
                    else
                    {
                        oneport.serialPort.WriteTimeout = TimeSpan.FromMilliseconds(oneport.WriteTimeout);
                        oneport.serialPort.ReadTimeout = TimeSpan.FromMilliseconds(oneport.ReadTimeout);

                        oneport.serialPort.BaudRate = 9600;
                        oneport.DataBits = 8;
                        oneport.StopBits = CommonFunctions.SerialStopBitCount.One;
                        oneport.serialPort.Parity = Windows.Devices.SerialCommunication.SerialParity.Even;
                        oneport.serialPort.Handshake = Windows.Devices.SerialCommunication.SerialHandshake.None;

                        oneport.ReadCancellationTokenSource = new CancellationTokenSource();

                        Listen(oneport);
                        oneport.PortOpen = true;

                        res.Success = true;
                        return res;
                    }
                }
            }
        }
        catch (Exception ex)
        {
            res.Success = false;
            res.ExceptionError = true;
            res.ErrorMessage = ex.Message;
            return res;
        }

        res.Success = false;
        return res;
    }
IntelliSenseIoT commented 4 years ago

Additional information to the previous one:

In Program I change the parity (serial communication), but always remains none. What is the problem?