22import re
33import subprocess
44import shutil
5- import signal
65import tempfile
76import time
87import uuid
@@ -149,6 +148,16 @@ def capture(self, filename, samplerate="200k"):
149148 args = self .sigrok .command_prefix + ['test' , '-e' , filename ]
150149
151150 while subprocess .call (args ):
151+ # in case the sigrok-cli call fails, this would wait forever.
152+ # to avoid this, we also check the spawned sigrok process
153+ if self ._process .poll () is not None :
154+ ret = self ._process .returncode
155+ if ret != 0 :
156+ stdout , stderr = self ._process .communicate ()
157+ self .logger .debug ("sigrok-cli call terminated prematurely with non-zero return-code" )
158+ self .logger .debug ("stdout: %s" , stdout )
159+ self .logger .debug ("stderr: %s" , stderr )
160+ raise ExecutionError (f"sigrok-cli call terminated prematurely with return-code '{ ret } '." )
152161 sleep (0.1 )
153162
154163 self ._running = True
@@ -161,15 +170,15 @@ def stop(self):
161170 fnames .extend (self .sigrok .channels .split (',' ))
162171 csv_filename = f'{ os .path .splitext (self ._basename )[0 ]} .csv'
163172
164- self . _process . send_signal ( signal . SIGINT )
165- stdout , stderr = self ._process .communicate ()
173+ # sigrok-cli can be quit through any keypress
174+ stdout , stderr = self ._process .communicate (input = "q" )
166175 self .logger .debug ("stdout: %s" , stdout )
167176 self .logger .debug ("stderr: %s" , stderr )
168177
169178 # Convert from .sr to .csv
170179 cmd = [
171180 '-i' ,
172- os .path .join (self ._tmpdir , self ._basename ), '-O' , 'csv' , '-o' ,
181+ os .path .join (self ._tmpdir , self ._basename ), '-O' , 'csv:time=true ' , '-o' ,
173182 os .path .join (self ._tmpdir , csv_filename )
174183 ]
175184 self ._call (* cmd )
@@ -179,7 +188,7 @@ def stop(self):
179188 if isinstance (self .sigrok , NetworkSigrokUSBDevice ):
180189 subprocess .call ([
181190 'scp' , f'{ self .sigrok .host } :{ os .path .join (self ._tmpdir , self ._basename )} ' ,
182- os .path .join ( self . _local_tmpdir , self ._filename )
191+ os .path .abspath ( self ._filename )
183192 ],
184193 stdin = subprocess .DEVNULL ,
185194 stdout = subprocess .DEVNULL ,
@@ -212,7 +221,7 @@ def stop(self):
212221 def analyze (self , args , filename = None ):
213222 annotation_regex = re .compile (r'(?P<startnum>\d+)-(?P<endnum>\d+) (?P<decoder>[\w\-]+): (?P<annotation>[\w\-]+): (?P<data>".*)' ) # pylint: disable=line-too-long
214223 if not filename and self ._filename :
215- filename = self ._filename
224+ filename = os . path . join ( self ._tmpdir , self . _basename )
216225 else :
217226 filename = os .path .abspath (filename )
218227 check_file (filename , command_prefix = self .sigrok .command_prefix )
0 commit comments