<p id="conf_area">
Note that you need to have libdevice-serialport-perl or perl-Device-SerialPort<br>
installed and that the /dev/ttyUSBn need to be accessible by normal users.<br>
-To be able to read back values from the supply, you need an interface capable<br>
-of supplying at least 7V on the DTR line of the serial port.<br>
Feel free to alter the config file to accommodate your needs!<br>
Please don't use the # character to comment out lines<br>
+Tested with HMC8043, HMP4040, HMP4030, PSP405, PSP2010, PST3202
+<br><pre>
+//PWRSPLY:/path/to/device:Speed:Name:Type:Channels
+//PWRSPLY:IP0.0.0.0:Port:Name:Type:Channels
+PWRSPLY:/dev/ttyUSB0:9600:PST3202:PST:3
+PWRSPLY:/dev/ttyUSB0:115200:HMP4030:HMP:3
+PWRSPLY:IP192.168.0.56:5050:HMP4040:HMP:4
+PWRSPLY:/dev/FTDI_FT232R_USB_UART_AH02HFZW:2400:PSP2010:PSP:1
+PWRSPLY:/dev/FTDI_FT232R_USB_UART_A702HE33:2400:PSP405:PSP:1</pre>
+<br>
<TEXTAREA NAME="Address" id="config_field" ROWS=10 COLS=50 >
Platzhalter
</TEXTAREA>
use strict;
use warnings;
use Device::SerialPort;
+use IO::Socket;
use feature 'state';
use URI::Escape;
use Time::HiRes qw( usleep);
+use POSIX qw/floor ceil strftime/;
my $envstring = $ENV{'QUERY_STRING'};
$envstring =~ s/%20/ /g;
my $ser_type = shift(@new_command);
$ser_type = "PSP" unless defined $ser_type;
-my $ser_speed = shift(@new_command);
+my $ser_speed = shift(@new_command); #speed or port number
$ser_speed = "2400" unless defined $ser_speed;
-my $port = new Device::SerialPort($ser_dev);
-unless ($port)
-{
- print "can't open serial interface $ser_dev\n";
- exit;
-}
-$port->user_msg('ON');
-$port->baudrate($ser_speed);
-$port->parity("none");
-$port->databits(8);
-$port->stopbits(1);
-$port->handshake("xoff");
-$port->handshake("none") if $ser_type eq "HMP" or $ser_type eq "PST";
-$port->write_settings;
+my $port;
+my $isIP = 0;
+
+if($ser_dev =~ /^IP(.*)/) {
+ $ser_dev = $1;
+ $isIP = 1;
+ $port = IO::Socket::INET->new(PeerAddr => $ser_dev, PeerPort => $ser_speed, Proto => "tcp", Type => SOCK_STREAM)
+ or die "ERROR: Cannot connect: $@";
+ }
+else {
+ $port = new Device::SerialPort($ser_dev);
+ unless ($port)
+ {
+ print "can't open serial interface $ser_dev\n";
+ exit;
+ }
+
+ $port->user_msg('ON');
+ $port->baudrate($ser_speed);
+ $port->parity("none");
+ $port->databits(8);
+ $port->stopbits(1);
+ $port->handshake("xoff");
+ $port->handshake("none") if $ser_type eq "HMP" or $ser_type eq "HMC" or $ser_type eq "PST";
+ $port->write_settings;
+ }
+
# debug output
#print "attempting to communicate with power supply connected to interface:\n$ser_dev\n\n";
receive_answer() if $ser_type eq "PSP"; # always called
-print receive_answer_HMP() if $ser_type eq "HMP" or $ser_type eq "PST"; # always called
-
+print receive_answer_HMP() if (($ser_type eq "HMP" or $ser_type eq "HMC") && $isIP == 0) or $ser_type eq "PST"; # always called
+print HMP_ethernet() if (($ser_type eq "HMP" or $ser_type eq "HMC") && $isIP == 1);
# transmit_command(); # send relais off in case current maximum is reached!
sub receive_answer_HMP {
my $ret ="";
+ print strftime("%H:%M:%S &", localtime());
while ( my $command = shift(@new_command) ) {
$port->lookclear;
usleep(1000);
return $ret;
}
+
+
+sub HMP_ethernet {
+ my $ret ="";
+ print strftime("%H:%M:%S &", localtime());
+ while ( my $command = shift(@new_command) ) {
+ usleep(20000);
+ $command = uri_unescape($command);
+ print $port "$command\n";
+ if($command =~ /\?/) {
+ my $e = <$port>;
+ chomp $e;
+ $e =~ s/\&//;
+ print $e.'&';
+ }
+ }
+ return $ret;
+ }
+
+
+
print "\n";
exit 1;
<td class="state"><input type="button" onClick="turn_on(2)" value="on"><td class="state"><input type="button" onClick="turn_off(2)" value="off">
<td class="state"><input type="button" onClick="turn_on(3)" value="on"><td class="state"><input type="button" onClick="turn_off(3)" value="off">
<td class="state"><input type="button" onClick="turn_on(4)" value="on"><td class="state"><input type="button" onClick="turn_off(4)" value="off">
-
-<tr class="sep"><td colspan=5><input type="checkbox" value="1" id="showreadings">Enable read-back of values<td colspan=4>Read Settings<input type="button" onClick="readSettings()" value="Go">
+<tr class="sep"><td id="master">Global Switch<td colspan=8><input type="button" onClick="globalOn()" value="ON">
+<input type="button" onClick="globalOff()" value="OFF">
+<tr class="sep"><td colspan=5><input type="checkbox" value="1" id="showreadings">Enable read-back of values<td colspan=4>
+Read settings<input type="button" onClick="readSettings()" value="Go">
<tr><td colspan=9 id="info">
</table>
</form>
if (chan > channels) return;
var value = parseFloat(document.getElementById("form_v"+chan).value);
var command;
- if(type=="HMP") command = "INST OUT"+chan+"&VOLT "+value.toFixed(3);
+ if(type=="HMP" || type=="HMC") command = "INST OUT"+chan+"&VOLT "+value.toFixed(3);
if(type=="PST") command = ":CHAN"+chan+":VOLT "+value.toFixed(3);
new_commands.push(command);
forceShowReadings = 1;
var value = parseInt(document.getElementById("form_v_lim"+chan).value);
var command;
if(type=="HMP") command = "INST OUT"+chan+"&VOLT:PROT "+value.toFixed(3);
+ if(type=="HMC") command = "INST OUT"+chan+"&VOLT:PROT ON&VOLT:PROT:LEV "+value.toFixed(3);
if(type=="PST") command = ":CHAN"+chan+":PROT:VOLT "+value.toFixed(3);
new_commands.push(command);
forceShowReadings = 1;
if (chan > channels) return;
var value = parseFloat(document.getElementById("form_c_lim"+chan).value);
var command;
- if(type=="HMP") command = "INST OUT"+chan+"&CURR "+value.toFixed(3);
+ if(type=="HMP" || type=="HMC") command = "INST OUT"+chan+"&CURR "+value.toFixed(3);
if(type=="PST") command = ":CHAN"+chan+":PROT:CURR "+value.toFixed(3);
new_commands.push(command);
forceShowReadings = 1;
function turn_on(chan) {
if (chan > channels) return;
- if(type=="HMP") new_commands.push("INST OUT"+chan+"&OUTP ON");
+ if(type=="HMP") new_commands.push("INST OUT"+chan+"&OUTP:SEL ON");
+ if(type=="HMC") new_commands.push("INST OUT"+chan+"&OUTP:CHAN ON");
if(type=="PST") new_commands.push(":OUTP:STAT ON");
forceShowReadings = 1;
}
function turn_off(chan) {
if (chan > channels) return;
- if(type=="HMP") new_commands.push("INST OUT"+chan+"&OUTP OFF");
+ if(type=="HMP") new_commands.push("INST OUT"+chan+"&OUTP:SEL OFF");
+ if(type=="HMC") new_commands.push("INST OUT"+chan+"&OUTP:CHAN OFF");
if(type=="PST") new_commands.push(":OUTP:STAT OFF");
forceShowReadings = 1;
}
+function globalOn() {
+ if(type=="HMP") new_commands.push("OUTP:GEN ON");
+ if(type=="HMC") new_commands.push("OUTP:MAST ON");
+ forceShowReadings = 1;
+}
+
+function globalOff() {
+ if(type=="HMP") new_commands.push("OUTP:GEN OFF");
+ if(type=="HMC") new_commands.push("OUTP:MAST OFF");
+ forceShowReadings = 1;
+}
function update(data) {
updateTask = setTimeout("communication()",updaterate);
function updatereads(data) {
var e = data.split("&");
+ document.getElementById("info").innerHTML = e.shift();
+ document.getElementById("master").style.background=(e.shift()=='1')?"limegreen":"#C00";
for(i=0;i<channels;i++) {
- document.getElementById("vol"+(i+1)).value=e[i*3];
- document.getElementById("cur"+(i+1)).value=e[i*3+1];
+ document.getElementById("vol"+(i+1)).value=(+e[i*3]).toFixed(3);
+ document.getElementById("cur"+(i+1)).value=(+e[i*3+1]).toFixed(3);
document.getElementById("chan"+(i+1)).style.background=(e[i*3+2]=="1")?"limegreen":"#C00";
}
updateTask = setTimeout("communication()",updaterate);
function updatesettings(data) {
var e = data.split("&");
- var id = e.shift();
- document.getElementById("info").innerHTML = "Device Info: "+id;
+// var id = e.shift();
+ document.getElementById("info").innerHTML = e.shift()+" Device Info: "+e.shift();
+ document.getElementById("master").style.background=(e.shift()=='1')?"limegreen":"#C00";
for(i=0;i<channels;i++) {
- document.getElementById("form_v"+(i+1)).value=e[i*3];
- document.getElementById("form_c_lim"+(i+1)).value=e[i*3+1];
- document.getElementById("form_v_lim"+(i+1)).value=e[i*3+2];
+ document.getElementById("form_v"+(i+1)).value=(+e[i*3]).toFixed(3);
+ document.getElementById("form_c_lim"+(i+1)).value=(+e[i*3+1]).toFixed(3);
+ document.getElementById("form_v_lim"+(i+1)).value=(+e[i*3+2]).toFixed(3);
}
updateTask = setTimeout("communication()",updaterate);
}
}
else if(readSettingsRequest == 1) {
readSettingsRequest = 0;
- if(type=="HMP") {
+ if(type=="HMP" || type=="HMC") {
cmds = "&SYST:MIX&%2AIDN%3F";
- for(i=1;i<=channels;i++)
- cmds +="&INST OUT"+i+"&SOUR:VOLT%3F&SOUR:CURR%3F&VOLT:PROT%3F";
+ if(type=="HMP") cmds += '&OUTP:GEN%3F';
+ if(type=="HMC") cmds += '&OUTP:MAST%3F';
+ for(i=1;i<=channels;i++){
+ if(type=="HMP") cmds +="&INST OUT"+i+"&SOUR:VOLT%3F&SOUR:CURR%3F&VOLT:PROT%3F";
+ if(type=="HMC") cmds +="&INST OUT"+i+"&SOUR:VOLT%3F&SOUR:CURR%3F&VOLT:PROT:LEV%3F";
+ }
}
if(type=="PST") {
cmds="&%2AIDN%3F";
else if(document.getElementById("showreadings").checked || forceShowReadings) {
forceShowReadings = 0;
cmds = "";
- if(type=="HMP") {
+ if(type=="HMP") cmds += '&OUTP:GEN%3F';
+ if(type=="HMC") cmds += '&OUTP:MAST%3F';
+ if(type=="HMP" || type=="HMC") {
for(i=1;i<=channels;i++)
cmds +="&INST OUT"+i+"&MEAS:VOLT%3F&MEAS:CURR%3F&OUTP:STAT%3F";
}