private async void ConnectDevice(string entryId) { try { // serialPort is a private variable of MainPage serialPort = await SerialDevice.FromIdAsync(entryId); // Configure serial settings serialPort.WriteTimeout = TimeSpan.FromMilliseconds(1000); serialPort.ReadTimeout = TimeSpan.FromMilliseconds(1000); serialPort.BaudRate = 9600; serialPort.Parity = SerialParity.None; serialPort.StopBits = SerialStopBitCount.One; serialPort.DataBits = 8; serialPort.Handshake = SerialHandshake.RequestToSend; serialPort.PinChanged += SerialPort_PinChanged; // Listien to incomming data Listen(); } catch (Exception ex) { status.Text = ex.Message; } } private async void SerialPort_PinChanged(SerialDevice sender, PinChangedEventArgs args) { switch (args.PinChange) { case SerialPinChange.ClearToSend: // If device is ready, write data if (serialPort.ClearToSendState) await WriteAsync(); break; default: break; } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)