Device::Modbus::TCP::Client - Perl client for Modbus TCP communications
#! /usr/bin/perl
use Device::Modbus::TCP::Client; use Data::Dumper; use strict; use warnings; use v5.10;
my $client = Device::Modbus::TCP::Client->new( host => '192.168.1.34', );
my $req = $client->read_holding_registers( unit => 3, address => 2, quantity => 1 );
say Dumper $req; $client->send_request($req) || die "Send error: $!"; my $response = $client->receive_response; say Dumper $response;
$client->disconnect;
This module is part of Device::Modbus::TCP, a distribution which implements the Modbus TCP protocol on top of Device::Modbus.
Device::Modbus::TCP::Client inherits from Device::Modbus::Client, and adds the capability of communicating via TCP sockets. As such, Device::Modbus::TCP::Client implements the constructor only. Please see Device::Modbus::Client for most of the documentation.
This method creates and returns a Device::Modbus::TCP::Client object. It takes the following arguments:
127.0.0.1 by default
502 by default.
Defaults to 2 seconds.
Returns the IO::Socket::INET object used by the client.
Returns true if the socket object exists and if it is connected.
This method closes the socket connection:
Most of the functionality is described in Device::Modbus::Client.
These are other implementations of Modbus in Perl which may be well suited for your application: Protocol::Modbus, MBclient, mbserverd.
You can find the repository of this distribution in GitHub.
Julio Fraire, <julio.fraire@gmail.com>
Copyright (C) 2015 by Julio Fraire This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.14.2 or, at your option, any later version of Perl 5 you may have available.
To install Device::Modbus::TCP, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Device::Modbus::TCP
CPAN shell
perl -MCPAN -e shell install Device::Modbus::TCP
For more information on module installation, please visit the detailed CPAN module installation guide.