in reply to Re: Need help with Modbus
in thread Need help with Modbus

Thank you! However, could you please elaborate: if my IP is 192.168.0.57 port 502, then do I format the like this? $proto = Protocol::Modbus->new( driver => 'TCP', transport => 'TCP', ip=>'192.168.0.57', port=>'502' );

if in c ret = read_input_registers(&mb_param, SUNSAVERMPPT, 0x0000, 75, data); Then Which are the function, address and quantity? in my $request4 = $proto->request( function => 4, address => 1, quantity => 1, );

Which handle/variable gets the modbus reply?

Replies are listed 'Best First'.
Re^3: Need help with Modbus
by Khen1950fx (Canon) on Jan 27, 2012 at 06:50 UTC

    The $req variable gets the modbus reply.

    #!/usr/bin/perl -l use strict; use warnings; use Protocol::Modbus; $|=1; my $modbus = Protocol::Modbus->new( driver => 'TCP', transport => 'TCP', ); my $trs = Protocol::Modbus::Transport->new( driver => 'TCP', address => '192.168.0.57', port => 502, timeout => 3, ); my $req = $modbus->request( function => 4, address => 1, quantity => 75, value => 0x0000, ); print "=" x 60; print "Response: ", $req; print "=" x 60; $trs->disconnect;
      Hello. Did this work for you? I am trying to communicate with a charge controller that supports modbus/tcp but when I modify code above I don't even see traffic leave my host. I get a response from the program that looks like "Response: ModbusRequest PDU(000000000006ff040001000a)" but I don't know what that means. I am going crazy over this. Please help. Thank you.
        The module's author has not yet completely finished the module. It doesn't interface with PLC devices. It only generates modbus protocol messages at this time. For more info, see Modbus Specifications and Guides.
        Thats not a Modbus-Response. It`s only a output of your request. For more information check this example -> http://cpansearch.perl.org/src/COSIMO/Protocol-Modbus-0.09/examples/read_coils_full_api.pl Which charger you want to use?