Shop OBEX P1 Docs P2 Docs Learn Events
having trouble with python program receiving serial strings from prop — Parallax Forums

having trouble with python program receiving serial strings from prop

train nuttrain nut Posts: 70
edited 2013-10-18 20:13 in Propeller 1
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

  • Heater.Heater. Posts: 21,230
    edited 2013-10-16 10:53
    Hit "reply to thread" then "go advanced"

    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).
  • train nuttrain nut Posts: 70
    edited 2013-10-16 17:38
    This is my spin program.
    CON                                                                 
         _clkmode      = xtal1 + pll16x                                    
         _xinfreq      = 5_000_000
         tran_pin = 30
         rec_pin = 31
    
    obj
      comm : "Extended_FDSerial"
    
    var
      long time
      
    pub main_program
    
    
    
      comm.start(rec_pin, tran_pin, 0, 115_200)                  'Set Serial at 115200
      time := cnt
      
    repeat
      comm.str(string("Testing"))
      comm.tx(13)
      comm.tx(10)
      waitcnt(time += clkfreq)
       
    


    This is my python program running under windows xp.
    import serial
    import binascii
    
    BAUD = 115200
    ser = serial.Serial('COM12' , BAUD, timeout = 1)
    while 'TRUE':
        print(ser.readline())
    
    


    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.
  • StephenMooreStephenMoore Posts: 188
    edited 2013-10-16 22:29
    Do you get the data with Parallax Serial Terminal?

    Must be something in the Python code.
  • train nuttrain nut Posts: 70
    edited 2013-10-17 07:53
    Yes parallax serial terminal receives the data fine. There isn't a lot of documentation on pyserial. So its possible that I don't have something quite right.
  • StephenMooreStephenMoore Posts: 188
    edited 2013-10-17 19:28
    Well as afar as I can tell it is something quirky about Python. I get the following from the Python command prompt>>
    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.
    >>> import serial
    >>> ser = serial.Serial('COM24', 115200, timeout=1)
    >>> print(ser.readline())
    b'Testing\r\n'
    >>> 
    

    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
  • MicrocontrolledMicrocontrolled Posts: 2,461
    edited 2013-10-17 20:50
    You mentioned you tried the test code from another thread. Was it by any chance this one? http://forums.parallax.com/showthread.php/128465-Here-is-the-Python-to-Propeller-Tutorial!!?highlight=Python
    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?
  • StephenMooreStephenMoore Posts: 188
    edited 2013-10-17 21:51
    This code runs in version 3.3.2:



    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
  • train nuttrain nut Posts: 70
    edited 2013-10-18 07:17
    Thanks for all the replies guys. I am using python 3.3.2 however I used the code you said works but I still don't get anything. I have noticed the read light that indicates the propeller is trans flaches evey time the properller sends data. The light quits flashing when the python program opens the port and if I recycle the prop I get one char from the input string. I don't know what is going on. I am new to python as I am thinking ahead to when windows finally get squirrely.
  • StephenMooreStephenMoore Posts: 188
    edited 2013-10-18 20:13
    Windows environmnent PATH variable is set to your Python directory?
    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.
Sign In or Register to comment.