aldas / modbus-tcp-client

PHP client for Modbus TCP and Modbus RTU over TCP (can be used for serial)
Apache License 2.0
195 stars 56 forks source link

Limitation of Unit ID #159

Closed Winni66 closed 8 months ago

Winni66 commented 8 months ago

Is your feature request related to a problem? Please describe. I'm quite new to Modbus topic. This library is used within one Smarthome solution called Edomi. I'm using a Webasto Wallbox which uses Unit ID 255 and unfortunately this library allowes only ID up to 247. It's not possible to change.

Describe the solution you'd like Would it be possible to disable ID limitation? I'm not able to build my own library for that, because I don't have the skills.

aldas commented 8 months ago

As a immediate workaround - you can change the unitID value after packet has been created.

$packet = new ReadHoldingRegistersRequest($startAddress, $quantity, $unitID); 
$packet[6] = 255;

For example: unit ID is 7th byte for FC3 request.

https://github.com/aldas/modbus-tcp-client/blob/53657b3de8f90c9e6727c9aca841b3e355fbe554/src/Packet/ModbusFunction/ReadHoldingRegistersRequest.php#L17-L24

Winni66 commented 8 months ago

Thanks for fast reply, but i fear it's not as easy as it seems for me:

 

1) I'm using this library for several modbus devices (wallbox, inverter, battery), therefore workaround with fixed ID will not work.

2) I tried to remove the limit here:         private function validate(int $length, int $unitId, int|null $transactionId): void     {         if (!$length || !($length > 0 && $length <= Types::MAX_VALUE_UINT16)) {             throw new InvalidArgumentException("length is not set or out of range (uint16): {$length}");         }         if (!($unitId >= 0 && $unitId <= 257)) {             throw new InvalidArgumentException("unitId is out of range (0-257): {$unitId}"); but it doesn't has impact. Unfortunately I don't know what composer does on my installation, perhaps there is something like compiling? I don't know how to handle this properly.

 

best regards

 

P.S.: there is also a message:

Cannot use aldas/modbus-tcp-client's latest version 3.5.0 as it requires php ^8.0 which is not satisfied by your platform.

I'm still on 7.2.34

 

Gesendet: Donnerstag, 22. Februar 2024 um 23:22 Uhr Von: "Martti T." @.> An: "aldas/modbus-tcp-client" @.> Cc: "Winni66" @.>, "Author" @.> Betreff: Re: [aldas/modbus-tcp-client] Limitation of Unit ID (Issue #159)

 

As a immediate workaround - you can change the unitID value after packet has been created.

$packet = new ReadHoldingRegistersRequest($startAddress, $quantity, $unitID); $packet[6] = 255;

For example: unit ID is 7th byte for FC3 request.

https://github.com/aldas/modbus-tcp-client/blob/53657b3de8f90c9e6727c9aca841b3e355fbe554/src/Packet/ModbusFunction/ReadHoldingRegistersRequest.php#L21

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

aldas commented 8 months ago

I think you could create custom patch for PHP 7 to remove that validation check and let composer to apply it.

See