From 675032e99a02a1d1157305eb4e200b373a196f2a Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Mon, 19 Oct 2020 11:47:04 +0200 Subject: Sigrok: Continuous measurement; fix sigrok-cli termination --- lib/lennart/SigrokAPIInterface.py | 9 ++------- lib/lennart/SigrokCLIInterface.py | 36 ++++++++++++++++++++++-------------- lib/lennart/SigrokInterface.py | 6 +----- 3 files changed, 25 insertions(+), 26 deletions(-) (limited to 'lib/lennart') diff --git a/lib/lennart/SigrokAPIInterface.py b/lib/lennart/SigrokAPIInterface.py index a8765ba..a2c087a 100644 --- a/lib/lennart/SigrokAPIInterface.py +++ b/lib/lennart/SigrokAPIInterface.py @@ -51,7 +51,6 @@ class SigrokAPIInterface(SigrokInterface): self, driver="fx2lafw", sample_rate=100_000, - sample_count=1_000_000, debug_output=False, used_datafeed=datafeed_changes, fake=False, @@ -60,12 +59,11 @@ class SigrokAPIInterface(SigrokInterface): :param driver: Driver that should be used :param sample_rate: The sample rate of the Logic analyzer - :param sample_count: The sample count of the Logic analyzer :param debug_output: Should be true if output should be displayed to user :param used_datafeed: one of the datafeeds above, user later as callback. :param fake: """ - super(SigrokAPIInterface, self).__init__(sample_rate, sample_count) + super(SigrokAPIInterface, self).__init__(sample_rate) if fake: raise NotImplementedError("Not implemented!") self.used_datafeed = used_datafeed @@ -98,7 +96,6 @@ class SigrokAPIInterface(SigrokInterface): ) sigrokDevice.open() - sigrokDevice.config_set(ConfigKey.LIMIT_SAMPLES, self.sample_count) sigrokDevice.config_set(ConfigKey.SAMPLERATE, self.sample_rate) enabled_channels = ["D1"] @@ -124,9 +121,7 @@ class SigrokAPIInterface(SigrokInterface): print( "Used time: ", total_time * 1_000_000, - "µs | sample/s: ", - self.sample_count / (total_time), - "Hz ", + "µs", ) self.session.stop() diff --git a/lib/lennart/SigrokCLIInterface.py b/lib/lennart/SigrokCLIInterface.py index 873b226..d7347ca 100644 --- a/lib/lennart/SigrokCLIInterface.py +++ b/lib/lennart/SigrokCLIInterface.py @@ -9,7 +9,6 @@ class SigrokCLIInterface(SigrokInterface): self, bin_temp_file="temp/out.bin", sample_rate=100_000, - sample_count=1_000_000, fake=False, ): """ @@ -17,10 +16,9 @@ class SigrokCLIInterface(SigrokInterface): :param bin_temp_file: temporary file for binary output :param sample_rate: The sample rate of the Logic analyzer - :param sample_count: The sample count of the Logic analyzer :param fake: if it should use existing data """ - super(SigrokCLIInterface, self).__init__(sample_rate, sample_count) + super(SigrokCLIInterface, self).__init__(sample_rate) self.fake = fake self.bin_temp_file = bin_temp_file self.sigrok_cli_thread = None @@ -30,13 +28,15 @@ class SigrokCLIInterface(SigrokInterface): Force stopping measure, sometimes needs pkill for killing definitly :return: None """ - self.sigrok_cli_thread.send_signal(subprocess.signal.SIGKILL) - stdout, stderr = self.sigrok_cli_thread.communicate(timeout=15) - time.sleep(5) - # TODO not nice solution, make better - import os + self.sigrok_cli_thread.terminate() - os.system("pkill -f sigrok") + try: + self.sigrok_cli_thread.wait(timeout=10) + except subprocess.TimeoutExpired: + logger.warning("sigrok-cli has not stopped. Killing it.") + self.sigrok_cli_thread.kill() + + self.sigrok_cli_thread.communicate() self.runOpenAnalyze() def runMeasure(self): @@ -51,11 +51,19 @@ class SigrokCLIInterface(SigrokInterface): """ starts the measurement, not waiting for done """ - shellcommand = ( - 'sigrok-cli --output-file %s --output-format binary --samples %s -d %s --config "samplerate=%s Hz"' - % (self.bin_temp_file, self.sample_count, self.driver, self.sample_rate) - ) - self.sigrok_cli_thread = subprocess.Popen(shellcommand, shell=True) + shellcommand = [ + "sigrok-cli", + "--output-file", + self.bin_temp_file, + "--output-format", + "binary", + "--continuous", + "-d", + self.driver, + "--config", + f"samplerate={self.sample_rate} Hz", + ] + self.sigrok_cli_thread = subprocess.Popen(shellcommand) def waitForAsynchronousMeasure(self): """ diff --git a/lib/lennart/SigrokInterface.py b/lib/lennart/SigrokInterface.py index 555a25f..a5eaffc 100644 --- a/lib/lennart/SigrokInterface.py +++ b/lib/lennart/SigrokInterface.py @@ -103,18 +103,14 @@ class SigrokResult: class SigrokInterface(DataInterface): - def __init__( - self, sample_rate, sample_count, driver="fx2lafw", filename="temp/sigrok.log" - ): + def __init__(self, sample_rate, driver="fx2lafw", filename="temp/sigrok.log"): """ :param sample_rate: Samplerate of the Logic Analyzer - :param sample_count: Count of samples :param driver: for many Logic Analyzer from Saleae the "fx2lafw" should be working :param filename: temporary file name """ # options - self.sample_count = sample_count self.sample_rate = sample_rate self.file = open(filename, "w+") self.driver = driver -- cgit v1.2.3