--- /dev/null
+#!/usr/bin/perl -w
+use Cwd;
+#print "Content-type: text/html\n\n";
+
+my $pwd = &Cwd::cwd();
+
+
+open(LESEN,"htdocs/pwr/pwr.conf")
+ or die "Fehler beim oeffnen von : $!\n";
+
+while(defined(my $i = <LESEN>)) {
+
+ if( $i =~ /^PWRSPLY:([^:]+):([^:]+)/g ) {
+ my $ser_dev=$1;
+ my $dev_id=$2;
+
+print <<EOF;
+<p>
+<iframe name="inlineframe" src="pwr.htm?device=$ser_dev&id=$dev_id" frameborder="0" scrolling="auto" width="800" height="340" ></iframe>
+</p>
+EOF
+ }
+}
+
+#print "CWD: ".$pwd."<br>(for debug)\n";
+
+
+return true;
--- /dev/null
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+ <html>
+ <head>
+ <link href="../layout/styles.css" rel="stylesheet" type="text/css"/>
+<script src="scripts.js" type="text/javascript"></script>
+ <title>Access all POWER!</title>
+
+ </head>
+
+ <body>
+<h2>Basic power supply control</h2>
+<p id="content">
+Platzhalter
+</p>
+
+<script language="javascript">
+
+function update(data) {
+ if(!document.getElementById("content").innerHTML) return;
+ document.getElementById("content").innerHTML = data;
+ }
+
+getdata('build_index.pl',update);
+</script>
+
+<p id="conf_area">
+Note that you need to have libdevice-serialport-perl or perl-Device-SerialPort
+installed and that the /dev/ttyUSBn need to be accessible by normal users.<br>
+Feel free to alter the config file to accommodate your needs!<br>
+Please don't use the # character to comment out lines<br>
+<TEXTAREA NAME="Address" id="config_field" ROWS=10 COLS=50 >
+Platzhalter
+</TEXTAREA>
+<br>
+<input type="button" onClick="save_conf()" value="save">
+<input type="button" onClick="reload_page()" value="reload page">
+
+<script language="javascript">
+
+function save_conf() {
+ var field_content = document.getElementById("config_field").value;
+ field_content = field_content.replace(/\n\r?/g, '&');
+ //alert(field_content);
+ getdata('save_conf.pl?'+field_content,alert);
+
+ //debug//document.getElementById("content").innerHTML = field_content;
+ }
+
+function reload_page() {
+ window.location.reload();
+}
+
+function write_field(data) {
+ if(!document.getElementById("config_field").value) return;
+ document.getElementById("config_field").value = data;
+ }
+
+
+getdata('read_conf.pl',write_field);
+</script>
+
+</p>
+
+
+ </body>
+
+ </html>
+
+
+
+
+
+
+
+
--- /dev/null
+//PWRSPLY:/path/to/device:Device_ID
+PWRSPLY:/dev/ttyUSB0:PWR_DEFAULT
\ No newline at end of file
--- /dev/null
+PWRSPLY:/dev/ttyUSB0:Device_1
+PWRSPLY:/dev/ttyUSB1:Device_2
+PWRSPLY:/dev/ttyUSB2:Device_3
--- /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>
+
+
+<table align=center id="layout" style="
+ border-width: 1px;
+ border-style: solid;
+ border-color: black;
+">
+
+<tr>
+<th align="left">Readings:</th><TD rowspan=2 style="border-left: 1px solid black; padding: 5px;"> <th align="left">Settings:</th>
+</tr>
+
+<tr>
+<td>
+
+<table id="readings" width="300" >
+</table>
+</td>
+
+
+
+
+<td>
+
+<form acion="">
+<table id="settings" >
+<tr>
+<td align="right">Voltage [V]<td><input type="text" id="form_v" name="voltage" value="">
+<td><input type="button" onClick="set_v()" value="set">
+<tr><td colspan=3><hr />
+<tr>
+<td align="right">Voltage limit [V]<td><input type="text" id="form_v_lim" name="voltage_limit" value="">
+<td><input type="button" onClick="set_v_lim()" value="set">
+<tr><td align="right">Current limit [A]<td><input type="text" id="form_c_lim" name="current_limit" value="">
+<td><input type="button" onClick="set_c_lim()" value="set">
+<tr><td align="right">Power limit [W]<td><input type="text" id="form_p_lim" name="power_limit" value="">
+<td><input type="button" onClick="set_p_lim()" value="set">
+<tr><td colspan=2>Save settings to EEPROM<td><input type="button" onClick="save_to_eep()" value="save">
+<tr><td colspan=3><hr />
+
+<tr>
+<tr><td colspan=2>Output Relais<td><input type="button" onClick="turn_on()" value="on"><input type="button" onClick="turn_off()" value="off">
+<tr><td colspan=3><hr />
+<tr><td colspan=3><input type="checkbox" value="1" id="showreadings">Enable read-back of values.
+</table>
+</form>
+
+</td>
+</tr>
+</table>
+
+
+
+
+<script language="javascript">
+var updaterate = 500;
+var updateTask;
+var new_commands = new Array();
+var ser_dev = getParameterByName("device");
+var dev_id = getParameterByName("id")
+
+
+function set_v() {
+ var value = parseFloat(document.getElementById("form_v").value);
+ var command = "SV "+padZeros(value.toFixed(2),5);
+ new_commands.push(command);
+}
+
+function set_v_lim() {
+ var value = parseInt(document.getElementById("form_v_lim").value);
+ var command = "SU "+padZeros(value,2);
+ new_commands.push(command);
+}
+
+function set_c_lim() {
+ var value = parseFloat(document.getElementById("form_c_lim").value);
+ var command = "SI "+padZeros(value.toFixed(2),4);
+ new_commands.push(command);
+}
+
+function set_p_lim() {
+ var value = parseInt(document.getElementById("form_p_lim").value);
+ var command = "SP "+padZeros(value,3);
+ new_commands.push(command);
+}
+
+function turn_on() {
+ new_commands.push("KOE");
+}
+
+function turn_off() {
+ new_commands.push("KOD");
+}
+
+function save_to_eep() {
+ new_commands.push("EEP");
+}
+
+function update(data) {
+ if(!document.getElementById("readings").innerHTML) return;
+ document.getElementById("readings").innerHTML = data;
+updateTask = setInterval("communication()",updaterate);
+ }
+
+
+function communication() {
+// getdata('pwr.pl?/dev/ttyUSB0-KOD',update);
+ cmds = new_commands.join('&');
+ if (cmds != "" || document.getElementById("showreadings").checked) {
+ clearInterval(updateTask);
+ getdata('pwr.pl?'+ser_dev+'&'+cmds,update);
+ }
+ 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>
--- /dev/null
+#!/usr/bin/perl -w
+#print "Content-type: text/html\n\n";
+
+
+use strict;
+use warnings;
+use Device::SerialPort;
+use feature 'state';
+use Time::HiRes qw( usleep);
+
+my $envstring = $ENV{'QUERY_STRING'};
+$envstring =~ s/%20/ /g;
+
+
+my @new_command = split('&',$envstring);
+my $ser_dev = shift(@new_command);
+$ser_dev = "/dev/ttyUSB0" unless defined $ser_dev;
+
+
+
+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(2400);
+$port->parity("none");
+$port->databits(8);
+$port->stopbits(1);
+$port->handshake("xoff");
+$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(); # send relais off in case current maximum is reached!
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+sub transmit_command {
+
+$port->lookclear;
+
+while ( my $command = shift(@new_command) ) {
+
+ $port->write("$command\r");
+ #print "i sent the command: $command";
+ #print "\n\nokay.\n";
+ usleep 1E5;
+ }
+}
+
+
+
+
+sub receive_answer {
+
+
+
+
+ my %state_lookup = (
+ 0 => 'off',
+ 1 => 'on' );
+
+ my $found = 0;
+
+
+
+ # clear buffers, then send the "list"-command to the power supply
+ $port->lookclear;
+ $port->write("L\r");
+ # sleep a second to give the supply time to react
+ usleep 1E5;
+
+ # read what has accumulated in the serial buffer
+ while(my $a = $port->lookfor) {
+ #print $a."\n"; # debug output
+ if ($a =~ m/V(\d\d\.\d\d)A(\d\.\d\d\d)W(\d\d\d\.\d)U(\d\d)I(\d\.\d\d)P(\d\d\d)F(\d\d\d\d\d\d)/) {
+ $found = 1;
+ my $c_volt = $1;
+ my $c_cur = $2;
+ my $c_pwr = $3;
+ my $l_volt = $4;
+ my $l_cur = $5;
+ my $l_pwr = $6;
+ my $state_string = $7;
+ my $relais_state = $state_lookup{substr $state_string, 0,1};
+ printf("
+ <table>
+ <tr>
+ <td align=right>%2.2f<td align=left> V
+ <tr>
+ <td align=right>%1.3f<td align=left> A
+ <tr>
+ <td align=right>%3.1f<td align=left> W
+ <tr>
+ <tr>
+ <td align=right>voltage limit: %d<td align=left> V
+ <tr>
+ <td align=right>current limit: %1.2f<td align=left> A
+ <tr>
+ <td align=right>power limit: %d<td align=left> W
+ <tr>
+ <tr>
+ <td align=right>output relais:<td align=left> $relais_state </td>
+ </table>"
+ ,$c_volt,$c_cur,$c_pwr,$l_volt,$l_cur,$l_pwr);
+
+# if( $c_cur > 0) {
+# if($c_cur > ($l_cur * 0.9) ) { # check if current limit reached, if so, turn power off!
+# print "!!! current limit reached, power off !!!<br>";
+# push(@new_command,"KOD");
+# }
+# }
+
+ last;
+
+ }
+ }
+
+
+
+
+ if($found) {
+
+ print "connection ok <br>";
+ } else {
+ print "!!! power supply not responding !!!<br>";
+ }
+
+ print " \n";
+
+
+
+
+
+
+
+}
+exit 1;
--- /dev/null
+#!/usr/bin/perl -w
+#print "Content-type: text/html\r\n\r\n";
+
+use Cwd;
+
+my $pwd = &Cwd::cwd();
+
+
+open(LESEN,"htdocs/pwr/pwr.conf")
+ or print "Fehler beim oeffnen von : $!\n";
+
+while(defined(my $i = <LESEN>)) {
+
+print $i;
+
+ }
+
+
+
+return true;
--- /dev/null
+#!/usr/bin/perl -w
+
+
+my $envstring = $ENV{'QUERY_STRING'};
+$envstring =~ s/%20/ /g;
+$envstring =~ s/&/\n/g;
+##$envstring =~ s/&/\n/g;
+
+
+open(SCHREIBEN,">htdocs/pwr/pwr.conf")
+ or print "Fehler beim oeffnen von : $!\n";
+
+print SCHREIBEN $envstring;
+close(SCHREIBEN);
+
+print "saved!";
+
+
+return true;
--- /dev/null
+
+
+function getdata(command,callback) {
+ var xmlhttp = null;
+ var cb = null;
+ xmlhttp=new XMLHttpRequest();
+ cb = callback;
+
+ xmlhttp.onreadystatechange = function() {
+ if(xmlhttp.readyState == 4) {
+ if(cb)
+ cb(xmlhttp.responseText);
+ }
+ }
+ xmlhttp.open("GET",command,true);
+ xmlhttp.send(null);
+ }
+
+
+// function reload() {
+// xmlhttp=new XMLHttpRequest();
+// xmlhttp.onreadystatechange = function() {
+// if(xmlhttp.readyState == 4) {
+// document.getElementById("content").innerHTML=xmlhttp.responseText;
+// if(document.getElementById('logbox')) {
+// if(saveScrollTop) {
+// document.getElementById('logbox').scrollTop = saveScrollTop;
+// }
+// }
+//
+// document.getElementById("stop").style.background="#444";
+// reloadevery = setTimeout('reload()',$.($delay*1000).qq$);
+// }
+// };
+// if(document.getElementById('logbox')) {
+// saveScrollTop = document.getElementById('logbox').scrollTop;
+// if (saveScrollTop == 0) {saveScrollTop = 0.1;}
+// }
+// xmlhttp.open("GET","get.cgi?$.$ENV{'QUERY_STRING'}.qq$",true);
+// xmlhttp.send(null);
+// document.getElementById("stop").style.background="#111";
+// }
\ No newline at end of file
--- /dev/null
+body {
+ background:#eee;
+}
+
+
+table#content, table#contentregs {
+ border:1px solid #aaa;
+ border-collapse:collapse;
+}
+
+
+table#content td, table#content th, table#contentregs td, table#contentregs th{
+ border:1px solid #aaa;
+ width:100px;
+ text-align:right;
+ padding-right:15px;
+}
+
+table#content, table#contentregs {
+ border:1px solid #aaa;
+}
+
+
+div#bar1 {
+ width:900px;
+ overflow-x:scroll;
+ }
+
+div#bar1 div {
+ width:66500px;
+ height:0px;
+}
+
+div#bar2 {
+ width:900px;
+ overflow-x:scroll;
+ }
+
+div#bar2 div {
+ width:65536px;
+ height:0px;
+}
+
+
+#total {
+ text-align:center;
+ font-weight:bold;
+ }
\ No newline at end of file