ppannuto / python-saleae

Python library to control a Saleae Logic Analyzer
Apache License 2.0
124 stars 55 forks source link

erratic behavior after calling get_analyzer #54

Closed flagline closed 4 years ago

flagline commented 4 years ago

Disclaimer: I just started using this module, so I may not be using it correctly.

I am using the saleae module in my application to capture serial communication to and from a device. Before calling capture_start(), I use the get_analyzers() and get_active_channels() calls to verify that the saleae is setup correctly. The first capture works fine, but subsequent captures raise an exception when calling get_analzyers(). A little debugging showed that the _recv() routine was returning 'TRUE' in response to the 'GET_ANALYZERS' command. It appears there is some sort or synchronization problem and the get_analzyers() is getting the response to a previous is_processing_complete().

My workaround was to use a try block around the get_analyzers() call and loop until successful. The first call raises an exception (except for first time) that I ignore and the second call is successful. This resyncs the socket communication and no further problems (so far).

ppannuto commented 4 years ago

Hmm, I haven't seen anything like that happen before. It certainly doesn't sound like anything that is supposed to happen.

Are you only calling capture_start or are you doing something to check when the capture is complete? Could you reduce to some minimum working example that exhibits the bug?

flagline commented 4 years ago

Here's a test program and output that illustrate what I'm seeing. SaleaeTest .py.txt output.txt

In the output you can see that a 'List index out of range' exception occurs on subsequent first calls to get analyzers. This is because _recv is returning 'TRUE' in response to the 'GET_ANAYLZERS' _cmd call (instead of the expected list of analyzers).

ppannuto commented 4 years ago

Interesting.. it's quite surprising to see any F in the Export list. I believe that wait should be using is_analyzer_complete. Though that still does not explain how things get out of sync. Perhaps the issue stems from not waiting for the first export analyzer to finish before triggering the next?

flagline commented 4 years ago

I tried setting a breakpoint in _recv (line 242 of saleae.py) so that I could step slowly and allow plenty of time between commands. It also allows me to see the _rxbuf contents after each command. But even stepping through the commands slowly, it's behaving oddly. For example, the calls to is_processing_complete() following start_capture() return 'NAK' the first time, 'ACK' the second time, and 'TRUE/nACK' after that. The reply on the second call looks incorrect to me.

ppannuto commented 4 years ago

Hmm.., from that description it sounds like it may be an upstream issue? Those inconsistent replies from the Logic software would certainly confuse processing on this end..

On Tue, Feb 25, 2020 at 1:21 PM flagline notifications@github.com wrote:

I tried setting a breakpoint in _recv (line 242 of saleae.py) so that I could step slowly and allow plenty of time between commands. It also allows me to see the _rxbuf contents after each command. But even stepping through the commands slowly, it's behaving oddly. For example, the calls to is_processing_complete() following start_capture() return 'NAK' the first time, 'ACK' the second time, and 'TRUE/nACK' after that. The reply on the second call looks incorrect to me.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ppannuto/python-saleae/issues/54?email_source=notifications&email_token=AACS3XQXZO4PYQLKENWDNVDREWDTXA5CNFSM4KX3PXTKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEM5ROHI#issuecomment-591075101, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACS3XQTKDHAKQ7YWCAPL2LREWDTXANCNFSM4KX3PXTA .

flagline commented 4 years ago

It could be. I appreciate your input, but I've put in as much time as I can afford looking into this. Despite the glitches, this module has been super helpful.

ppannuto commented 4 years ago

I understand! Thanks for all your debug effort.

If you find the loop method to be robust enough as a workaround and think it's worth integrating generally in the library, I'm happy to take a PR.

In the meantime, I think I'm going to close this issue out as an upstream bug (attn @Marcus10110). Feel free to re-open (you or others) if new information merits.

flagline commented 4 years ago

No problem. For what I'm doing, it seems to be working, but I'm only using a small subset of the commands. I think for a real solution, you'd need to identify where the problem is coming from. I'm still a bit mystified as to exactly what is going on.

On Wed, Feb 26, 2020 at 8:12 AM Pat Pannuto notifications@github.com wrote:

Closed #54 https://github.com/ppannuto/python-saleae/issues/54.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ppannuto/python-saleae/issues/54?email_source=notifications&email_token=AOTHQVKJGQFRI4VS26KI7Q3RE2IFBA5CNFSM4KX3PXTKYY3PNVWWK3TUL52HS4DFWZEXG43VMVCXMZLOORHG65DJMZUWGYLUNFXW5KTDN5WW2ZLOORPWSZGOW473XGY#event-3074407323, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOTHQVOBNUWDTMSO5CXHGCTRE2IFBANCNFSM4KX3PXTA .

-- Tom Herron Flagline Consulting, LLC 541-224-6953