2019-12-22 15:39:16 +00:00
#!/usr/bin/perl
#
use strict ;
use warnings ;
2020-01-09 13:17:46 +00:00
sub BEGIN {
2020-01-10 16:42:09 +00:00
push @ INC , "." ;
2020-01-09 13:17:46 +00:00
}
use iec1107 ;
2019-12-22 15:39:16 +00:00
my $ port = Device::SerialPort - > new ( "/dev/ttyUSB0" ) || die $! ;
$ port - > baudrate ( 9600 ) ;
$ port - > databits ( 7 ) ;
$ port - > parity ( "even" ) ;
$ port - > stopbits ( 1 ) ;
$ port - > handshake ( "none" ) ;
$ port - > write_settings ;
$ port - > purge_all ( ) ;
2020-01-10 16:42:09 +00:00
$ port - > read_char_time ( 0 ) ;
$ port - > read_const_time ( 150 ) ; #was 100ms previously, this lead to race conditions
2019-12-22 15:39:16 +00:00
2020-01-10 08:33:12 +00:00
my @ ids = ( 1613300152 , 1613300153 ) ;
2019-12-22 15:39:16 +00:00
# It is possible to find out the device id of a single device on RS-485 9600@7E1 by sending "/?!\r\n"
2020-01-10 16:42:09 +00:00
# It does not work with more than one device on the same bus, it results in garbage!
2020-01-10 08:33:12 +00:00
my $ passwd = "00000000" ; # Standard password 0 over 8-digits
2020-01-07 21:29:35 +00:00
2020-01-10 08:33:12 +00:00
for my $ id ( @ ids ) {
my $ drs110m = iec1107 - > new ( "port" = > $ port , "id" = > $ id , "passwd" = > $ passwd ) ;
2020-01-07 21:29:35 +00:00
2020-01-10 08:33:12 +00:00
print ( "Meter: $id\n" ) ;
2020-01-10 16:42:09 +00:00
# $drs110m->start_communication()->start_programming_mode()->update_values();#this function concatenation is neat but absolutely destroying readability
2020-01-09 13:17:46 +00:00
$ drs110m - > start_communication ( ) ;
2020-01-10 16:42:09 +00:00
2020-01-09 13:17:46 +00:00
$ drs110m - > start_programming_mode ( ) ;
2020-01-10 16:42:09 +00:00
2020-01-09 13:17:46 +00:00
$ drs110m - > update_values ( ) ;
2020-01-10 16:42:09 +00:00
2020-01-10 08:33:12 +00:00
while ( my ( $ reg , $ val ) = each ( % { $ drs110m - > regs } ) ) { #Note: this type switching in perl is crazy!
print ( "$reg : $val\n" ) ;
} ;
2020-01-09 13:17:46 +00:00
#print("log off from $serialID\n");
$ drs110m - > log_off ( ) ;
2020-01-07 21:29:35 +00:00
}
2019-12-22 15:39:16 +00:00