Ankündigung

Einklappen
Keine Ankündigung bisher.

- √ - pyserial unter python 3.2?

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

    - √ - pyserial unter python 3.2?

    Hallo,

    ich hab hier ein Problem mit pyserial:
    Code:
    >>> ser=serial.Serial()
    >>> ser.port=comport
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    NameError: name 'comport' is not defined
    >>> exit()
    
    c:\Python32>python
    Python 3.2.3 (default, Apr 11 2012, 07:15:24) [MSC v.1500 32 bit (Intel)] on win
    32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import serial
    >>> ser = serial.Serial(15)
    >>> ser.write("?")
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "c:\Python32\lib\site-packages\serial\serialwin32.py", line 283, in write
    
        data = to_bytes(data)
      File "c:\Python32\lib\site-packages\serial\serialutil.py", line 76, in to_byte
    s
        b.append(item)  # this one handles int and str for our emulation and ints fo
    r Python 3.x
    TypeError: an integer is required
    >>>
    Das ganze ist noch unter Windows, weil das Kabel noch nicht in den Keller liegt..

    Jetzt mag es sein, dass sich die Syntax geändert hat, zwischen python 2.7 und 3.2...
    Ich kann aber keine Doku zu pyserial unter python 3.2 finden. Hat jemand von euch da Erfahrung?

    Gruß,
    Hendrik

    #2
    Ok, gefunden:
    In Python3, the standard type for string-literals is not a byte-string,
    but unicode. Thus you need to explicitly encode the passed value to a
    bytes-object, as that's what is allowd for communicating with the
    uoutside world.


    ser.write('this is a string'.encode('utf-8'))

    should do the trick.

    The error-message is an abomination though...

    Kommentar

    Lädt...
    X