psSerial: how to write a single byte value to the serial port?
Tim Hoffman
timh at zute.net
Wed Nov 17 04:08:42 EST 2004
SoftwareTester wrote:
> http://pyserial.sourceforge.net/
> example shows how to write string to serial port.
>
>
> #Open port 0 at "9600,8,N,1", no timeout
>
>
>>>>import serial
>>>>ser = serial.Serial(0) #open first serial
>>>>ser.write("hello") #write a string
>>>>ser.close() #close port
>
>
> how do i write a single byte value to the serial port?
mystring = "hello"
ser.write(mystring[0:1])
or
ser.write("h")
or
ser.write(chr(i)) # where 0<=i<=255
Is that what you where asking for ?
T
More information about the Python-list
mailing list