From 851a854f21c7a9a410f5d54b6a044cb4a0fc09f9 Mon Sep 17 00:00:00 2001 From: Alexandre Gobbo Date: Mon, 14 May 2018 17:19:16 +0200 Subject: [PATCH] bsget include module, offset and timeout as parameters --- src/main/assembly/script/Lib/startup.js | 10 ++++++++-- src/main/assembly/script/Lib/startup.py | 19 ++++++++----------- src/main/java/ch/psi/pshell/bs/Stream.java | 6 +++--- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/main/assembly/script/Lib/startup.js b/src/main/assembly/script/Lib/startup.js index bb3846fa..9367888d 100644 --- a/src/main/assembly/script/Lib/startup.js +++ b/src/main/assembly/script/Lib/startup.js @@ -2071,17 +2071,23 @@ function string_to_obj(o) { return o } -function bsget(channel){ +function bsget(channel, modulo, offset, timeout){ /* Reads an values a bsread stream, using the default provider. Args: channel(str or list of str): channel name(s) + module(int, optional): stream modulo + offset(int, optional): stream offset + timeout(float, optional): stream timeout in secs Returns: BS value or list of values */ + if (!is_defined(modulo)) modulo = 1 + if (!is_defined(offset)) offset = 0 + if (!is_defined(timeout)) timeout=5.0 var channels = (typeof channel === 'string')? [channel]: channel - var ret = Stream.readChannels(channels) + var ret = Stream.readChannels(channels, modulo, offset, timeout*1000) if (typeof channel === 'string') { return ret[0] } diff --git a/src/main/assembly/script/Lib/startup.py b/src/main/assembly/script/Lib/startup.py index 4bca1dde..8d314a52 100644 --- a/src/main/assembly/script/Lib/startup.py +++ b/src/main/assembly/script/Lib/startup.py @@ -687,8 +687,6 @@ def onAfterPass(self, num_pass): on_after_scan_pass(self, num_pass) readables=to_list(string_to_obj(readables)) - #TODO: Calling through abstract would enForce the constructor signature, but is not working - #scan = ch.psi.pshell.scan.HardwareScan.newScan(HardwareScan, config, writable,readables, start, end , steps, passes, zigzag) scan = HardwareScan(config, writable,readables, start, end , steps, int(passes), zigzag) processScanPars(scan, pars) scan.start() @@ -954,7 +952,6 @@ def get_plots(title=None): ArrayList of Plot objects. """ - return get_context().getPlots(title) def get_plot_snapshots(title = None, file_type = "png", size = None, temp_path = get_context().setup.getContextPath()): @@ -1125,7 +1122,6 @@ def append_table(path, data): None """ - #data = to_array(data) if is_list(data): arr = java.lang.reflect.Array.newInstance(Class.forName("java.lang.Object"),len(data)) for i in range (len(data)): @@ -1217,7 +1213,6 @@ def set_exec_pars(**args): """ get_context().setExecutionPars(args) -#TODO: Change return to dictionary def get_exec_pars(): """ Returns script execution parameters. @@ -2244,18 +2239,21 @@ def exec_cpython(script_name, args = [], method_name = None, python_name = "pyth jsonret = ret[ret.rfind('\n')+1:].strip() return json.loads(jsonret) -def bsget(channel): +def bsget(channel, modulo=1, offset=0, timeout = 5.0): """Reads an values a bsread stream, using the default provider. Args: channel(str or list of str): channel name(s) + module(int, optional): stream modulo + offset(int, optional): stream offset + timeout(float, optional): stream timeout in secs Returns: BS value or list of values """ channels = to_list(channel) - ret = Stream.readChannels(channels) - if type(channel) is str: + ret = Stream.readChannels(channels, modulo, offset, int(timeout * 1000)) + if is_string(channel): return ret[0] return ret @@ -2275,7 +2273,6 @@ def flatten(data): import itertools return itertools.chain(*data) -#Float range -> Useful for scanning is a range def frange_gen(start, finish, step): while ((step >= 0.0) and (start <= finish)) or ((step < 0.0) and (start >= finish)): yield start @@ -2366,7 +2363,7 @@ def _getBuiltinFunctionNames(filter = None): return to_array(ret) def _getFunctionDoc(function): - if type(function) is str: + if is_string(function): if function not in globals(): return function = globals()[function] @@ -2525,6 +2522,6 @@ def show_panel(device, title=None): if type(device) is BufferedImage: device = DirectSource(title, device) device.initialize() - if type(device) is str: + if is_string(device): device = get_device(device) return get_context().showPanel(device) diff --git a/src/main/java/ch/psi/pshell/bs/Stream.java b/src/main/java/ch/psi/pshell/bs/Stream.java index eaf6b7c8..8829b615 100644 --- a/src/main/java/ch/psi/pshell/bs/Stream.java +++ b/src/main/java/ch/psi/pshell/bs/Stream.java @@ -580,15 +580,15 @@ public Object getValue(int index) { return getCurrentValue().getValue(index); } - public static List readChannels(List names) throws IOException, InterruptedException { + public static List readChannels(List names, int modulo, int offset, int timeout) throws IOException, InterruptedException { Stream stream = new Stream(null); try { for (String name : names) { - stream.addScalar(name, name, 1, 0); + stream.addScalar(name, name, modulo, offset); } stream.initialize(); stream.start(); - stream.waitValueNot(null, 5000); + stream.waitValueNot(null, timeout); return stream.getValues(); } finally { stream.close();