我一直在用Windows测试RaspberryPi3,以便通过IoT与现有的FreeScale硬件进行通信。我一直在使用SerialUART样品作为参考。在我的UWP成功地插入了UART端口之后,我似乎无法接收硬件传输的RS485数据。
我的硬件RS485 UART配置为4800波特率,8位数据格式,非parit和停止等待模式禁用。我成功地在UWP示例中插入了4800-8-none-one,但是硬件传输的数据并没有在Read Data text block上触发和显示。从我的硬件传输的数据是十六进制的,这是F5-01-55-4B。
在传输过程中出现错误。

RS485电路如下。

请告诉我我错过了什么吗?谢谢。
发布于 2019-01-24 01:41:55
您可以参考以下代码。请注意,ReadString方法需要长度的“代码单位”才能读取。这就是为什么在“连线上”时,每条字符串的前面都是它的长度。在您的方案中,无法确保从代码单元中的硬件传输的数据。我不确定在TextBox中以十六进制格式显示数据是否为您所接受。
private async Task ReadAsync(CancellationToken cancellationToken)
{
Task<UInt32> loadAsyncTask;
uint ReadBufferLength = 1024;
// If task cancellation was requested, comply
cancellationToken.ThrowIfCancellationRequested();
// Set InputStreamOptions to complete the asynchronous read operation when one or more bytes is available
dataReaderObject.InputStreamOptions = InputStreamOptions.Partial;
using (var childCancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken))
{
// Create a task object to wait for data on the serialPort.InputStream
loadAsyncTask = dataReaderObject.LoadAsync(ReadBufferLength).AsTask(childCancellationTokenSource.Token);
// Launch the task and wait
UInt32 bytesRead = await loadAsyncTask;
if (bytesRead > 0)
{
//rcvdText.Text = dataReaderObject.ReadString(bytesRead);
var bufferArray = dataReaderObject.ReadBuffer(bytesRead).ToArray();
var content = string.Empty;
foreach(var b in bufferArray)
{
content += Convert.ToString(b,16).ToUpper() + " ";
}
rcvdText.Text = content;
status.Text = "bytes read successfully!";
}
}
}https://stackoverflow.com/questions/54301070
复制相似问题