Closed ranjithphptech closed 1 year ago
Seems that Packet::isCompleteLengthRTU
is little buggy with for write* responses.
This should work for FC6 response:
->setIsCompleteCallback(static function ($binaryData, $streamIndex): bool {
return strlen($binaryData) == 8;
})
FC6 RTU response has 6 bytes of data + 2 bytes for CRC https://github.com/aldas/modbus-tcp-client/blob/48c46a8327667cbe25a59a33078eff2d6d482748/src/Packet/ModbusFunction/WriteSingleRegisterResponse.php#L17-L20
Hey, I have released new version 3.1.1
that fixes Packet::isCompleteLengthRTU
to understand write response length correctly
@ranjithphptech could you recheck with latest version?
my code use ModbusTcpClient\Network\BinaryStreamConnection; use ModbusTcpClient\Packet\ModbusFunction\WriteSingleRegisterRequest; use ModbusTcpClient\Packet\ModbusFunction\WriteSingleRegisterResponse; use ModbusTcpClient\Packet\RtuConverter; use ModbusTcpClient\Utils\Packet;
require DIR . '/../vendor/autoload.php'; require DIR . '/logger.php';
$connection = BinaryStreamConnection::getBuilder() ->setUri('/dev/ttyUSB0') ->setProtocol('serial') ->setIsCompleteCallback(static function ($binaryData, $streamIndex): bool { return Packet::isCompleteLengthRTU($binaryData); }) ->setLogger(new EchoLogger()) ->build();