Python XBee Library Can't Read Properties after a Packet Receipt

Tried posting this yesterday, but I guess it didn’t post or something.

Anyway I’m trying to read properties out of an S3B module using the digi-xbee python library and it works if I call it right after instantiation, but not if I try it after a packet is received.

I create the S3BDevice Object with my serial port, I can read data packets from remote S3B devices, but when I try and read the ID property from the modem it times out.

Important bits of the code ncdModem.device is DigiMeshDevice(serial_port, baud_rate):

SERIAL_PORT = “/dev/cu.usbserial-AI02QZQZ”
BAUD_RATE = 115200

#this is function is the callback that I pass into the NCDEnterprise module during
#instantiation. The module uses the Digi XBee module which runs on another thread.
def my_custom_callback(sensor_data):
# print('full return: '+ str(sensor_data))
#This call does not work
print(ncdModem.device.get_parameter(“ID”))
if(sensor_data[‘mode’] == ‘PGM’):
print(str(sensor_data))
if(sensor_data[‘sensor_type’] == 24):
# send_configuration_command()
print('full return: '+str(sensor_data))
for prop in sensor_data:
print(prop + ’ ’ + str(sensor_data[prop]))
if(sensor_data[‘mode’] == ‘PGM’):
print(sensor_data[‘source_address’])

#instantiate the NCDEnterprise Object and pass in the Serial Port, Baud Rate,

and Function/Method object

ncdModem = NCDEnterprise(SERIAL_PORT, BAUD_RATE, my_custom_callback)
#This call works
print(ncdModem.device.get_parameter(“ID”))

Actually solved the issue just now.

I’m guessing that the serial port isn’t a shared object throughout the library so when I try and write to the COM Port via .get_parameter the library tries to open a COM port and since the event callback portion of the library is currently keeping the serial port open it fails.

Fixed it by calling this connection reset anytime the library is blocking the Serial Port:
def ncd_xbee_serial_open_override(self):
self.device.close()
self.device.open()
self.device.add_packet_received_callback(self.parse)

Basically I just close the serial port, open it again, and add back my callbacks.

Be sure to add your callbacks back because they disappear for some reason after a close.