NAME
Device::Modbus::RTU::Client - Perl client for Modbus RTU communications
SYNOPSIS
#! /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;
DESCRIPTION
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.
METHODS
new
This method opens the serial port to communicate using the Modbus RTU protocol. It takes the following arguments:
- port
-
The serial port to open.
- baudrate
-
A valid baud rate. Defaults to 9600 bps.
- databits
-
An integer from 5 to 8. Defaults to 8.
- parity
-
Either 'even', 'odd' or 'none'. Defaults to 'none'.
- stopbits
-
1 or 2. Defaults to 1.
- timeout
-
Defaults to 10 (seconds).
disconnect
This method closes the serial port:
$client->disconnect;
SEE ALSO
Most of the functionality is described in Device::Modbus::Client.
Other distributions
These are other implementations of Modbus in Perl which may be well suited for your application: Protocol::Modbus, MBclient, mbserverd.
GITHUB REPOSITORY
You can find the repository of this distribution in GitHub.
AUTHOR
Julio Fraire, <julio.fraire@gmail.com>
COPYRIGHT AND LICENSE
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.