From 05b395b9424b29ee3be9f8906d5fec7c9d484d8f Mon Sep 17 00:00:00 2001 From: Jan Michel Date: Thu, 2 May 2013 19:02:29 +0200 Subject: [PATCH] Added power supply control from Michael Wiebusch --- web/htdocs/pwr/.pwr.pl.swp | Bin 0 -> 12288 bytes web/htdocs/pwr/build_index.pl | 28 ++++++ web/htdocs/pwr/index.html | 76 ++++++++++++++++ web/htdocs/pwr/pwr.conf | 2 + web/htdocs/pwr/pwr.conf_out | 3 + web/htdocs/pwr/pwr.htm | 160 ++++++++++++++++++++++++++++++++++ web/htdocs/pwr/pwr.pl | 159 +++++++++++++++++++++++++++++++++ web/htdocs/pwr/read_conf.pl | 20 +++++ web/htdocs/pwr/save_conf.pl | 19 ++++ web/htdocs/pwr/scripts.js | 42 +++++++++ web/htdocs/pwr/styles.css | 48 ++++++++++ 11 files changed, 557 insertions(+) create mode 100644 web/htdocs/pwr/.pwr.pl.swp create mode 100755 web/htdocs/pwr/build_index.pl create mode 100644 web/htdocs/pwr/index.html create mode 100644 web/htdocs/pwr/pwr.conf create mode 100644 web/htdocs/pwr/pwr.conf_out create mode 100644 web/htdocs/pwr/pwr.htm create mode 100755 web/htdocs/pwr/pwr.pl create mode 100755 web/htdocs/pwr/read_conf.pl create mode 100755 web/htdocs/pwr/save_conf.pl create mode 100644 web/htdocs/pwr/scripts.js create mode 100644 web/htdocs/pwr/styles.css diff --git a/web/htdocs/pwr/.pwr.pl.swp b/web/htdocs/pwr/.pwr.pl.swp new file mode 100644 index 0000000000000000000000000000000000000000..f35773162d6806ccf47e3293c6fc7de90ba53a4f GIT binary patch literal 12288 zcmeI2ONZm9JlIX$I&dxeLI=eHoi-P-#Jba+?5ZE=CHItg|>X~+Xy4&vR z9X6ZAL_PR8850i@PvTwSV!Zk`AP5pY`9$ym-tc+Qe^qz0GXp}1CzBrX+nN5V>Z|Yj zSJhXuS!(6UjhpD|fgys|QbKM&^xD=d^VgA?wS+V+y}_jYBCj2r)(ow#T%;44cPodb z_3Ji0;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T zV#G(BxFRhVEAu1jbVvu$fT)ea!D@9Hly9|rr0vdjo80EG-O+B7YD?p)1*6)K(l*p? ziw6(3+mgW*WsFWX2C7FK3@yj#*lyY^O=?pH{td{Vg|+fQeZ<2fQHwGZCe%Y=ohtPB-3hGHrJ$92!!T5*BAZcQeo5e zm4{wgAq?7TFhLtEpiI}pW@zKE7}Rp8XmA>E-(ohcg{H}U)T_Ye+*2v`(&#foAJjX8 z3YXTc86FLbYNoK7cy?7G5+oCc(DE(8wd_MvzA9mDf$279{s<)*R37;;o;N^+X>bP< z$!QQ(*0utX?T@RWoIzUK%e5-5GIdpNk$!mu(Pt`jY@Fs@C!bNpr5rt)X1+)==-t=8 z3o%HOZU}ZGGSE4at1>5$cfy=%K#`VpdO?$9Nw6MMjyug}2cnzhtlg412o-G{{4lCy zRMh2F(j`&S6e&g2f>KTG@g(;#8Z<0ZbX*UrdgH6+!ip!ts$7JREO0+0w@I9hN-6%) z-9;1|wT}LR9Q0>@iz=fPG7)i_xT*X0yO=C0ff*#n-G-(Qi>(wj~Xq7gj z!ElvHx~tZv`2ZR6(q^79A?+E9}-d>!F5ug-FQL>bRbB(k@d??g)~hsscN W=tz2dN@3uaYL-*-xNp<`7WoH2x00R! literal 0 HcmV?d00001 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 -- 2.43.0