Sample code to reach registers on Schneider IEM3355 Modbus energy meter

Although registers are well documented, I was unsuccessful using pymodbus3 and my own C client to read modbus data. Finally a stable version in perl:


use Device::Modbus::RTU::Client;
use warnings;
use Data::Dumper;

my $client = Device::Modbus::RTU::Client->new(
port => '/dev/ttyUSB0',
baudrate => 38400,
parity => 'even',
);

sub read_string
#where:as in the documentation
{
$where= shift;
$length = shift;

my $req = $client->read_holding_registers(
unit => 3, #might be different for you!
address => $where-1, #although it is 30 in doc, it is 29 in reality
quantity => $length,
);

$client->send_request($req);
my $resp = $client->receive_response;
#printf(Dumper($resp));
my $t=$resp->values;
$i=0;
$s="";

while ($i<$length) { $s.=chr($t->[$i]/256);
$s.=chr($t->[$i]%256);
$i++;
}
#printf("$s\n");
return $s;

}

printf("name:".read_string(30,20)."\n");
printf("model:".read_string(50,20)."\n");
printf("manufacturer:".read_string(70,20)."\n");

$client->disconnect;


boldi@supercell$ perl arammero.pl
name:Energy Meter
model:iEM3355
manufacturer:Schneider Electric

edit no. 4: I'm github publisher right now. I have to update my CV with new skills.
https://github.com/bbencsath/schneider_iem3355_modbus_client/blob/master/code/sample_client.pl

This entry was posted on February 23, 2018 at 7:00 pm and is filed under Uncategorized. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply


Warning: Undefined variable $user_ID in /data/web/html/boldiphishing/wordpress/wp-content/themes/fishlover/comments.php on line 47

You must be logged in to post a comment.