问题
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?
The code is myserialport.write('T\r\n')
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...
回答1:
for i in data:
PID.write(i)
time.sleep(1)
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.
来源:https://stackoverflow.com/questions/14654031/pyserial-sends-ascii-data-but-recieving-device-does-not-respond-to-it