-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patharead2
executable file
·83 lines (73 loc) · 2.66 KB
/
aread2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/perl
# aread2 - Get readings from aurora inverter
# Copyright (C) 2012 R.J.Middleton
# e-mail: [email protected]
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
sub help_info { print <<"End of Info;" ; }
############################################################################
#
# File Name ......................... aread2
# Written By ........................ Dick Middleton
# Date .............................. 09-Mar-12
#
# Last-modified: 2012-11-17 10:12:13 on penguin.lingbrae"
#
# Description :
#
############################################################################
End of Info;
@_ = split('/', $0); # extract program name
our $pn = pop(@_); # basename
our $dr = join('/', @_); # dirname
use Getopt::Std;
use Device::Inverter::Aurora;
our %opt;
our $option_set = "hq"; # valid option characters
&getopts($option_set, \%opt) || die "$pn aborted: Incorrect option\n";
&help_info && exit(0) if $opt{h};
# chop($today = `date +%d-%b-%y`); # today's date
my $dev = new Device::Inverter::Aurora(
retries => 0,
port => '/dev/ttyUSB0',
read_const_time => 750,
debug => 0);
eval {
my @data = (
'READINGS',
sprintf(': %d', $dev->getGridPower()),
sprintf(': %0.3f', $dev->getDailyEnergy()/1000),
sprintf(": %0.2f:", $dev->getTotalEnergy()/1000),
"\n"
);
print @data;
};
if ($@) {
my $error = $@;
my $lastError = $dev->lastError();
if ($error =~ /Read failure, \d attempts made/ && $lastError =~ /Failed to read in all bytes/) {
print STDERR "It would appear that the aurora has gone away\n";
}
elsif ($error =~ /Read failure, \d attempts made/ && $lastError =~ /Failed to write/) {
print STDERR "USB Serial port died\n";
# ** Disconnect and reconnect as udev will have re-mapped the symlink **
}
else {
print STDERR $error;
print STDERR $lastError;
}
}
# Local Variables:
# mode:perl
# time-stamp-pattern: "30/Last-modified:[ \t]+%:y-%02m-%02d %02H:%02M:%02S on %h"
# End: