| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
########################################### |
|
2
|
|
|
|
|
|
|
package Device::MAS345; |
|
3
|
|
|
|
|
|
|
########################################### |
|
4
|
2
|
|
|
2
|
|
22909
|
use strict; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
68
|
|
|
5
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
85
|
|
|
6
|
2
|
|
|
2
|
|
3138
|
use Device::SerialPort; |
|
|
2
|
|
|
|
|
80755
|
|
|
|
2
|
|
|
|
|
154
|
|
|
7
|
2
|
|
|
2
|
|
3082
|
use Log::Log4perl qw(:easy); |
|
|
2
|
|
|
|
|
125678
|
|
|
|
2
|
|
|
|
|
13
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = "0.03"; |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
########################################### |
|
12
|
|
|
|
|
|
|
sub new { |
|
13
|
|
|
|
|
|
|
########################################### |
|
14
|
0
|
|
|
0
|
0
|
0
|
my($class, %options) = @_; |
|
15
|
|
|
|
|
|
|
|
|
16
|
0
|
|
|
|
|
0
|
my $self = { |
|
17
|
|
|
|
|
|
|
port => "/dev/ttyS0", |
|
18
|
|
|
|
|
|
|
baudrate => 600, |
|
19
|
|
|
|
|
|
|
bytes => 14, |
|
20
|
|
|
|
|
|
|
pause => 1, |
|
21
|
|
|
|
|
|
|
databits => 7, |
|
22
|
|
|
|
|
|
|
%options, |
|
23
|
|
|
|
|
|
|
}; |
|
24
|
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
0
|
bless $self, $class; |
|
26
|
0
|
|
|
|
|
0
|
$self->reset(); |
|
27
|
|
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
0
|
return $self; |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
########################################### |
|
32
|
|
|
|
|
|
|
sub error { |
|
33
|
|
|
|
|
|
|
########################################### |
|
34
|
0
|
|
|
0
|
0
|
0
|
my($self, $err) = @_; |
|
35
|
|
|
|
|
|
|
|
|
36
|
0
|
0
|
|
|
|
0
|
$self->{error} = $err if defined $err; |
|
37
|
0
|
|
|
|
|
0
|
return $self->{error}; |
|
38
|
|
|
|
|
|
|
} |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
########################################### |
|
41
|
|
|
|
|
|
|
sub read { |
|
42
|
|
|
|
|
|
|
########################################### |
|
43
|
2
|
|
|
2
|
0
|
1572
|
my($self) = @_; |
|
44
|
|
|
|
|
|
|
|
|
45
|
2
|
|
|
|
|
4
|
my $data; |
|
46
|
|
|
|
|
|
|
|
|
47
|
2
|
|
|
|
|
6
|
$data = $self->read_raw(); |
|
48
|
|
|
|
|
|
|
|
|
49
|
2
|
|
|
|
|
14
|
my $valrx = qr/-?[\w.]+/; |
|
50
|
|
|
|
|
|
|
|
|
51
|
2
|
100
|
|
|
|
137
|
if($data =~ /(\w+)\s+($valrx)\s+(\w+)/) { |
|
|
|
50
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
52
|
1
|
|
|
|
|
8
|
return ($2, $3, $1); |
|
53
|
|
|
|
|
|
|
} elsif($data =~ /(\w+)\s+($valrx)(kOhm|MOhm)/) { # for bunched lines |
|
54
|
1
|
|
|
|
|
9
|
return ($2, $3, $1); |
|
55
|
|
|
|
|
|
|
} elsif($data =~ /($valrx)/) { |
|
56
|
0
|
|
|
|
|
|
return ($1, "", ""); |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
LOGDIE "Unrecognized response: $data"; |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
########################################### |
|
63
|
|
|
|
|
|
|
sub read_raw { |
|
64
|
|
|
|
|
|
|
########################################### |
|
65
|
0
|
|
|
0
|
0
|
|
my($self) = @_; |
|
66
|
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
DEBUG "Purging"; |
|
68
|
0
|
0
|
|
|
|
|
$self->{serial}->purge_all() || |
|
69
|
|
|
|
|
|
|
LOGDIE "Purge failed ($!)"; |
|
70
|
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
$self->{serial}->rts_active(0); |
|
72
|
0
|
|
|
|
|
|
$self->{serial}->dtr_active(1); |
|
73
|
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
DEBUG "Sending newline"; |
|
75
|
0
|
0
|
|
|
|
|
$self->{serial}->write("\n") || |
|
76
|
|
|
|
|
|
|
LOGDIE "Send of newline failed"; |
|
77
|
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
DEBUG "Waiting $self->{pause} seconds"; |
|
79
|
0
|
|
|
|
|
|
select(undef, undef, undef, $self->{pause}); |
|
80
|
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
DEBUG "Reading response"; |
|
82
|
0
|
|
|
|
|
|
my($count, $data) = $self->{serial}->read($self->{bytes}); |
|
83
|
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
DEBUG "Received $count bytes"; |
|
85
|
0
|
0
|
|
|
|
|
if($count != $self->{bytes}) { |
|
86
|
0
|
|
|
|
|
|
LOGDIE "Read $self->{bytes}, got only $count"; |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
return $data; |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
########################################### |
|
93
|
|
|
|
|
|
|
sub reset { |
|
94
|
|
|
|
|
|
|
########################################### |
|
95
|
0
|
|
|
0
|
0
|
|
my($self) = @_; |
|
96
|
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
$self->{serial} = Device::SerialPort->new( |
|
98
|
|
|
|
|
|
|
$self->{port}, undef); |
|
99
|
|
|
|
|
|
|
|
|
100
|
0
|
0
|
|
|
|
|
$self->{serial}->baudrate($self->{baudrate}) or |
|
101
|
|
|
|
|
|
|
LOGDIE "Setting baudrate to $self->{baudrate} failed"; |
|
102
|
|
|
|
|
|
|
|
|
103
|
0
|
0
|
|
|
|
|
$self->{serial}->databits($self->{databits}) or |
|
104
|
|
|
|
|
|
|
LOGDIE "Setting databits to $self->{databits} failed"; |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
1; |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
__END__ |