The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Protocol::Modbus - Implements Modbus protocol message generation and parsing

VERSION

This documentation relates to Protocol::Modbus version 0.01. API is surely going to change! Warning! Beta-version ahead!

SYNOPSIS

  use Protocol::Modbus;

  # Initialize protocol object
  my $proto = Protocol::Modbus->new( driver=>'TCP', transport=>'TCP' );

  # Get a request object
  my $request = $proto->request(
      function => Protocol::Modbus::FUNC_READ_COILS, # or 0x01
      address  => 0x1234,
      quantity => 1,
      #unit     => 0x07, # Not required for Modbus/TCP
  );
  
  # ... or another way
  my $request = $proto->readInputsRequest(
      address  => 0,
      quantity => 64,
      #unit    => 0x07, # Not required for Modbus/TCP
  );

  # Dump request as binary packets
  print unpack('H*', $request->pdu()), "\n";

  # Pretty-print request on stdout
  print $request . "\n";   # Modbus Request PDU(......)
  print $request->stringify() . "\n";

  # Parse responses...
  #
  # TODO...

DESCRIPTION

Object-oriented class to abstract generation and parsing of Modbus protocol messages. This class only handles protocol messages generation and parsing. It does not directly interface with your PLC devices. For that task, see the Device::PLC CPAN module (when that will be released).

Be sure to check out the examples folder to see some scripts that should work out of the box with a Modbus TCP server.

METHODS

Main methods are used to build Modbus requests.

readCoilsRequest
readInputsRequest
readHoldRegistersRequest
writeCoilRequest
writeRegisterRequest

STATUS

The set of classes is quite far from covering the whole Modbus protocol. In particular, aspects related to mantaining the state of the modbus server are completely skipped at this stage.

For now, there is only the main design and few more classes. I only implemented the necessary things to make the examples work, that is only simple requests with response parsing and coils status for example.

Further development will see the light when there's need and time... I wouldn't be surprised if it doesn't work for you out-of-the-box.

SEE ALSO

Device::PLC
http://www.modbus-ida.com

AUTHOR

Cosimo Streppone, <cosimo@cpan.org>

COPYRIGHT AND LICENSE

Copyright (C) 2007 by Cosimo Streppone

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.

2 POD Errors

The following errors were encountered while parsing the POD:

Around line 344:

=over should be: '=over' or '=over positive_number'

Around line 373:

=over should be: '=over' or '=over positive_number'