【发布时间】:2018-12-12 02:39:49
【问题描述】:
UART 数据传输 树莓派 UART (RX TX) Arduino 我知道应该避免异步无效。它们仅用于事件处理。对于其他方法返回任务。异步和等待 哪里会出错?为什么数据不来?
谁知道显示如何在 UART 上接收数据的链接?
using Windows.Storage.Streams;
using Windows.Devices.Enumeration;
using Windows.Devices.SerialCommunication;
public async void Serial()
{
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 */
SerialDevice SerialPort = await SerialDevice.FromIdAsync(dis[0].Id); /* Create an serial device with our selected device */
/* Configure serial settings */
SerialPort.WriteTimeout = TimeSpan.FromMilliseconds(1000);
SerialPort.ReadTimeout = TimeSpan.FromMilliseconds(1000);
SerialPort.BaudRate = 9600; /* mini UART: only standard baudrates */
SerialPort.Parity = SerialParity.None; /* mini UART: no parities */
SerialPort.StopBits = SerialStopBitCount.One; /* mini UART: 1 stop bit */
SerialPort.DataBits = 8;
/* Write a string out over serial */
string txBuffer = "Hello Serial";
DataWriter dataWriter = new DataWriter();
dataWriter.WriteString(txBuffer);
uint bytesWritten = await SerialPort.OutputStream.WriteAsync(dataWriter.DetachBuffer());
/* Read data in from the serial port */
const uint maxReadLength = 1024;
DataReader dataReader = new DataReader(SerialPort.InputStream);
uint bytesToRead = await dataReader.LoadAsync(maxReadLength);
string rxBuffer = dataReader.ReadString(bytesToRead);
}
【问题讨论】:
-
哦..您使用
Winodws IOT Core..我想尝试在Windows中开发应用程序以从连接到R-PI的串行端口读取数据 -
仔细阅读标题,然后减去:)
-
@SergeyKuntsevich,您是否跨过与另一个串口端连接的 RxTx 线?
标签: c# raspberry-pi iot windowsiot windows-iot-core-10