Hi all, I am working with a pair of Series 2 Xbees and python. I can send data and turn my led off and on no problem, but when i go to read the response back the data comes back always missing the start byte and missing some of the end. I ran the same packet in x-ctu to compare the differences in the data that python is seeing to verify this. Any pointers or help is greatly appreciated.
Python script
import serial
import serial.tools.list_ports as getPorts
# Get list of ports available
portList = (getPorts.comports())
portNumber = 0
for item in portList:
print (portNumber,' <---> ', item[0])
portNumber = portNumber + 1
usePort = input('Enter device port: ')
ser = (serial.Serial(usePort,9600,timeout=2, rtscts=True, dsrdtr=True))
ledOff = bytes ([0x7e, 0x00, 0x10, 0x17, 0x05, 0x00, 0x13, 0xA2, 0x00, 0x40, 0x8a, 0xda, 0x38, 0xff, 0xfe, 0x02, 0x44, 0x32, 0x04, 0xd9])
ledOn = bytes ([0x7e, 0x00, 0x10, 0x17, 0x05, 0x00, 0x13, 0xA2, 0x00, 0x40, 0x8a, 0xda, 0x38, 0xff, 0xfe, 0x02, 0x44, 0x32, 0x05, 0xd8])
option = input('Turn Led off or on? : ')
if option == ('on'):
print ('Turn on')
ser.write(ledOn)
incoming = ser.readline()
elif option == ('off'):
print ('Turn off')
ser.write(ledOff)
incoming = ser.readline()
else:
print ('invalid')
incoming = ('no data received')
print (incoming)
ser.close()
Results of Python script
0 <---> /dev/tty.Bluetooth-PDA-Sync
1 <---> /dev/tty.Bluetooth-Modem
2 <---> /dev/tty.usbserial-A501D90P
Enter device port: /dev/tty.usbserial-A501D90P
Turn Led off or on? : off
Turn off
b'~\x00\x0f\x97\x05\x00\x13\xa2\x00@\x8a\xda8\x15\rD2\x00:'