NAME

Protocol::Modbus::Transaction - Modbus protocol request/response transaction

SYNOPSIS

use Protocol::Modbus;

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

# Get a request object
my $req = $proto->request(
    function => Protocol::Modbus::FUNC_READ_COILS, # or 0x01
    address  => 0x1234,
    quantity => 1,
    unit     => 0x07, # Only has sense for Modbus/TCP
);

# Init transaction and execute it, obtaining a response
my $trn = Protocol::Modbus::Transaction->new( request=>$req );
my $res = $trn->execute();

# Pretty-print response on stdout
print $response . "\n";   # Modbus Response PDU(......)

# ...
# Parse response
# ...

DESCRIPTION

Implements the basic Modbus transaction model, with request / response cycle. Also responsible of raising exceptions (see Protocol::Modbus::Exception class).

METHODS

protocol

Returns the protocol object in use. Should be an instance of Protocol::Modbus or its subclasses.

request

Get/set request object. Should be an instance of Protocol::Modbus::Request class.

response

Get/set response object. Should be an instance of Protocol::Modbus::Response class.

execute

Executes transaction, sending request to proper channel (depending on protocol at this time). Returns a Protocol::Modbus::Response object in case of successful transaction. Returns a Protocol::Modbus::Exception object in case of failure and exception raised.

SEE ALSO

Protocol::Modbus::Exception

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.

3 POD Errors

The following errors were encountered while parsing the POD:

Around line 157:

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

Around line 180:

You forgot a '=back' before '=head1'

You forgot a '=back' before '=head1'

Around line 182:

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