From: Michael Wiebusch Date: Mon, 13 May 2013 13:56:08 +0000 (+0200) Subject: added support for Vacom MVC-3 pressure readout controller X-Git-Url: https://jspc29.x-matter.uni-frankfurt.de/git/?a=commitdiff_plain;h=c5e2f143199425641515dfd87fb29562bcd11999;p=labtools.git added support for Vacom MVC-3 pressure readout controller --- 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 0000000..f357731 Binary files /dev/null and b/RasPi_slow_control_suite/www/tools/pressure/.pwr.pl.swp differ 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