简体   繁体   English

如何使用C#测试串行/超级终端集成?

[英]How to test serial / Hyperterminal integration with C#?

I have to develop software for a USB scale that, when you press a button on it, sends serial communications over USB. 我必须开发用于USB秤的软件,当您按它上的按钮时,它会通过USB发送串行通信。 I can see the values in HyperTerminal. 我可以在超级终端中看到这些值。

I am going to use the .NET classes for Serial communication to trap the data. 我将使用.NET类进行串行通信以捕获数据。

The problem is, I don't have the scale. 问题是,我没有规模。 The scale is connected to a remote computer I can RDP into. 秤连接到我可以RDP插入的远程计算机。 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. 我不能要求客户每天100次按下按钮,我需要有一种方法可以对秤的报告内容有一个相当好的了解,并且只能在我认为有解决方案时进行测试。

I'm looking for something locally, that can mimic the scale and send to my .NET Serial classes, the same output as the scale. 我正在本地寻找可以模拟刻度的东西,并将其发送到我的.NET Serial类,其输出与刻度相同。 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? 我该怎么做?

1) Abstract away your communications code. 1)提取您的通信代码。 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. 2)如果您有2个串行端口(或两台PC),则设置一个通过一个端口发出声音的Scale仿真器应用程序,然后将其插入运行软件的另一个端口。

If you take the serial port emulation route, take a look at com0com . 如果采用串行端口仿真路径,请查看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. 当您的笔记本电脑缺少串行端口时,此功能非常有用。

You have two problems: 您有两个问题:

  1. Test your .NET Serial classes to verify they can handle receiving data (any data) through a serial port 测试您的.NET串行类,以验证它们可以处理通过串行端口接收的数据(任何数据)
  2. Test your application to verify it can handle the specific type of data which you get from the scale 测试您的应用程序,以验证它可以处理从标尺中获取的特定类型的数据

You can test 1. by attaching anything which can generate data (eg another PC with Hyperterminal) to your PC's local serial port. 您可以通过将可以生成数据的任何内容(例如,另一台具有超级终端的PC)连接到PC的本地串行端口来进行测试。

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 (ie which feeds into your program, using the API which your serial classes would use, the data which you expect to receive from the scale). 您可以进行测试2.通过(出于测试目的)用充当“串行类+规模”组合的“模拟对象”的软件替换串行类(即,使用串行类将要使用的API馈入程序中的软件)使用,您希望从秤中收到的数据)。

You can also test 1 and 2, by: 您还可以通过以下方法测试1和2:

  • Writing a program, which pretends to be the scale by sending the type of data which the scale would send 编写一个程序,通过发送秤将发送的数据类型来伪装成秤
  • Running this program to send data out of a serial port 运行该程序以串行端口发送数据
  • Using a null modem to connct your two serial ports back-to-back (so that the data sent out of one port is received by another into your software). 使用空调制解调器背对背连接两个串行端口(以便从一个端口发送的数据被另一个端口接收到您的软件中)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM