From c5e2f143199425641515dfd87fb29562bcd11999 Mon Sep 17 00:00:00 2001 From: Michael Wiebusch Date: Mon, 13 May 2013 15:56:08 +0200 Subject: [PATCH] added support for Vacom MVC-3 pressure readout controller --- RasPi_slow_control_suite/README.txt | 14 +- .../www/tools/pressure/.pwr.pl.swp | Bin 0 -> 12288 bytes .../www/tools/pressure/build_index.pl | 35 ++ .../www/tools/pressure/delete_log.pl | 31 ++ .../www/tools/pressure/device.htm | 185 ++++++++++ .../www/tools/pressure/devices.conf | 5 + .../www/tools/pressure/index.html | 76 +++++ .../www/tools/pressure/plot.pl | 323 ++++++++++++++++++ .../www/tools/pressure/read_conf.pl | 20 ++ .../www/tools/pressure/save_conf.pl | 20 ++ .../www/tools/pressure/scripts.js | 43 +++ .../www/tools/pressure/shm | 1 + .../www/tools/pressure/styles.css | 48 +++ 13 files changed, 800 insertions(+), 1 deletion(-) create mode 100644 RasPi_slow_control_suite/www/tools/pressure/.pwr.pl.swp create mode 100755 RasPi_slow_control_suite/www/tools/pressure/build_index.pl create mode 100755 RasPi_slow_control_suite/www/tools/pressure/delete_log.pl create mode 100644 RasPi_slow_control_suite/www/tools/pressure/device.htm create mode 100644 RasPi_slow_control_suite/www/tools/pressure/devices.conf create mode 100644 RasPi_slow_control_suite/www/tools/pressure/index.html create mode 100755 RasPi_slow_control_suite/www/tools/pressure/plot.pl create mode 100755 RasPi_slow_control_suite/www/tools/pressure/read_conf.pl create mode 100755 RasPi_slow_control_suite/www/tools/pressure/save_conf.pl create mode 100644 RasPi_slow_control_suite/www/tools/pressure/scripts.js create mode 120000 RasPi_slow_control_suite/www/tools/pressure/shm create mode 100644 RasPi_slow_control_suite/www/tools/pressure/styles.css diff --git a/RasPi_slow_control_suite/README.txt b/RasPi_slow_control_suite/README.txt index f721324..be00ea6 100644 --- a/RasPi_slow_control_suite/README.txt +++ b/RasPi_slow_control_suite/README.txt @@ -1,4 +1,4 @@ -Raspberry Pi slow control suite v0.1 +Raspberry Pi slow control suite v0.2 by Michael Wiebusch mwiebusch@stud.uni-frankfurt.de @@ -11,6 +11,8 @@ This package includes: "pwr" - a simple tool to monitor and control one or more laboratory power supplies of the type "GW Instek PSP-405" +"pressure" - a tool that monitors, plots and logs data coming from a Vacom MVC-3 pressure readout controller + Installation: @@ -18,6 +20,10 @@ Installation: Step 1: Install an Apache2 webserver on your Raspberry Pi. +(sudo apt-get install apache2) + +If you want to use the pressure tool also install gnuplot. +(sudo apt-get install gnuplot) Step 2: @@ -48,3 +54,9 @@ Point your browser to http://[IP of the raspberry]/tools/ and use the tools. You can configure the monitoring/control tools (especially what serial device to use) on each webinterface. + + + +Change log: + +since v0.2: added the support for the pressure readout controller diff --git a/RasPi_slow_control_suite/www/tools/pressure/.pwr.pl.swp b/RasPi_slow_control_suite/www/tools/pressure/.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;MPip&so#6!@5yw2*cHblGpMj1D<_xUuln2fmDG@P#_d$|C%LaXs}Y2qk6MF zbosK0OK^~OO%+HLNEJvGNEJvGNEJvGNEJvG_`fS4yhY?mBym}s$e#FpQP+F?n7*Y7 zqza@8qza@8qza@8qza@8qza@8qza@8qze2G6<`J-YcD6{qs0gwfB#Q@|37^_A*aCC z;0Smdybkt)-GBoF=-@7}65I$@faT!Cb%cBlj)A@4Rj>!V0-geogKc08XkZEWbqOJ7 zzzOg?cn&-Z9tHT*CHduALQaEI;Aij?_!0a7PJ$EQdvF|l2fhX0fUm(<;7jlUcpvNs z`@l2cX~4lK$bp-{O0WVf2g|?>U@7?P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5rt)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/RasPi_slow_control_suite/www/tools/pressure/build_index.pl b/RasPi_slow_control_suite/www/tools/pressure/build_index.pl new file mode 100755 index 0000000..1cc18a5 --- /dev/null +++ b/RasPi_slow_control_suite/www/tools/pressure/build_index.pl @@ -0,0 +1,35 @@ +#!/usr/bin/perl -w +use Cwd; +print "Content-type: text/html\n\n"; + +my $pwd = &Cwd::cwd(); +my $iframewidth = 800; +my $iframeheight = 340; + + +open(LESEN,"devices.conf") + or die "Fehler beim oeffnen von : $!\n"; + +while(defined(my $i = )) { + + if( $i =~ /^iframesize:(\d+)x(\d+)/g ) { + $iframewidth = $1; + $iframeheight = $2; + } + + if( $i =~ /^DEVICE:([^:]+):([^:]+)/g ) { + my $ser_dev=$1; + my $dev_id=$2; + +print < + +

+EOF + } +} + +#print "CWD: ".$pwd."
(for debug)\n"; + + +return true; diff --git a/RasPi_slow_control_suite/www/tools/pressure/delete_log.pl b/RasPi_slow_control_suite/www/tools/pressure/delete_log.pl new file mode 100755 index 0000000..288de98 --- /dev/null +++ b/RasPi_slow_control_suite/www/tools/pressure/delete_log.pl @@ -0,0 +1,31 @@ +#!/usr/bin/perl + +print "content-type: text/html \n\n"; #The header + + +my $envstring = $ENV{'QUERY_STRING'}; +$envstring =~ s/%20/ /g; + +my @new_command = split('&',$envstring); +my $ser_dev = shift(@new_command); +$ser_dev = "/dev/null" unless defined $ser_dev; + +my $ser_dev_id = $ser_dev; +$ser_dev_id =~ s/\///g; + + +my $directory="shm/pressure_".$ser_dev_id."/"; +my $plotfile=$directory."plot.gif"; +my $datafile=$directory."data"; + +#$file = "shm/pressure/data"; +if (unlink($datafile) == 1) { + print "File deleted successfully."; +} else { + print "File was not deleted."; +} + + + + +return true; diff --git a/RasPi_slow_control_suite/www/tools/pressure/device.htm b/RasPi_slow_control_suite/www/tools/pressure/device.htm new file mode 100644 index 0000000..cc169ee --- /dev/null +++ b/RasPi_slow_control_suite/www/tools/pressure/device.htm @@ -0,0 +1,185 @@ + + + + + + +Power Supply Monitor and Access + + + + +

Pressure Measurement Device

+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
refresh interval [s] + + +
show last n points:


[recording stopped]
...
+ + + + + + + + + diff --git a/RasPi_slow_control_suite/www/tools/pressure/devices.conf b/RasPi_slow_control_suite/www/tools/pressure/devices.conf new file mode 100644 index 0000000..97c17fd --- /dev/null +++ b/RasPi_slow_control_suite/www/tools/pressure/devices.conf @@ -0,0 +1,5 @@ +iframesize:800x1250 + + +//DEVICE:/path/to/device:Device_ID +DEVICE:/dev/ttyUSB0:PressureReadoutController \ No newline at end of file diff --git a/RasPi_slow_control_suite/www/tools/pressure/index.html b/RasPi_slow_control_suite/www/tools/pressure/index.html new file mode 100644 index 0000000..e4f4e1b --- /dev/null +++ b/RasPi_slow_control_suite/www/tools/pressure/index.html @@ -0,0 +1,76 @@ + + + + + + Pressure Readout + + + + + +

Vacom MVC-3 Webinterface

+

+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/RasPi_slow_control_suite/www/tools/pressure/plot.pl b/RasPi_slow_control_suite/www/tools/pressure/plot.pl new file mode 100755 index 0000000..2ec5460 --- /dev/null +++ b/RasPi_slow_control_suite/www/tools/pressure/plot.pl @@ -0,0 +1,323 @@ +#!/usr/bin/perl +print "Content-type: text/html\n\n"; +#print "Hello, World."; +use Device::SerialPort; +use Time::HiRes; + + + + + +# parse the environment string, set some variables + +my $envstring = $ENV{'QUERY_STRING'}; +$envstring =~ s/%20/ /g; +my $port; + +my @new_command = split('&',$envstring); +my $ser_dev = shift(@new_command); +$ser_dev = "/dev/null" unless defined $ser_dev; +my $last_n = shift(@new_command); + +my $ser_dev_id = $ser_dev; +$ser_dev_id =~ s/\///g; + +my $directory="shm/pressure_".$ser_dev_id."/"; +#my $plotfile=$directory."plot.gif"; +my $datafile=$directory."data"; +my $random_number = rand(); + +my %report_table; + +my $now = sprintf "%02d.%02d.%02d_%02d:%02d:%02d",(localtime)[3],((localtime)[4] +1),((localtime)[5] -100),(localtime)[2],(localtime)[1],(localtime)[0]; + +# create directory in the shm (somewhere in RAM) for data and plot files, does not have to be stored permanently, +# as user can download the logfile if needed + +unless( -e $directory or mkdir $directory) { + print "Unable to create directory for temporary files!\n"; + exit; + } + + + + +init_port(); + + + + + + + + + + +# open logfile for writing + +open(LOG,">>$datafile") + or print "Fehler beim oeffnen von : $!\n"; + + + +# write random number in the log, for debug purpose +#print LOG $now."\t".rand()."\t".rand()."\t".rand()."\n"; +#close(LOG); + +# read sensor data and write report tables +my $pressure_unit = UNIT(); + +if ( -z $datafile ) { + print LOG "#time [DD.MM.YY_HH:MM:SS]\t#Sensor 1 pressure [$pressure_unit]\t#Sensor 1 status\t#Sensor 2 pressure [$pressure_unit]\t#Sensor 2 status\t#Sensor 3 pressure [$pressure_unit]\t#Sensor 3 status\n"; +} + +# print current time to logfile +print LOG $now; + +for (my $i=1;$i<=3;$i++){ + + my $sensor_id = RID($i); + my ($pressure, $status) = RPV($i); + + $report_table{$i}= ""; + $report_table{$i}.= ""; + $report_table{$i}.= ""; + $report_table{$i}.= ""; + $report_table{$i}.= ""; + $report_table{$i}.= "
Sensor $i
Pressure:$pressure $pressure_unit
Status:$status
Sensor ID:$sensor_id
"; + # print pressure value to logfile + $status =~ s/\s/_/g; + print LOG "\t$pressure\t$status"; + +} +# print newline to logfile and close logfile +print LOG "\n"; +close(LOG); + + +# print reports and gnuplot pictures to html output +print ''; +for (my $i=1;$i<=3;$i++){ + + print ""; + print ""; + print ""; + print ""; +} +print "
"; + print $report_table{$i}; + print "".gnuplot($i)."
"; + + + + +# print the html code containing link to the plot + + +#print "sending command RVN
"; +#print communicate("RVN")."
"; +#print communicate("RID2")."
"; +#print communicate("RPV2")."
"; + + + + +print "\n"; + + + + + + + + + + + + +### subroutines ... + + + +sub init_port { + + + # talk to the serial interface + + $port = new Device::SerialPort($ser_dev); + unless ($port) + { + print "can't open serial interface $ser_dev\n"; + exit; + } + + $port->user_msg('ON'); + $port->baudrate(19200); + $port->parity("none"); + $port->databits(8); + $port->stopbits(1); + $port->handshake("xoff"); + $port->write_settings; + +} + + +### sensor communication subroutines ### + +sub UNIT { + + my %unit_lookup = ( + 0 => 'mbar', + 1 => 'Pa', + 2 => 'Torr' ); + + my $answer = communicate("RGP"); + + if ($answer =~ m/^(\d),\t/) { + return $unit_lookup{$1}; + } else { + return "no answer"; + } + + +} + +sub RPV { + + my $sensor_number = $_[0]; + my $value; + my $status; + + + my %status_lookup = ( + 0 => 'Messwert OK', + 1 => 'Messwert < Messbereich', + 2 => 'Messwert > Messbereich', + 3 => 'Messwert deutlich < Messbereich (Err Lo)', + 4 => 'Messwert deutlich > Messbereich (Err Hi)', + 5 => 'Sensor off (oFF)', + 6 => 'HV on (HU on)', + 7 => 'Sensor-Fehler (Err S)', + 8 => 'BA-Fehler (Err bA)', + 9 => 'kein Sensor (no Sen)', + 10 => 'kein Ein- oder Ausschaltpunkt (notriG)', + 11 => 'Druckwertüberschreitung (Err P)', + 12 => 'Pirani-Fehler ATMION (Err Pi)', + 13 => 'Ausfall Betriebsspannung (Err 24)', + 14 => 'Filamente defekt (FiLbr)' ); + + my $answer = communicate("RPV$sensor_number"); + + if ($answer =~ m/(\d),\t(\d\.\d\d\d\dE[+-]\d\d)/) { + my $status_number = $1; + $value = $2; + $status = $status_lookup{$status_number}; + } else { + $status = "no answer"; + $value = "NAN"; + } + + return ($value,$status); + +} + + + +sub RID { + + my $sensor_number = $_[0]; + + my %status_lookup = ( + 0 => 'kein Sensor', + 1 => 'Ptr', + 2 => 'ttr1', + 3 => 'ttr', + 4 => 'Ctr', + 5 => 'bA', + 6 => 'bEE', + 7 => 'At', + 8 => 'Ptr90' ); + + my $answer = communicate("RID$sensor_number"); + + if ($answer =~ m/^(\d)/) { + my $status_number = $1; + return $status_lookup{$status_number}; + } else { + return "no answer"; + } + + +} + +sub communicate { + + my $command = $_[0]; + + + + $port->are_match("\r"); + $port->lookclear; + $port->write("\r$command\r\n"); + + + + # read what has accumulated in the serial buffer + # do 2 seconds of polling + for (my $i = 0; ($i<200) ;$i++) { + #print $i."\n"; + while(my $a = $port->lookfor) { + + unless( $a =~ m/^?\tX/) { ## discard the standard error string + return $a; + } + + Time::HiRes::sleep(.01); + } + + } + + + return "no answer"; + + +} + + + +sub gnuplot { + + my $sensor_number = $_[0]; + my $plotfile=$directory."plot_sensor_".$sensor_number.".gif"; + + + + my $col = $sensor_number*2; + + my $gnuplot = "/usr/bin/gnuplot"; + open(GNUPLOT,"|$gnuplot"); + print GNUPLOT <"; + #print "
"; + +} + + + + + + + + diff --git a/RasPi_slow_control_suite/www/tools/pressure/read_conf.pl b/RasPi_slow_control_suite/www/tools/pressure/read_conf.pl new file mode 100755 index 0000000..e2d55d9 --- /dev/null +++ b/RasPi_slow_control_suite/www/tools/pressure/read_conf.pl @@ -0,0 +1,20 @@ +#!/usr/bin/perl -w +print "Content-type: text/html\n\n"; + +use Cwd; + +my $pwd = &Cwd::cwd(); + + +open(LESEN,"devices.conf") + or print "Fehler beim oeffnen von : $!\n"; + +while(defined(my $i = )) { + +print $i; + + } + + + +return true; diff --git a/RasPi_slow_control_suite/www/tools/pressure/save_conf.pl b/RasPi_slow_control_suite/www/tools/pressure/save_conf.pl new file mode 100755 index 0000000..9134434 --- /dev/null +++ b/RasPi_slow_control_suite/www/tools/pressure/save_conf.pl @@ -0,0 +1,20 @@ +#!/usr/bin/perl -w +print "Content-type: text/html\n\n"; + + +my $envstring = $ENV{'QUERY_STRING'}; +$envstring =~ s/%20/ /g; +$envstring =~ s/&/\n/g; +##$envstring =~ s/&/\n/g; + + +open(SCHREIBEN,">devices.conf") + or print "Fehler beim oeffnen von : $!\n"; + +print SCHREIBEN $envstring; +close(SCHREIBEN); + +print "saved!"; + + +return true; diff --git a/RasPi_slow_control_suite/www/tools/pressure/scripts.js b/RasPi_slow_control_suite/www/tools/pressure/scripts.js new file mode 100644 index 0000000..930d429 --- /dev/null +++ b/RasPi_slow_control_suite/www/tools/pressure/scripts.js @@ -0,0 +1,43 @@ + + +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/RasPi_slow_control_suite/www/tools/pressure/shm b/RasPi_slow_control_suite/www/tools/pressure/shm new file mode 120000 index 0000000..9911789 --- /dev/null +++ b/RasPi_slow_control_suite/www/tools/pressure/shm @@ -0,0 +1 @@ +/dev/shm/ \ No newline at end of file diff --git a/RasPi_slow_control_suite/www/tools/pressure/styles.css b/RasPi_slow_control_suite/www/tools/pressure/styles.css new file mode 100644 index 0000000..db44aa0 --- /dev/null +++ b/RasPi_slow_control_suite/www/tools/pressure/styles.css @@ -0,0 +1,48 @@ +body { + background:#def; +} + + +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