[UWP] [C#]以编程方式在串口上发送和获取数据,无需单击事件

编程入门 行业动态 更新时间:2024-10-26 06:32:27
本文介绍了[UWP] [C#]以编程方式在串口上发送和获取数据,无需单击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

你好,

我希望你能帮助我。我正在开发一个UWP应用程序。我使用包含无限循环的以下函数在串行端口上成功发送和接收数据。

I hope you can help me. I am working on a UWP app. I successfully send and receive data on a serial port employing the following function that includes an infinite loop.

private async void Listen() { try { if (serialPort != null) { dataReaderObject = new DataReader(serialPort.InputStream); // keep reading the serial input while (true) { await ReadAsync(ReadCancellationTokenSource.Token); } } } ... finally { // Cleanup once complete if (dataReaderObject != null) { dataReaderObject.DetachStream(); dataReaderObject = null; } } }

但这仅在我在文本框中写入数据并单击按钮发送时才有效。

But this only works when I write data in a textbox and click a button to send it.

我可以通过哪种方式在没有"Button_Click"的情况下在串口上发送和读取数据。功能?我会在调用Listen()函数之后实现一个在串口上发送和接收数据的函数。我的问题是这个函数是从未调用,因为没有关联的点击事件,无限循环阻止调用它。

In which way can I send and read data on the serial port without a "Button_Click" function? I would implement a function to send and receive data on the serial port just after the Listen() function is called. My problem is that this function is never called because there is no click events associated and the infinite loop prevent to call it.

请清楚,如你所见,我我是新手。

Please, be clear, as you see, I am a newbie.

非常感谢您提前。

Gabriele

推荐答案

感谢您发布此处。

由于您的问题与UWP有关,我会将此案移至UWP论坛。

Since your issue is related to UWP, I will move the case to UWP forum.

最诚挚的问候,

Hart

更多推荐

[UWP] [C#]以编程方式在串口上发送和获取数据,无需单击事件

本文发布于:2023-11-13 01:08:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1582995.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:串口   单击   事件   方式   数据

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!