Skip Menu |

This queue is for tickets about the Device-Modbus-TCP CPAN distribution.

Report information
The Basics
Id: 122686
Status: open
Priority: 0/
Queue: Device-Modbus-TCP

People
Owner: JFRAIRE [...] cpan.org
Requestors: rdiezmail-perl [...] yahoo.de
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: write_multiple_registers() generates a malformed request when sending more than 123 registers
Date: Wed, 2 Aug 2017 15:06:49 +0000 (UTC)
To: "bug-Device-Modbus-TCP [...] rt.cpan.org" <bug-Device-Modbus-TCP [...] rt.cpan.org>
From: "R. Diez" <rdiezmail-perl [...] yahoo.de>
Hi there: With Modbus TCP, you can only write up to 123 registers at once with write_multiple_registers(). This limit is imposed by the Modbus TCP protocol. However, if you try to send more registers, module Device::Modbus::TCP just sends a malformed request. I think the upper bit gets set, which means that an exception code is sent as a Modbus request. The server rejects it accordingly. I think the client should check and throw an exception (with "die") to the caller instead of sending a malformed request. Other than that, many thanks for the module! Best regards, rdiez
Hello! Actually, the client does find and reject the request. The problem is that it is treated unexpectedly: Instead of dying, it returns an exception *response* as if it was the server. But the client does not die: my $client = Device::Modbus::TCP::Client->new( port => 6545 ); my $req = $client->write_multiple_registers( function => 'Write Multiple Registers', address => 1, values => [(0x000A, 0x0102) x 62], # results in 124 registers ); isa_ok $req, 'Device::Modbus::Exception'; is $req->{code}, 0x90, 'Function code is correct for a write registers request'; is $req->{exception_code}, 3, 'Exception code is correct for a request above 123 registers'; So... I think the proper way to take this would be to just die with a nice, explicative note. Thank you for your note and the time you took to report this problem. I shall let you know by this means when the new version with the correct behavior is out. Julio On Wed Aug 02 11:07:33 2017, rdiezmail-perl@yahoo.de wrote: Show quoted text
> Hi there: > > > With Modbus TCP, you can only write up to 123 registers at once with > write_multiple_registers(). This limit is imposed by the Modbus TCP > protocol. > > However, if you try to send more registers, module Device::Modbus::TCP > just sends a malformed request. I think the upper bit gets set, which > means that an exception code is sent as a Modbus request. The server > rejects it accordingly. > > I think the client should check and throw an exception (with "die") to > the caller instead of sending a malformed request. > > Other than that, many thanks for the module! > > > Best regards, > rdiez
On Mon Aug 07 17:58:29 2017, JFRAIRE wrote: Show quoted text
> Hello! > > Actually, the client does find and reject the request. The problem is > that it is treated unexpectedly: Instead of dying, it returns an > exception *response* as if it was the server. But the client does not > die: > > my $client = Device::Modbus::TCP::Client->new( port => 6545 ); > > my $req = $client->write_multiple_registers( > function => 'Write Multiple Registers', > address => 1, > values => [(0x000A, 0x0102) x 62], # results in 124 registers > ); > > isa_ok $req, 'Device::Modbus::Exception'; > is $req->{code}, 0x90, > 'Function code is correct for a write registers request'; > is $req->{exception_code}, 3, > 'Exception code is correct for a request above 123 registers'; > > > So... I think the proper way to take this would be to just die with a > nice, explicative note. > > Thank you for your note and the time you took to report this problem. > I shall let you know by this means when the new version with the > correct behavior is out. > > Julio > > On Wed Aug 02 11:07:33 2017, rdiezmail-perl@yahoo.de wrote:
> > Hi there: > > > > > > With Modbus TCP, you can only write up to 123 registers at once with > > write_multiple_registers(). This limit is imposed by the Modbus TCP > > protocol. > > > > However, if you try to send more registers, module > > Device::Modbus::TCP > > just sends a malformed request. I think the upper bit gets set, which > > means that an exception code is sent as a Modbus request. The server > > rejects it accordingly. > > > > I think the client should check and throw an exception (with "die") > > to > > the caller instead of sending a malformed request. > > > > Other than that, many thanks for the module! > > > > > > Best regards, > > rdiez