简体   繁体   English

使用 python 串口设置 RS232 引脚

[英]Setting RS232 pins using python serial

I want to write and receive data from a frequency response analyser.我想从频率响应分析仪写入和接收数据。 I am connecting to the instrument using a serial connection via a Serial-USB adapter.我通过串行 USB 适配器使用串行连接连接到仪器。 The manual says it will only transmit when CTS (pin8) is high, and only receive when DCD (pin1) is high, both are listed as input pins.手册上说只有在CTS(pin8)为高电平时才会发送,只有在DCD(pin1)为高电平时才会接收,两者都被列为输入引脚。 Does anyone know if there is a way to send high signals to these pins when i want to transmit/receive using pySerial?有谁知道当我想使用 pySerial 发送/接收时是否有办法向这些引脚发送高信号?

Thanks.谢谢。

Today, connecting a PC to a device through a serial port is often done in a peer-to-peer relationship.今天,通过串行端口将 PC 连接到设备通常是在对等关系中完成的。

In that case, a cable called a cross cable is used to connect the two, but there is no standard specification for the pin assignment, and there are many variations.在这种情况下,使用称为交叉电缆的电缆将两者连接起来,但引脚分配没有标准规范,并且有很多变化。

DCD (and RI) is an input signal on both the PC and the device, and there is no corresponding output signal, so the RTS or DTR signal should be used as an alternative. DCD(和RI)在PC和设备上都是输入信号,没有对应的输出信号,所以应该用RTS或DTR信号作为替代。

How you can handle them in software depends on the connection specifications of the cable hardware you choose.如何在软件中处理它们取决于您选择的电缆硬件的连接规格。

After confirming that the RTS/DTR signal on the PC side is connected to the CTS/DCD pin on the device side of the cable, by setting rts and dtr of PySerial to True by software, the CTS/DCD on the device side turns on.确认PC端的RTS/DTR信号连接到线缆设备端的CTS/DCD引脚后,通过软件将PySerial的rts和dtr设置为True,设备端的CTS/DCD开启.


In response to comment:回应评论:

If you fix the signal on the device side as described in the comment and the device side can operates in that state, the PC side will be able to send and receive at any time without additional control processing.如果按照注释中的描述在设备端固定信号并且设备端可以在该状态下运行,那么PC端将可以随时发送和接收,无需额外的控制处理。

最后我用一根电线将CTS和DCD引脚手动连接到一个不断输出高信号的引脚。

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

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