veeso / ATtila

Python module to communicate easily with modems and RF modules using AT commands
MIT License
25 stars 10 forks source link

[BUG] Bad response #3

Closed jocelynke closed 4 years ago

jocelynke commented 4 years ago

Describe the bug I often get bad response to the same command :

Exception :  "Command 'AT+CSQ' got a bad response: '['AT+CSQ']' (and hasn't any doppelganger)!"

To Reproduce Run the following code

atrunenv = ATRuntimeEnvironment(True)
atrunenv.configure_communicator(serial_port="/dev/ttyUSB2", baud_rate=9600, timeout=5)
atrunenv.open_serial()
while True:
    print("Running command")
    try:
        response = atrunenv.exec("AT+CSQ;;OK;;0;;5;;['AT+CSQ=?{rssi},','AT+CSQ=${rssi},?{ber}']")
        print(response.full_response)
    except Exception as e:
        print("Exception : ", e)
    time.sleep(1)

Expected behavior No exception since the command is correct and a timeout of 5 seconds should be sufficient. The sleep(1) makes sure to not run too many commands.

Desktop:

veeso commented 4 years ago

Hi,

thank you for reporting the issue.

Let me explain the problem here: With a multi threading system you could just have one thread reading and providing the buffer to the main thread, while here there's no multi threading and when you write the process will start reading and then it waits for the other endpoint to finish writing.

This is fine, except for the fact that sometimes pyserial, which is used by ATtila to interface with serial devices, says there's nothing to read and the read returns. The timeout indeed is only used when no data has been read.

The last fix, improved a lot the performance, but in many cases it missed the bytes. This happens especially when using a low baud rate (such as 9600 indeed).

I've managed to fix this issue, but yep, the performance is lower. Still fast, but not superfast. The problem is that I want to guarantee my read function to wait for the endpoint to finish, but this involves delays, which are annoying. In my opinion it's not too slow, and should be fine. I don't think I want to make other fixes for this issue, since here I can choose between:

If you want to give it a try, there's a patch 1.1.5.

Let me know if it's ok for you.

jocelynke commented 4 years ago

OK thanks for the explanation. I will give it a try!