question about binary and serial info

nephish at xit.net nephish at xit.net
Thu Aug 18 13:42:32 EDT 2005


>>> import serial
>>> ser = serial.Serial('/dev/ttyS0', 2400, timeout= 10, bytesize=8, stopbits=1)
>>> a = ser.read(1)
>>> print a
^
>>> ser.close()

>>> type(a)
<type 'str'>

>>> int(a, 16)
Traceback (innermost last):
  File "<stdin>", line 1, in ?
ValueError: invalid literal for int(): ^

so i run it again the same way, only reading 4 bytes this time.

>>> ser = serial.Serial('/dev/ttyS0', 2400, timeout= 10, bytesize=8, stopbits=1)
>>> a = ser.read(1)
>>> print a
^AÜÀ
>>> ser.close()

>>> type(a)
<type 'str'>


int(a, 16)
Traceback (innermost last):
  File "<stdin>", line 1, in ?
ValueError: invalid literal for int(): ^AÜÀ

i dont understand what i am missing here.
the string character represents a hex character.




More information about the Python-list mailing list