简体   繁体   English

Windows中的串行通信仿真

[英]Serial communication emulation in Windows

I want to emulate an Arduino serial communication in Windows. 我想在Windows中模拟Arduino串行通信。 I wrote this pySerial script to represent the connection: 我写了这个pySerial脚本来表示连接:

from serial import Serial
from time import sleep

serial_conn = Serial(<some port>)
serial_conn.baudrate = 9600

for i in range(1,10):
    serial_conn.write(<dummy data>)
    sleep(1)

The problem is the following: I tried to use available serial ports (like COM1 or COM3 for example) but I can't sniff the port with a serial monitor tool. 问题如下:我尝试使用可用的串行端口(例如COM1或COM3),但无法使用串行监视工具来嗅探该端口。 It's because I need hardware to open the port? 这是因为我需要硬件来打开端口吗? Or maybe the problem are the tested ports? 还是问题出在经过测试的端口? (maybe Windows uses the COM1 for comm as Linux uses the first serial too). (也许Windows使用COM1进行通信,而Linux也使用第一个串行)。 Should I try with a virtual serial ports tool? 我应该尝试使用虚拟串口工具吗? If that's the point, can you recomend me someone and the usage? 如果那是重点,您能推荐给我一个人和用法吗?

In Windows hardware and virtual serial ports have the same enumeration scheme, so they will be COM. 在Windows中,硬件和虚拟串行端口具有相同的枚举方案,因此它们将是COM。 The problem is that only one program at time (theorically) can use a Serial port, so if the port is used by your Python program, it won't be available to the terminal. 问题在于,从理论上讲,只有一个程序可以使用一个串行端口,因此,如果您的Python程序使用该端口,则该端口将对终端不可用。

You should setup a fake COM, and this mean a custom driver... too much difficult. 您应该设置一个伪造的COM,这意味着要自定义驱动程序……太难了。

Socket, file and standard input can be read/written one byte a time, so you can test your parser using them. 套接字,文件和标准输入一次只能读取/写入一个字节,因此您可以使用它们来测试解析器。

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

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