From 41d0b0896bf8eec5f3a627af45112755abfaf2b5 Mon Sep 17 00:00:00 2001 From: Michael Wiebusch Date: Thu, 20 Nov 2014 11:47:18 +0100 Subject: [PATCH] slight modifications to the onewire temperature front-end --- .../voltage_readout.pl_bak12.10.25_17:59:26 | 136 ------------------ .../www/tools/onewire/config.conf | 12 +- .../www/tools/onewire/voltage_readout.pl | 36 +++-- 3 files changed, 34 insertions(+), 150 deletions(-) delete mode 100755 RasPi_slow_control_suite/www/tools/onewire/bak/voltage_readout.pl_bak12.10.25_17:59:26 diff --git a/RasPi_slow_control_suite/www/tools/onewire/bak/voltage_readout.pl_bak12.10.25_17:59:26 b/RasPi_slow_control_suite/www/tools/onewire/bak/voltage_readout.pl_bak12.10.25_17:59:26 deleted file mode 100755 index 8789972..0000000 --- a/RasPi_slow_control_suite/www/tools/onewire/bak/voltage_readout.pl_bak12.10.25_17:59:26 +++ /dev/null @@ -1,136 +0,0 @@ -#!/usr/bin/perl -w - -use strict; -use warnings; -use Device::SerialPort; -use feature 'state'; - - - - - - - - -sub adc2mV { - my $adc = $_[0]; - my $voltage = ($adc -(-0.904714))/0.936225; - return $voltage; -} - - - -#default device -my $ser_dev = "/dev/ttyUSB0"; - - - -# read config file - -open(LESEN,"htdocs/chiptemp/config.conf") - or die "Fehler beim oeffnen von : $!\n"; - -while(defined(my $i = )) { - - if( $i =~ /^SER_DEV=([^=]+)/g ) { - $ser_dev=$1; - $ser_dev =~ s/\n//g; - $ser_dev =~ s/\r//g; - } - -} - - - - - - - - - - - - - - - - - - - -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(19200); -$port->parity("none"); -$port->databits(8); -$port->stopbits(1); -$port->handshake("xoff"); -$port->write_settings; - - - -my $nmax = 10; -my $n = 0; -my @data; - - - - - - # clear buffers, then send the "list"-command to the power supply - $port->lookclear; - - # read what has accumulated in the serial buffer - -while ($n < $nmax) { - sleep 1; - while(my $a = $port->lookfor) { - #print $a."\n"; # debug output - if ($a =~ m/(\d\d\d\d)\t(\d\d\d\d)\t(\d\d\d\d)\t(\d\d\d\d)\t(\d\d\d\d)\t(\d\d\d\d)\t(\d\d\d\d)\t(\d\d\d\d)\t(\d\d\d\d)\t(\d\d\d\d)\t(\d\d\d\d)\t(\d\d\d\d)\t(\d\d\d\d)\t(\d\d\d\d)\t(\d\d\d\d)\t(\d\d\d\d)\t/) { - push(@data,[$1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16]); - $n++; - #print $data[0]->[0]."\n"; - if($n == $nmax) { - last; - } - - } - } -} - -#print $data[9]->[15]."\n"; - -my @mean; -for (my $j=0; $j<$nmax;$j++){ - for (my $i=0; $i<16;$i++) { - $mean[$i] += $data[$j]->[$i]; - } -} - -for my $j (0..15) { - $mean[$j] = sprintf("%6.1f mV",adc2mV($mean[$j]/$nmax)); -} - - -#$mean = $mean/$nmax; -#my $voltage=adc2mV($mean); -#print $mean."\n"; -#printf("this corresponds to %6.1f mV\n",$voltage); - -print join("\n",@mean); - - -#open(SCHREIBEN,">> calib_data.dat") -# or die "Fehler beim oeffnen von file: $!\n"; -# -#print SCHREIBEN $ARGV[0]."\t".$mean."\n"; - - - - diff --git a/RasPi_slow_control_suite/www/tools/onewire/config.conf b/RasPi_slow_control_suite/www/tools/onewire/config.conf index b011460..f3bb67e 100644 --- a/RasPi_slow_control_suite/www/tools/onewire/config.conf +++ b/RasPi_slow_control_suite/www/tools/onewire/config.conf @@ -2,7 +2,9 @@ //example: //SER_DEV=/dev/ttyUSB0 -SER_DEV=/dev/ttyUSB2 +SER_DEV=/dev/ttyUSB0 +INTERVAL=3 + //you can define sensor renaming rules here //example: @@ -11,4 +13,10 @@ SER_DEV=/dev/ttyUSB2 ID:284EFC4103000074=Prototyp_heat_sink ID:281B28E20200007A=Cleanroom_air ID:28CF43E202000003=Plane_f -ID:284037E2020000BF=Plane_e \ No newline at end of file +ID:284037E2020000BF=Plane_e +ID:2849FF9F0500007A=GISA1 +ID:28FEF9BC0500009C=GISA2 +ID:28500BBD05000079=GISA3 +ID:286F6DD00400009B=GISA4 +ID:28A345CA010000A9=Heatsink +ID:288E22A005000000=GISAtest \ No newline at end of file diff --git a/RasPi_slow_control_suite/www/tools/onewire/voltage_readout.pl b/RasPi_slow_control_suite/www/tools/onewire/voltage_readout.pl index 532dd62..aa59936 100755 --- a/RasPi_slow_control_suite/www/tools/onewire/voltage_readout.pl +++ b/RasPi_slow_control_suite/www/tools/onewire/voltage_readout.pl @@ -25,6 +25,9 @@ my $logfile = "onewirelog.txt"; open(LESEN,"config.conf") or die "Fehler beim oeffnen von : $!\n"; + +my $interval = 10; + while(defined(my $i = )) { if( $i =~ /^SER_DEV=([^=]+)/g ) { @@ -33,6 +36,12 @@ while(defined(my $i = )) { $ser_dev =~ s/\r//g; } + if( $i =~ /^INTERVAL=([^=]+)/g ) { + $interval=$1; + $interval =~ s/\n//g; + $interval =~ s/\r//g; + } + if( $i =~ /^(ID:[^=]+)=([^=]+)/g ) { my $id = $1; my $designator = $2; @@ -64,6 +73,7 @@ my $port = new Device::SerialPort($ser_dev); unless ($port) { print "can't open serial interface $ser_dev\n"; + sleep 1; exit; } @@ -77,7 +87,7 @@ $port->write_settings; -my $nmax = 20; +#my $nmax = 5; # number of seconds for serial accumulation (delay) my $n = 0; my @data; my $found = 0; @@ -85,12 +95,11 @@ my $found = 0; my %reporthash; - # clear buffers, then send the "list"-command to the power supply $port->lookclear; # read what has accumulated in the serial buffer -while ($n < $nmax) { +while ($n < $interval) { sleep 1; $n++; while(my $a = $port->lookfor) { @@ -106,14 +115,15 @@ while ($n < $nmax) { # print $id."\n".$temp."\n"; - - if(defined($idhash{$id})) { - # print "match!\n"; - $reporthash{$idhash{$id}} = $temp; - } else { - $reporthash{$rawid} = $temp; + if( $id =~ m/^ID:[0-9A-F]{16}$/ ){ + if(defined($idhash{$id})) { + # print "match!\n"; + $reporthash{$idhash{$id}} = $temp; + } else { + $reporthash{$rawid} = $temp; + } + } - } } } @@ -124,8 +134,10 @@ unless($found){ } open(SCHREIBEN,">> shm/$logfile") - or die "Fehler beim oeffnen von $ARGV[0].c: $!\n"; - while( my ($k, $v) = each %reporthash ) { + or die "Fehler beim oeffnen von /dev/shm/$logfile: $!\n"; +# while( my ($k, $v) = each %reporthash ) { + for my $k ( sort keys %reporthash ) { + my $v = $reporthash{$k}; print "Sensor $k => $v °C\n"; print SCHREIBEN "$now:\t$k\t$v Deg.C\n"; } -- 2.43.0