我在使用 python 通过串口发送数据时遇到问题
我正在尝试通过使用 PYTHON 通过串行端口发送名为 ON 的命令来打开我的应用程序。我已经在控制器中编写了一个程序,当我通过串行端口收到命令时,它必须执行一些操作。
这是我的代码:
import serial
s=serial.Serial(0)
s.write('^ON') #this is my string to ON
s.close()
但问题是它可以读取控制器发送的数据 但它无法将数据写入控制器
I am trying to ON my application by sending a command called ON via serial port using PYTHON..I already wrote a program in my controller that when ever i receive a command via serial port it has to perform some operations.
this is my code:
import serial
s=serial.Serial(0)
s.write('^ON') #this is my string to ON
s.close()
but the thing is it can able to read the data send by the controller
but it cant able to write the data in to the controller
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的微控制器可能需要使用连接器上的 RTS/CTS 或 DSR/DTR 引脚进行“硬件流控制”。也就是说,为了接收,它可能期望发送器“升高”某个引脚,以警告控制器准备发送。这种硬件流控制似乎越来越不常见,因此在 PySerial 中默认禁用。
试试这一行:
或者,如果这不起作用,请尝试:
如果两者都不起作用,请尝试以下:
我希望其中之一对您有用!
(可能不是:很多业余爱好项目的电缆都硬连线了流量控制引脚。但是,我们会看到的!)
Your microcontroller might be expecting "hardware flow control", using the RTS/CTS or DSR/DTR pins on the connector. That is, to receive, it may expect the transmitter to "raise" a certain pin, to alert the controller to prepare for a transmission. This hardware flow control seems to be getting less common, and so is disabled by default in PySerial.
Try this line:
Or, if that doesn't work, try:
If neither works, try this:
I hope one of those works for you!
(It might not: a lot of hobby projects' cables hard-wire the flow control pins. But, we'll see!)