测试串口应用

发布于 2025-01-07 16:55:48 字数 323 浏览 0 评论 0原文

我有一个将数据发送到串口的代码。我只是想确保它正确发送数据。我检查了函数的返回值和写入的字节数,它是成功的。有没有其他方法可以实际查看我正在写的数据?

if(WriteFile(m_hSerialComm, pszBuf, dwSize, &dwNumberOfBytesWritten, NULL) != 0)

我尝试使用“高级终端端口软件”

但数据没有出现在那扇窗户里。

I have a code to send data to serial port. I just want to make sure that it is sending the data properly. I checked the function's return value and the number of bytes written and it is success. Is there any other way to actually see the data whatever i am writing?

if(WriteFile(m_hSerialComm, pszBuf, dwSize, &dwNumberOfBytesWritten, NULL) != 0)

I tried to use "Advanced Terminal Port software"

but the data is not coming in that window.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

丶情人眼里出诗心の 2025-01-14 16:55:48

有多种方法可以测试您的软件。如果您有两个串行端口,则用电缆将它们连接起来,并使用终端应用程序(例如您提到的应用程序)监听另一个端口。否则,您可以通过将引脚 2 和 3 连接在一起,在同一端口上环回。无需硬件的选项是使用 com0com 等工具提供的虚拟串行端口。

There are several ways to test your software. If you have two serial ports then connect them with a cable and listen on the other port with a terminal application such as the one you mentioned. Otherwise, you could loop back on the same port by connecting pins 2 and 3 together. A hardware-free option would be to use virtual serial ports as provided by tools like com0com.

各自安好 2025-01-14 16:55:48

假设您正在 Microsoft Windows 操作系统上开发代码,我建议使用 Portmon for Windows“官方”串行端口监控实用程序。我过去使用过它,发现它足够简单,而且对于它的多个过滤/搜索选项也非常有用(因为有时串行端口上传递的数据量很大)。

如果您想要的只是写入到您自己的端口的数据的日志,为什么不将您的 WriteFile (也许还有您的 ReadFile)函数封装在一些“实用”函数中,这些函数既可以在您的串行端口上读取/写入,也可以在您的串口上读取数据。在某个日志文件中?您甚至可以添加时间戳,并直接从您自己的代码中过滤“您正在寻找的任何内容”。

我发现最后一个选项在与客户远程调试应用程序时非常有用。您在应用程序中添加一个按钮来打开和关闭登录,然后您只需要求客户点击“日志”按钮并向您发送结果即可。

Assuming from your piece of code that you are developing on a Microsoft Windows operating system, I would recommend the Portmon for Windows "official" serial port monitoring utility. I have used it in in the past, and found it simple enough, and also quite useful specifically for its multiple filtering/search options (since sometimes the amount of data passed on your serial port is huge).

If all you want is a log of the data you have written to your own port, why not encapsulate your WriteFile (and maybe also your ReadFile) functions in some "utility" function(s) that reads/writes both on your serial port and in some log file? You could even add timestamps, and filter "whatever you are looking for" straight from your own code.

I found this last option really useful when remotely debugging applications with customers. You add a button in your application that toggles the logging on and off, then you simply have to ask your customer to hit the "log" button and to send you the results.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文