having trouble with python program receiving serial strings from prop
train nut
Posts: 70
I tried the test program in another thread but I don't seem to be getting any string in. I'm not quite sure how to post code so I can't post anything to help. How do I post code?
Comments
Paste your code in there then highlight it and hit the # button at the top of the edit window.
Or manually put [ code ] and [ /code ] at the beginning and end of the code block. (without the spaces).
This is my python program running under windows xp.
All I get on the console is b" each time the prop sends the message. I am using a parallax usb to serial converter. The prop seems to receive serial strings from the pc fine. If I put a loop back short on the serial plug the python program sends and receives fine. Help.
Thank you Heater for the info.
Must be something in the Python code.
However I am not able to run the program yet as a module. Also, the b seems to come from the print command since it is not in the quotes. Note: the = sign does not show up in the timeout=1.
sm
If so, the problem would probably be in your Python version. There was a major syntax change from Python 2.x to Python 3.x and the code is not backward compatible. Some old code will run on the new Python version but operation can be sketchy.
What is your experience with Python? Are you new to it or do you have prior knowledge of the language?
import serial
ser = serial.Serial('COM24', 115200, timeout=1)
while 'TRUE' :
print(ser.readline().decode('UTF-8'))
It needed the colon. The b gets suppressed by using the decode option.
Output:
Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:03:43) [MSC v.1600 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>>
Testing
Testing
Testing
Testing
Testing
>>>
sm
Pyserial installed correctly? (using the Windows download installer)
The led issue with the Prop sounds like a Reset from the USB port. I assume you loaded to EEPROM so the test program reboots?
You may need to close the serial port from the Python command line too... that really should be done at the end of the Python test program.