I found the solution: - write to serial:
using (var dataWriter = new DataWriter(serialPort.OutputStream))
{
dataWriter.WriteString("what u want to send ");
await dataWriter.StoreAsync();
//await dataWriter.FlushAsync();
dataWriter.DetachStream();
}
and serial initialization:
public sealed partial class MainPage : Page
{
private SerialDevice serialPort = null;
DataWriter dataWriteObject = null;
DataReader dataReaderObject = null;
private ObservableCollection<DeviceInformation> listOfDevices;
private CancellationTokenSource ReadCancellationTokenSource;
public MainPage()
{
this.InitializeComponent();
comPortInput.IsEnabled = false;
sendTextButton.IsEnabled = false;
listOfDevices = new ObservableCollection<DeviceInformation>();
ListAvailablePorts();
InitSerial();
}
private async void InitSerial()
{
string portNameN = "UART0";
string aqs = SerialDevice.GetDeviceSelector(portNameN);
var myDevices = await DeviceInformation.FindAllAsync(aqs, null);
if (myDevices.Count == 0)
{
status.Text = "Device not found...";
return;
}
serialPort = await SerialDevice.FromIdAsync(myDevices[0].Id);
// 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.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;
}