pySerial 发送 ASCII 数据,但接收设备不响应 [英] pySerial sends ASCII data but recieving device does not respond to it

查看:115
本文介绍了pySerial 发送 ASCII 数据,但接收设备不响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试让 pySerial 向设备(重量秤和质量流量控制器)发送命令,它们都使用 ASCII 格式,并且都不响应发送的命令.但是,我可以使用终端轻松控制两者.我创建了一个虚拟端口来查看从 pySerial 发送到我的设备的内容,但它发送了正确的数据.(T\r\n 发送为 T 13 10,与终端发送的相同)所以我不知所措.似乎 pySerial 向我的设备发送了正确的数据,但由于任何原因没有被正确接受,奇怪的是我可以使用 pySerial 从设备轻松读取数据.只是写作部分失败了,有关如何排除故障或解决此问题的任何建议?

I have been trying to get pySerial to send commands to a device (Weight scale, and mass flow controller) both use ASCII format, and both do not respond to comands sent. However I can easely control both with use of Terminal. I have create a virtual comport to see whats being sent to my devices from pySerial but it sends correct data. (T\r\n is sent as T 13 10, same as what Terminal sends ) so I am at a loss. It seems as though pySerial sends out the right data to my device but for what ever reason is not properly accepted, strangely I can easely read data from the device using pySerial. Its just that the writing section fails, any suggestions on how to trouble shoot or fix this issue?

代码是myserialport.write('T\r\n')

The code is myserialport.write('T\r\n')

我曾尝试使用flush()和flushOutput(),但都没有成功,我还尝试在循环中连续发送命令,但它不起作用.这不是硬件问题,因为我可以使用终端程序控制设备,但不能使用 pySerial...

I have tried to use flush() and flushOutput() but neither did the trick, I also tried to send the commands conseticutavely in a loop, but it did not work eather. its not a hardware issue, since I can control equipment useing Terminal program and only does not work with pySerial...

推荐答案

for i in data:
    PID.write(i)
    time.sleep(1)

您在终端中键入比串行端口写入慢,并且读取每个字符需要时间.与 PC 相比,秤(或其他任何东西)通常非常慢.

You type slower in a terminal than a serial port write and it needs time to read each char. The scale (or whatever) is usually very slow compared to a PC.

这篇关于pySerial 发送 ASCII 数据,但接收设备不响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆