Skip to content

Commit

Permalink
bsget include module, offset and timeout as parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgobbo committed May 14, 2018
1 parent 75e6795 commit 851a854
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
10 changes: 8 additions & 2 deletions src/main/assembly/script/Lib/startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
Expand Down
19 changes: 8 additions & 11 deletions src/main/assembly/script/Lib/startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()):
Expand Down Expand Up @@ -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)):
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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)
6 changes: 3 additions & 3 deletions src/main/java/ch/psi/pshell/bs/Stream.java
Original file line number Diff line number Diff line change
Expand Up @@ -580,15 +580,15 @@ public Object getValue(int index) {
return getCurrentValue().getValue(index);
}

public static List readChannels(List<String> names) throws IOException, InterruptedException {
public static List readChannels(List<String> 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();
Expand Down

0 comments on commit 851a854

Please sign in to comment.