测试串口应用
我有一个将数据发送到串口的代码。我只是想确保它正确发送数据。我检查了函数的返回值和写入的字节数,它是成功的。有没有其他方法可以实际查看我正在写的数据?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有多种方法可以测试您的软件。如果您有两个串行端口,则用电缆将它们连接起来,并使用终端应用程序(例如您提到的应用程序)监听另一个端口。否则,您可以通过将引脚 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.
假设您正在 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.