ppannuto / python-saleae

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

"CommandNAKedError" received while exporting data using export_analyzer #47

Closed pudumula closed 5 years ago

pudumula commented 5 years ago

While running the following script

import os
import saleae
import time
s = saleae.Saleae()
s.get_analyzers()
s.set_capture_seconds(10)
s.capture_start_and_wait_until_finished()
save_path = os.path.join(os.getcwd(), "file_name.csv")
# 0 is simple parallel
while not s.is_analyzer_complete(0):
    time.sleep(1)
time.sleep(10)
s.export_analyzer(0,save_path)

i get the following error


CommandNAKedError Traceback (most recent call last)

in () 2 time.sleep(1) 3 time.sleep(10) ----> 4 s.export_analyzer(0,save_path) 5 # s.export_data2(save_path) ~\AppData\Local\Continuum\anaconda3\lib\site-packages\saleae\saleae.py in export_analyzer(self, analyzer_index, save_path, wait_for_processing, data_response) 972 '''Export analyzer index N and save to absolute path save_path. The analyzer must be finished processing''' 973 if wait_for_processing: --> 974 while not self.is_analyzer_complete(analyzer_index): 975 time.sleep(0.1) 976 self._build('EXPORT_ANALYZER') ~\AppData\Local\Continuum\anaconda3\lib\site-packages\saleae\saleae.py in is_analyzer_complete(self, analyzer_index) 986 self._build('IS_ANALYZER_COMPLETE') 987 self._build(str(analyzer_index)) --> 988 resp = self._finish() 989 return resp.strip().upper() == 'TRUE' 990 ~\AppData\Local\Continuum\anaconda3\lib\site-packages\saleae\saleae.py in _finish(self, s) 181 self._build(s) 182 try: --> 183 ret = self._cmd(', '.join(self._to_send)) 184 finally: 185 self._to_send = [] ~\AppData\Local\Continuum\anaconda3\lib\site-packages\saleae\saleae.py in _cmd(self, s, wait_for_ack, expect_nak) 214 ret = None 215 if wait_for_ack: --> 216 ret = self._recv(expect_nak=expect_nak) 217 return ret 218 ~\AppData\Local\Continuum\anaconda3\lib\site-packages\saleae\saleae.py in _recv(self, expect_nak) 205 return None 206 else: --> 207 raise self.CommandNAKedError 208 ret, self._rxbuf = self._rxbuf.split('ACK', 1) 209 return ret CommandNAKedError: Is something wrong with my script ?
ppannuto commented 5 years ago

Hmm, there seem to be some known issues in the Saleae software where it can NAK unexpectedly if the Saleae software isn't ready (see #7 for more discussion).

You can try adding a sleep before calling is_analyzer_complete. Also, in this case specifically, I don't think you should need to the explicit call as the library will call wait internally anyway.

Since it's just the wait that's throwing, you can also try catching the NAK error and reissuing the is_complete check.

I don't think this is an issue in the python library, but feel free to re-open if you find a bug in the library somewhere.