İ want to write 2 byte of data to serial port using pyserial in python. since the pyserial lets me send 1 byte at one time i writed following code to accomplish my problem but this doesnt seem to work right do you have opinion to help me with this? the code ;
import serial # import the module
ComPort = serial.Serial('/dev/ttyUSB0') # open ttyUSB0
ComPort.baudrate = 9600 # set Baud rate
ComPort.bytesize = 8 # Number of data bits = 8
ComPort.parity = 'N' # No parity
ComPort.stopbits = 1 # Number of Stop bits = 1
position = 324 # integer to be send to port
get_bin = lambda x, n: format(x, 'b').zfill(n) # binary format
data = (get_bin(position,16)) # 16 digit binary format
data_first_part = data[0:8] #first 8 digits
data_second_part = data[8:16] #second 8 digit
try:
data1 = bytearray(data_first_part)
data2 = bytearray(data_second_part)
No = ComPort.write(data1+data2)
print data1+data2
print data1
print data2
ComPort.close() #Close the Serial port
except IndexError:
print "no success"