Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

driver/sigrok: various fixes #1346

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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