Device::Modbus::RTU::Client - Perl client for Modbus RTU communications
#! /usr/bin/env perl use Device::Modbus::RTU::Client; use strict; use warnings; use v5.10; my $client = Device::Modbus::RTU::Client->new( port => '/dev/ttyUSB0', baudrate => 19200, parity => 'none', ); my $req = $client->read_holding_registers( unit => 4, address => 0, quantity => 2, ); $client->send_request($req); my $resp = $client->receive_response; $client->disconnect;
This module is part of Device::Modbus::RTU, a distribution which implements the Modbus RTU protocol on top of Device::Modbus.
Device::Modbus::RTU::Client inherits from Device::Modbus::Client, and adds the capability of communicating via the serial port. As such, Device::Modbus::RTU::Client implements the constructor only. Please see Device::Modbus::Client for most of the documentation.
This method opens the serial port to communicate using the Modbus RTU protocol. It takes the following arguments:
The serial port to open.
A valid baud rate. Defaults to 9600 bps.
An integer from 5 to 8. Defaults to 8.
Either 'even', 'odd' or 'none'. Defaults to 'none'.
1 or 2. Defaults to 1.
Defaults to 10 (seconds).
This method closes the serial port:
$client->disconnect;
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::RTU, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Device::Modbus::RTU
CPAN shell
perl -MCPAN -e shell install Device::Modbus::RTU
For more information on module installation, please visit the detailed CPAN module installation guide.