Skip to content

Commit

Permalink
Merge pull request #1346 from flxzt/sigrok-driver-fixes
Browse files Browse the repository at this point in the history
driver/sigrok: various fixes
  • Loading branch information
Emantor committed Jun 26, 2024
2 parents 1e8bad9 + 8646297 commit cecb82f
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions labgrid/driver/sigrokdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import re
import subprocess
import shutil
import signal
import tempfile
import time
import uuid
Expand Down Expand Up @@ -149,6 +148,16 @@ def capture(self, filename, samplerate="200k"):
args = self.sigrok.command_prefix + ['test', '-e', filename]

while subprocess.call(args):
# in case the sigrok-cli call fails, this would wait forever.
# to avoid this, we also check the spawned sigrok process
if self._process.poll() is not None:
ret = self._process.returncode
if ret != 0:
stdout, stderr = self._process.communicate()
self.logger.debug("sigrok-cli call terminated prematurely with non-zero return-code")
self.logger.debug("stdout: %s", stdout)
self.logger.debug("stderr: %s", stderr)
raise ExecutionError(f"sigrok-cli call terminated prematurely with return-code '{ret}'.")
sleep(0.1)

self._running = True
Expand All @@ -161,15 +170,15 @@ def stop(self):
fnames.extend(self.sigrok.channels.split(','))
csv_filename = f'{os.path.splitext(self._basename)[0]}.csv'

self._process.send_signal(signal.SIGINT)
stdout, stderr = self._process.communicate()
# sigrok-cli can be quit through any keypress
stdout, stderr = self._process.communicate(input="q")
self.logger.debug("stdout: %s", stdout)
self.logger.debug("stderr: %s", stderr)

# Convert from .sr to .csv
cmd = [
'-i',
os.path.join(self._tmpdir, self._basename), '-O', 'csv', '-o',
os.path.join(self._tmpdir, self._basename), '-O', 'csv:time=true', '-o',
os.path.join(self._tmpdir, csv_filename)
]
self._call(*cmd)
Expand All @@ -179,7 +188,7 @@ def stop(self):
if isinstance(self.sigrok, NetworkSigrokUSBDevice):
subprocess.call([
'scp', f'{self.sigrok.host}:{os.path.join(self._tmpdir, self._basename)}',
os.path.join(self._local_tmpdir, self._filename)
os.path.abspath(self._filename)
],
stdin=subprocess.DEVNULL,
stdout=subprocess.DEVNULL,
Expand Down Expand Up @@ -212,7 +221,7 @@ def stop(self):
def analyze(self, args, filename=None):
annotation_regex = re.compile(r'(?P<startnum>\d+)-(?P<endnum>\d+) (?P<decoder>[\w\-]+): (?P<annotation>[\w\-]+): (?P<data>".*)') # pylint: disable=line-too-long
if not filename and self._filename:
filename = self._filename
filename = os.path.join(self._tmpdir, self._basename)
else:
filename = os.path.abspath(filename)
check_file(filename, command_prefix=self.sigrok.command_prefix)
Expand Down

0 comments on commit cecb82f

Please sign in to comment.