如何测试串行/超级终端与 C# 的集成?
我必须为 USB 秤开发软件,当您按下秤上的按钮时,该软件就会通过 USB 发送串行通信。 我可以在超级终端中看到这些值。
我将使用 .NET 类进行串行通信来捕获数据。
问题是我没有秤。 秤已连接到我可以通过 RDP 连接的远程计算机。 当我想要测试时,我可以让客户按下体重秤上的按钮。
我不能要求客户每天按下按钮 100 次,我需要有一种方法来开发,对秤将报告的内容有一个相当好的了解,并且仅在我认为我有解决方案时才进行测试。
我正在本地寻找一些东西,它可以模仿比例并发送到我的.NET Serial 类,与比例相同的输出。 理想情况下,如果我能记录体重秤的数据,然后在另一台机器上回放,那就完美了。
我该怎么做?
I have to develop software for a USB scale that, when you press a button on it, sends serial communications over USB. I can see the values in HyperTerminal.
I am going to use the .NET classes for Serial communication to trap the data.
The problem is, I don't have the scale. The scale is connected to a remote computer I can RDP into. When I want to test, I can ask the client to press the button on the scale.
I can't ask the client to press the button 100 times a day, I need to have a way to develop with a reasonably good idea of what the scale will report, and only test when I think I have a solution.
I'm looking for something locally, that can mimic the scale and send to my .NET Serial classes, the same output as the scale. Ideally, if I could record the scale's data, and then play it back on another machine, it would be perfect.
How would I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
1) 抽象出您的通信代码。 在测试模式下,从数据文件流而不是串行流提供逻辑功能。
或
2) 如果您有 2 个串行端口(或两个端口),则设置一个通过一个端口进行通信的秤仿真器应用程序,并将其插入运行软件的另一个端口。
1) Abstract away your communications code. In test mode, feed your logic function from a data file stream rather than the serial stream.
or
2) If you have 2 serial ports (or two pcs), then setup a scale emulator app that talks out thru one port, and plug that into the other port where your software is running.
如果您采用串行端口模拟路线,请查看 com0com。 我一直用它来伪造与实验室仪器的通信,效果很好。 当您的笔记本电脑缺少串行端口时非常有用。
If you take the serial port emulation route, take a look at com0com. I use it all the time to fake communications with laboratory instruments and it works nicely. Very useful when you laptop lacks serial ports.
您有两个问题:
您可以测试 1。通过将任何可以生成数据的设备(例如另一台带有超级终端的 PC)连接到 PC 的本地串行端口。
您可以通过(出于测试目的)用软件替换您的串行类来进行测试,该软件充当“串行类+比例”组合的“模拟对象”(即,使用您的串行类将使用的API输入到您的程序中)使用您期望从秤接收的数据)。
您还可以通过以下方式测试 1 和 2:
You have two problems:
You can test 1. by attaching anything which can generate data (e.g. another PC with Hyperterminal) to your PC's local serial port.
You can test 2. by (for testing purposes) replacing your serial classes with software which acts as a "mock object" for the 'serial classes + scale' combination (i.e. which feeds into your program, using the API which your serial classes would use, the data which you expect to receive from the scale).
You can also test 1 and 2, by: