The property returns the 'the number of bytes in the receive buffer'. This seems to be the equivalent of 's description: 'the number of bytes. That's already arrived and stored in the serial receive buffer.' Try: import serial ser = serial.Serial('/dev/ttyACM0', 9600, timeout=0.050). While ser.in_waiting: # Or: while ser.inWaiting(): print ser.readline() For versions prior to pyserial 3.0, use.inWaiting(). To determine your pyserial version, do this: import serial print(serial.__version__). I solved the same problem like so. The only drawback of this code is that when the first time I'm sending letter 'a', ser.inWaiting() will return 0. To remove this effect I added delay of 1 second before it. That seems to solve the problem. In my case, ATmega16 sends back a string either 8 or 12bits. A correct answer will depend on the version of Python - this has tripped me up for some time today. I suspect some of the comments were running on Raspberry Pi which is currently at Python 2.7.9 and similarly less-than-current pySerial. So on a Pi you might use ser.inWaiting() which is similar to Serial.available() in Arduino C - both return the number of bytes in the receive buffer; for pySerial >= 3.0 you use ser.in_waiting (note this is an attribute not a function - ) Incidentally, on a Pi (and presumably older Pythons/pySerials) import serial; print (serial.__version__) results in an attribute error but works on newer versions. I have written my code as below. Hope you can use it modify your code import serial import csv import os import time import sys import string from threading import Timer def main(): pass if __name__ == '__main__': main() COUNT=0 f=open('test.csv','w+'); result = csv.writer(f,delimiter=',') result_statement=('Dir','ACTUATOR_ON_OFF','MODE','DATE','TIME',' TRACKER DESIRED ANGLE',' TRACKER ACTUAL ANGLE') result.writerow(result_statement) f.close() while COUNT. Thank you for the feedback Ajit, but your code unfortunately doesn't address my issue. You simply expect 150 bytes of serial data to be available with ser.read(150) rather than checking to see how much (if any) is available. Some extra tips, a lot of this code can be improved to by more python-like (shorter, cleaner, faster, easier to read). Try using the with keyword in play of f = open(), f.close(), and ser.close(). Additionally, your while COUNT. Wingware python ide Last Keys. X6Orbt-pmNOVy-bO0g4I-x0SZG0 Ar2yb7-tz6UoV-tEKs0y-l5RcqL rbqcT4-s4r9LB-u1Zrn2-7JbOJw D9zyzh-jVKSTw-fxertY-nuqBoF. Wingware python ide serial number generator for WINDOWS.
0 Comments
|
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
March 2019
Categories |