var updateTask;
var new_commands = new Array();
var ser_dev = getParameterByName("device");
-var dev_id = getParameterByName("id")
-
+var dev_id = getParameterByName("id");
+var type = getParameterByName("type");
function set_v() {
var value = parseFloat(document.getElementById("form_v").value);
}
function turn_on() {
- new_commands.push("KOE");
+ if(type=="PSP") new_commands.push("KOE");
}
function turn_off() {
- new_commands.push("KOD");
+ if(type=="PSP") new_commands.push("KOD");
}
function save_to_eep() {
- new_commands.push("EEP");
+ if(type=="PSP") new_commands.push("EEP");
}
function update(data) {
cmds = new_commands.join('&');
if (cmds != "" || document.getElementById("showreadings").checked) {
clearInterval(updateTask);
- getdata('pwr.pl?'+ser_dev+'&'+cmds,update);
+ getdata('pwr.pl?'+ser_dev+'&'+type+'&'+cmds,update);
}
new_commands = new Array();
}
use warnings;
use Device::SerialPort;
use feature 'state';
+use URI::Escape;
use Time::HiRes qw( usleep);
my $envstring = $ENV{'QUERY_STRING'};
my $ser_dev = shift(@new_command);
$ser_dev = "/dev/ttyUSB0" unless defined $ser_dev;
-
+my $ser_type = shift(@new_command);
+$ser_type = "PSP" unless defined $ser_type;
my $port = new Device::SerialPort($ser_dev);
unless ($port)
}
$port->user_msg('ON');
-$port->baudrate(2400);
+$port->baudrate(2400) if $ser_type eq "PSP";
+$port->baudrate(115200) if $ser_type eq "HMP";
$port->parity("none");
$port->databits(8);
$port->stopbits(1);
-$port->handshake("xoff");
+$port->handshake("xoff");
+$port->handshake("none") if $ser_type eq "HMP";
$port->write_settings;
# debug output
#print "attempting to communicate with power supply connected to interface:\n$ser_dev\n\n";
-transmit_command(); #if new command, send it!
-receive_answer(); # always called
+transmit_command() if $ser_type eq "PSP"; #if new command, send it!
+receive_answer() if $ser_type eq "PSP"; # always called
+
+
+receive_answer_HMP() if $ser_type eq "HMP"; # always called
+
# transmit_command(); # send relais off in case current maximum is reached!
$port->lookclear;
while ( my $command = shift(@new_command) ) {
-
- $port->write("$command\r");
- #print "i sent the command: $command";
- #print "\n\nokay.\n";
- usleep 1E5;
- }
+ $command = uri_unescape($command);
+ $port->write("$command\r\n");
+ print "i sent the command: $command";
+ #print "\n\nokay.\n";
+ usleep 1E5;
+ }
}
}
}
-
-
-
-
- if($found) {
-
- print "connection ok <br>";
- } else {
- print "!!! power supply not responding !!!<br>";
}
-
- print " \n";
-
-
-
-
-
-
-}
+sub receive_answer_HMP {
+
+ while ( my $command = shift(@new_command) ) {
+ $port->lookclear;
+ $command = uri_unescape($command);
+ $port->write("$command\r\n");
+# print "i sent the command: $command\n";
+ #print "\n\nokay.\n";
+ usleep 1E5;
+ while(my $a = $port->lookfor) {
+ print $a."&"; # debug output
+ }
+ }
+ }
+
+print "\n";
+
exit 1;
--- /dev/null
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
+<link href="styles.css" rel="stylesheet" type="text/css"/>
+<script src="scripts.js" type="text/javascript"></script>
+<title>Power Supply Monitor and Access</title>
+</head>
+<body style="font-family: sans-serif;" >
+
+
+<p style="bold" id="headline">Power Supply Access</p>
+
+
+
+<form acion="">
+<table id="settings" class="smallboxes">
+<tr><th><th colspan=2>Chan 1<th colspan=2>Chan 2<th colspan=2>Chan 3<th colspan=2>Chan 4
+<tr class="sep"><td align="right">Voltage [V]
+ <td><input type="text" id="form_v1" name="voltage" value=""><td><input type="button" onClick="set_v(1)" value="set">
+ <td><input type="text" id="form_v2" name="voltage" value=""><td><input type="button" onClick="set_v(2)" value="set">
+ <td><input type="text" id="form_v3" name="voltage" value=""><td><input type="button" onClick="set_v(3)" value="set">
+ <td><input type="text" id="form_v4" name="voltage" value=""><td><input type="button" onClick="set_v(4)" value="set">
+
+<tr><td align="right">Actual[V/A]
+ <td> <input type="text" id="vol1" disabled> <td> <input type="text" id="cur1" disabled>
+ <td> <input type="text" id="vol2" disabled> <td> <input type="text" id="cur2" disabled>
+ <td> <input type="text" id="vol3" disabled> <td> <input type="text" id="cur3" disabled>
+ <td> <input type="text" id="vol4" disabled> <td> <input type="text" id="cur4" disabled>
+
+<tr><td align="right">Limits[V/A]
+ <td><input type="text" id="form_v_lim1" name="voltage_limit" onChange="set_v_lim(1)" value=""><td><input type="text" id="form_c_lim1" name="current_limit" onChange="set_c_lim(1)" value="">
+ <td><input type="text" id="form_v_lim2" name="voltage_limit" onChange="set_v_lim(2)" value=""><td><input type="text" id="form_c_lim2" name="current_limit" onChange="set_c_lim(2)" value="">
+ <td><input type="text" id="form_v_lim3" name="voltage_limit" onChange="set_v_lim(3)" value=""><td><input type="text" id="form_c_lim3" name="current_limit" onChange="set_c_lim(3)" value="">
+ <td><input type="text" id="form_v_lim4" name="voltage_limit" onChange="set_v_lim(4)" value=""><td><input type="text" id="form_c_lim4" name="current_limit" onChange="set_c_lim(4)" value="">
+
+<tr class="sep"><td>Output Relais
+ <td><td><input type="button" onClick="turn_on(1)" value="on"><br><input type="button" onClick="turn_off(1)" value="off">
+ <td><td><input type="button" onClick="turn_on(2)" value="on"><br><input type="button" onClick="turn_off(2)" value="off">
+ <td><td><input type="button" onClick="turn_on(3)" value="on"><br><input type="button" onClick="turn_off(3)" value="off">
+ <td><td><input type="button" onClick="turn_on(4)" value="on"><br><input type="button" onClick="turn_off(4)" value="off">
+
+<tr><td colspan=9><input type="checkbox" value="1" id="showreadings">Enable read-back of values.
+</table>
+</form>
+
+
+
+
+<div id="readings" width="300" >
+</div>
+
+
+<script language="javascript">
+var updaterate = 500;
+var updateTask;
+var new_commands = new Array();
+var ser_dev = getParameterByName("device");
+var dev_id = getParameterByName("id");
+var type = getParameterByName("type");
+var channels = getParameterByName("channels");
+
+
+function set_v(chan) {
+ var value = parseFloat(document.getElementById("form_v"+chan).value);
+ var command;
+ if(type=="HMP") command = "INST OUT"+chan+"&VOLT "+value.toFixed(3);
+ new_commands.push(command);
+}
+
+function set_v_lim(chan) {
+ var value = parseInt(document.getElementById("form_v_lim"+chan).value);
+ var command;
+ if(type=="HMP") command = "INST OUT"+chan+"&VOLT:PROT "+value.toFixed(3);
+ new_commands.push(command);
+}
+
+function set_c_lim(chan) {
+ var value = parseFloat(document.getElementById("form_c_lim"+chan).value);
+ var command;
+ if(type=="HMP") command = "INST OUT"+chan+"&CURR "+value.toFixed(3);
+ new_commands.push(command);
+}
+
+function turn_on(chan) {
+ if(type=="HMP") new_commands.push("INST OUT"+chan+"&OUTP ON");
+}
+
+function turn_off(chan) {
+ if(type=="HMP") new_commands.push("INST OUT"+chan+"&OUTP OFF");
+}
+
+
+function update(data) {
+ updateTask = setInterval("communication()",updaterate);
+ }
+
+
+function updatereads(data) {
+ if(document.getElementById("readings"))
+ document.getElementById("readings").innerHTML=data;
+ var e = data.split("&");
+ for(i=0;i<channels;i++) {
+ document.getElementById("vol"+(i+1)).value=e[i*2];
+ document.getElementById("cur"+(i+1)).value=e[i*2+1];
+ }
+ updateTask = setInterval("communication()",updaterate);
+ }
+
+function communication() {
+ cmds = new_commands.join('&');
+ if (cmds != "") {
+ clearInterval(updateTask);
+ getdata('pwr.pl?'+ser_dev+'&'+type+'&'+cmds,update);
+ }
+ else if(document.getElementById("showreadings").checked) {
+ clearInterval(updateTask);
+ cmds = "";
+ for(i=1;i<=channels;i++)
+ cmds +="&INST OUT"+i+"&MEAS:VOLT%3F&MEAS:CURR%3F";
+ getdata('pwr.pl?'+ser_dev+'&'+type+cmds,updatereads);
+ }
+ new_commands = new Array();
+}
+
+
+function padZeros(theNumber, max) {
+ var numStr = String(theNumber);
+
+ while ( numStr.length < max) {
+ numStr = '0' + numStr;
+ }
+
+ return numStr;
+}
+
+
+function getParameterByName(name)
+{
+ name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
+ var regexS = "[\\?&]" + name + "=([^&#]*)";
+ var regex = new RegExp(regexS);
+ var results = regex.exec(window.location.search);
+ if(results == null)
+ return "";
+ else
+ return decodeURIComponent(results[1].replace(/\+/g, " "));
+}
+
+
+
+
+updateTask = setInterval("communication()",updaterate);
+document.getElementById("headline").innerHTML = "Power Supply "+'<b>'+dev_id+'</b>'+" [connected to "+'<b>'+ser_dev+'</b>'+"]" ;
+
+
+</script>
+</body></html>