From: Jan Michel Date: Thu, 2 May 2013 17:02:29 +0000 (+0200) Subject: Added power supply control from Michael Wiebusch X-Git-Url: https://jspc29.x-matter.uni-frankfurt.de/git/?a=commitdiff_plain;h=05b395b9424b29ee3be9f8906d5fec7c9d484d8f;p=daqtools.git Added power supply control from Michael Wiebusch --- diff --git a/web/htdocs/pwr/.pwr.pl.swp b/web/htdocs/pwr/.pwr.pl.swp new file mode 100644 index 0000000..f357731 Binary files /dev/null and b/web/htdocs/pwr/.pwr.pl.swp differ diff --git a/web/htdocs/pwr/build_index.pl b/web/htdocs/pwr/build_index.pl new file mode 100755 index 0000000..fde757e --- /dev/null +++ b/web/htdocs/pwr/build_index.pl @@ -0,0 +1,28 @@ +#!/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 = )) { + + if( $i =~ /^PWRSPLY:([^:]+):([^:]+)/g ) { + my $ser_dev=$1; + my $dev_id=$2; + +print < + +

+EOF + } +} + +#print "CWD: ".$pwd."
(for debug)\n"; + + +return true; diff --git a/web/htdocs/pwr/index.html b/web/htdocs/pwr/index.html new file mode 100644 index 0000000..1caf55f --- /dev/null +++ b/web/htdocs/pwr/index.html @@ -0,0 +1,76 @@ + + + + + + + Access all POWER! + + + + +

Basic power supply control

+

+Platzhalter +

+ + + +

+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.
+Feel free to alter the config file to accommodate your needs!
+Please don't use the # character to comment out lines
+ +
+ + + + + +

+ + + + + + + + + + + + + diff --git a/web/htdocs/pwr/pwr.conf b/web/htdocs/pwr/pwr.conf new file mode 100644 index 0000000..5e6e030 --- /dev/null +++ b/web/htdocs/pwr/pwr.conf @@ -0,0 +1,2 @@ +//PWRSPLY:/path/to/device:Device_ID +PWRSPLY:/dev/ttyUSB0:PWR_DEFAULT \ No newline at end of file diff --git a/web/htdocs/pwr/pwr.conf_out b/web/htdocs/pwr/pwr.conf_out new file mode 100644 index 0000000..8f4bdb9 --- /dev/null +++ b/web/htdocs/pwr/pwr.conf_out @@ -0,0 +1,3 @@ +PWRSPLY:/dev/ttyUSB0:Device_1 +PWRSPLY:/dev/ttyUSB1:Device_2 +PWRSPLY:/dev/ttyUSB2:Device_3 diff --git a/web/htdocs/pwr/pwr.htm b/web/htdocs/pwr/pwr.htm new file mode 100644 index 0000000..bf4f3af --- /dev/null +++ b/web/htdocs/pwr/pwr.htm @@ -0,0 +1,160 @@ + + + + + + +Power Supply Monitor and Access + + + + +

Power Supply Access

+ + + + + + + + + + + + + + + + +
Readings: Settings:
+ + +
+
+ +
+ + + + +
Voltage [V] + +

+
Voltage limit [V] + +
Current limit [A] + +
Power limit [W] + +
Save settings to EEPROM +

+ +
Output Relais +

+
Enable read-back of values. +
+
+ +
+ + + + + + diff --git a/web/htdocs/pwr/pwr.pl b/web/htdocs/pwr/pwr.pl new file mode 100755 index 0000000..2e174ef --- /dev/null +++ b/web/htdocs/pwr/pwr.pl @@ -0,0 +1,159 @@ +#!/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(" + + + + + + + + + + + +
%2.2f V +
%1.3f A +
%3.1f W +
voltage limit: %d V +
current limit: %1.2f A +
power limit: %d W +
output relais: $relais_state
" + ,$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 !!!
"; +# push(@new_command,"KOD"); +# } +# } + + last; + + } + } + + + + + if($found) { + + print "connection ok
"; + } else { + print "!!! power supply not responding !!!
"; + } + + print " \n"; + + + + + + + +} +exit 1; diff --git a/web/htdocs/pwr/read_conf.pl b/web/htdocs/pwr/read_conf.pl new file mode 100755 index 0000000..8153541 --- /dev/null +++ b/web/htdocs/pwr/read_conf.pl @@ -0,0 +1,20 @@ +#!/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 = )) { + +print $i; + + } + + + +return true; diff --git a/web/htdocs/pwr/save_conf.pl b/web/htdocs/pwr/save_conf.pl new file mode 100755 index 0000000..3fdd270 --- /dev/null +++ b/web/htdocs/pwr/save_conf.pl @@ -0,0 +1,19 @@ +#!/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; diff --git a/web/htdocs/pwr/scripts.js b/web/htdocs/pwr/scripts.js new file mode 100644 index 0000000..016187c --- /dev/null +++ b/web/htdocs/pwr/scripts.js @@ -0,0 +1,42 @@ + + +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 diff --git a/web/htdocs/pwr/styles.css b/web/htdocs/pwr/styles.css new file mode 100644 index 0000000..b7e3b6f --- /dev/null +++ b/web/htdocs/pwr/styles.css @@ -0,0 +1,48 @@ +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