Skip to content

Commit

Permalink
Updated control classes to work with scan commands submitted from the…
Browse files Browse the repository at this point in the history
… web

interface.  This required a slight adjustment to the parsing of incoming
parameter names to allow arrays to be defined with [] after the name.
Ensure the scan command completes with a good status.
Added scan status items and populate the webpage accordingly.
  • Loading branch information
ajgdls committed Oct 24, 2017
1 parent bc75b84 commit ecc411f
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 4 deletions.
1 change: 1 addition & 0 deletions percival/detector/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ def parse_parameters(self, param_string):
params = param_string.split("&")
for param in params:
pv = param.split("=")
pv[0] = pv[0].replace("[]", "")
# Check if the parameter already exists
if pv[0] in self._parameters:
# It does, so check if it is a list
Expand Down
3 changes: 3 additions & 0 deletions percival/detector/detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,7 @@ def execute_command(self, command):
if command.has_param('steps'):
steps = int(command.get_param('steps'))
self._setpoint_control.scan_set_points(setpoints, steps, dwell)
self._active_command.complete(success=True)
else:
raise PercivalDetectorError("Number of scan steps required to scan")
else:
Expand Down Expand Up @@ -1105,6 +1106,8 @@ def read(self, parameter):
reply["setpoints"] = []
for name in self._setpoint_control.set_points:
reply["setpoints"].append(name)
reply["status"] = self._setpoint_control.get_status()
self._log.info("Setpoints: %s", reply)

elif parameter == "controls":
reply = {}
Expand Down
6 changes: 4 additions & 2 deletions percival/detector/set_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ def scan_loop(self):
def get_status(self):
status = {
"scanning": self._scanning,
"scan_index": self._scan_index,
"scan": self._scan_points
"scan_index": self._scan_index
}
if self._scan_points:
status["scan"] = str(self._scan_points)
self._log.info("Status: %s", status)
return status
36 changes: 36 additions & 0 deletions static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,42 @@ <h3>Control</h3>
<div class="row sidebar-row vertical-align">
<div class="col-xs-2">&nbsp;</div>
</div>
<div class="row sidebar-row vertical-align">
<div class="col-xs-2">Scan Set Points:</div>
<div class="col-xs-5 status vertical-align">
<small>Initial setpoint:<div class="dropdown">
<select id="scan-set-point-start">
</select>
</div></small>
<small>Final setpoint:<div class="dropdown">
<select id="scan-set-point-end">
</select>
</div></small>
<span>Number of steps:<input type="text" id="scan-sp-steps" value="10"></input></span>
<span>Dwell time (ms):<input type="text" id="scan-sp-dwell" value="1000"></input></span>
<span><button id="server-scan-set-point-cmd">Execute</button></span>
</div>
<div class="col-xs-3 status vertical-align">
<div id="sp-scan-response" class="panel panel-default">
<table>
<tr valign="top">
<td style="padding:0 15px 0 15px;">Scanning:</td><td id="sp-scan-scanning"></td>
</tr><tr>
<td style="padding:0 15px 0 15px;">Index:</td><td id="sp-scan-index"></td>
</tr><tr>
<td style="padding:0 15px 0 15px;">Scan:</td><td id="sp-scan-scanpoints"></td>
</tr>
</table>
<!--<div class="panel-heading clearfix">
<span class="panel-title pull-left">Status</span>
</div>-->
</div>
</div>

</div>
<div class="row sidebar-row vertical-align">
<div class="col-xs-2">&nbsp;</div>
</div>
<div class="row sidebar-row vertical-align">
<div class="col-xs-2">Upload Configuration File:</div>
<div class="col-xs-5 status vertical-align">
Expand Down
45 changes: 43 additions & 2 deletions static/js/percival.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ $( document ).ready(function()
$('#server-set-point-cmd').click(function(){
send_set_point_command();
});
$('#server-scan-set-point-cmd').click(function(){
send_scan_command();
});
$('#server-config-cmd').click(function(){
send_config_command();
});
Expand Down Expand Up @@ -319,6 +322,31 @@ function send_set_point_command()
$.put('/api/' + api_version + '/percival/cmd_apply_setpoint?setpoint=' + set_name, process_cmd_response);
}

function send_scan_command()
{
//data = {}
sp = [$('#scan-set-point-start').find(":selected").text(),$('#scan-set-point-end').find(":selected").text()];
//data = {'setpoints': sp};
//alert(data)
steps = $('#scan-sp-steps').val();
dwell = $('#scan-sp-dwell').val();
//$.put('/api/' + api_version + '/percival/cmd_scan_setpoints?dwell=' + dwell + '&steps=' + steps, data, process_cmd_response, 'json');
//alert('/api/' + api_version + '/percival/cmd_scan_setpoints?dwell=' + dwell + '&steps=' + steps);
$.ajax({
url: '/api/' + api_version + '/percival/cmd_scan_setpoints',
type: 'PUT',
dataType: 'json',
data: {
'dwell' : dwell,
'steps' : steps,
'setpoints' : sp
},
headers: {'Content-Type': 'application/json',
'Accept': 'application/json'},
success: process_cmd_response
});
}

function process_cmd_response(response)
{
}
Expand Down Expand Up @@ -435,7 +463,7 @@ function update_server_setup() {
}
});
$.getJSON('/api/' + api_version + '/percival/commands/', function(response) {
percival.sys_commands = response.commands
percival.sys_commands = response.commands;
html = "";
for (var index=0; index < percival.sys_commands.length; index++){
html += "<option role=\"presentation\">" + percival.sys_commands[index] + "</option>";
Expand All @@ -445,14 +473,27 @@ function update_server_setup() {
}
});
$.getJSON('/api/' + api_version + '/percival/setpoints/', function(response) {
percival.set_points = response.setpoints
//alert(response);
percival.set_points = response.setpoints;
html = "";
for (var index=0; index < percival.set_points.length; index++){
html += "<option role=\"presentation\">" + percival.set_points[index] + "</option>";
}
//alert(html);
if (html != $('#select-set-point').html()){
$('#select-set-point').html(html);
}
if (html != $('#scan-set-point-start').html()){
$('#scan-set-point-start').html(html);
}
if (html != $('#scan-set-point-end').html()){
$('#scan-set-point-end').html(html);
}
$('#sp-scan-scanning').text(response.status.scanning);
$('#sp-scan-index').text(response.status.scan_index);
if (response.status.scan){
$('#sp-scan-scanpoints').text(response.status.scan);
}
});
}

Expand Down

0 comments on commit ecc411f

Please sign in to comment.