The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Device::Modbus::ASCII::Client - Modbus ASCII communications for Perl

SYNOPSIS

#! /usr/bin/env perl

use Device::Modbus::ASCII::Client;
use strict;
use warnings;
use v5.10;

my $client = Device::Modbus::ASCII::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::ASCII, a distribution which implements the Modbus ASCII protocol on top of Device::Modbus.

Device::Modbus::ASCII::Client inherits from Device::Modbus::Client, and adds the capability of communicating via the serial port using the ASCII version of Modbus. Please see Device::Modbus::Client for most of the documentation.

METHODS

new

This method opens the serial port to communicate using the Modbus ASCII 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 'even'.

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) 2018 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.