Thanks to visit codestin.com
Credit goes to github.com

Skip to content

read failed after minutes of running #222

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jrleeman opened this issue Jan 22, 2021 · 3 comments
Closed

read failed after minutes of running #222

jrleeman opened this issue Jan 22, 2021 · 3 comments

Comments

@jrleeman
Copy link

On Ubuntu 20.04 with Python 3.8 after continuously running and receiving data for a few minutes we get the message

read failed: device reports readiness to read but returned no data (device disconnected or multiple access on port?)

with a traceback starting at line 444 in xbee/reader.py and going all the way down to serial/serialposix.py. The only solution appears to be to kill the process and start it again, but that's obviously non-ideal. It's not a hardware issue as XCTU reads continuously for hours with no issue.

Nothing fancy happening in my code:

def process_xbee_packet(xbee_message):
    """
    Processes the xbee packet and writes it to file.
    """
    well_data = {}
    raw_packet = xbee_message.data
    well_data['time'] = datetime.utcnow()
    well_data['start_byte'] =raw_packet[0]
    well_data['transmitter_id'] = raw_packet[1]
    well_data['depth'] = struct.unpack('f', raw_packet[2:6])[0]
    well_data['water_temperature'] = struct.unpack('f', raw_packet[6:10])[0]
    well_data['air_pressure'] = struct.unpack('f', raw_packet[10:14])[0]
    well_data['air_temperature'] = struct.unpack('f', raw_packet[14:18])[0]
    well_data['battery'] = struct.unpack('H', raw_packet[18:20])[0]
    well_data['end_byte'] = raw_packet[20]
    print(well_data['transmitter_id'])

    # Write it to file if the packet is complete (start and end bytes are correct)
    if (well_data['start_byte'] == 190) and (well_data['end_byte'] == 239):
        write_well_data(config, well_data)

if __name__ == '__main__':
    try:
        device = XBeeDevice(config['XBEE']['ComPort'], config['XBEE']['BaudRate'])
        device.open()
        device.add_data_received_callback(process_xbee_packet)
        input()
    except (KeyboardInterrupt, SystemExit):
        device.close()
@Artyrm
Copy link

Artyrm commented Aug 20, 2021

Someone is accessing your serial port. Lib just bails out in such cases, but you can try to handle it my way: #252 (comment)

tatianaleon added a commit that referenced this issue Aug 25, 2021
This commit configures exclusive access for the provided XBee serial port by
default. This can be overridden in the constructor (although not recommended)

#222
#252

Signed-off-by: Tatiana Leon <[email protected]>
tatianaleon added a commit that referenced this issue Aug 25, 2021
tatianaleon added a commit that referenced this issue Sep 2, 2021
This commit configures exclusive access for the provided XBee serial port by
default. This can be overridden in the constructor (although not recommended)

#222
#252

Signed-off-by: Tatiana Leon <[email protected]>
tatianaleon added a commit that referenced this issue Sep 2, 2021
@tatianaleon
Copy link
Contributor

Solved in 1.4.1.

@jrleeman
Copy link
Author

Awesome! 🥳

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants