我有一个程序可以将串行设备拆分为多个虚拟串行端口并将所有数据路由到它们。
---- /dev/ttyS1.a [data]->
|
[data]-> /dev/ttyS1 ---- /dev/ttyS1.b [data]->
|
---- /dev/ttyS1.c [data]->
我的工作程序(为了可读性和简单性而编写的伪代码):
poll(...) {
// Route data from master to vsp
master.read(buf)
for(virtual serial ports as vsp) {
vsp.write(buf)
}
// Route data from vsp to master (if need be)
for(virtual serial ports as vsp) {
if(vsp.needs_to_write()) {
vsp.read(buf)
master.write(buf)
}
}
}
我的机器上有一个物理串行端口设备,它不断地提供数据,这就是我测试我的程序最初是否工作的方式,但我想编写一个测试来模拟/模拟写入和读取两个方向并验证两端的数据。由于我从我的物理串行端口设备接收到的数据写入看似随机的数据,因此很难验证正在写入的数据是否正是正在写入的数据。
我怎样才能做到这一点? (伪代码)
1. fork process that feeds a known char sequence into /dev/ttyS2 in a loop
2. use my program to read from the COM `master.read(buf)` and then write to the vsp `vsp.write(buf)`
3. how can I verify that after writing to the buf that the vsp has the correct data?
感谢任何帮助我对如何自动测试这个感到困惑。
编辑 1: 没人能帮忙吗?
最佳答案
我觉得你可以用com0com来测试。您可以连接虚拟串行端口,然后写入一个并从其他端口读取它收到的内容。 enter link description here
关于C++ - 在没有物理设备的情况下测试串口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22202950/