-
Notifications
You must be signed in to change notification settings - Fork 60
Description
I use this example script to communicate with Solax X3 G4 on COM port using RS485/ETH converter a then using modbus RTU over TCP protocol:
<?php
use ModbusTcpClient\Network\BinaryStreamConnection;
use ModbusTcpClient\Packet\ModbusFunction\ReadHoldingRegistersRequest;
use ModbusTcpClient\Packet\RtuConverter;
use ModbusTcpClient\Utils\Packet;
require '../vendor/autoload.php';
$connection = BinaryStreamConnection::getBuilder()
->setPort(myPort)
->setHost('myIP')
->setReadTimeoutSec(3) // increase read timeout to 3 seconds
->setIsCompleteCallback(function ($binaryData, $streamIndex) {
return Packet::isCompleteLengthRTU($binaryData);
})
->build();
$startAddress = 182;
$quantity = 1;
$slaveId = 1; // RTU packet slave id equivalent is Modbus TCP unitId
$tcpPacket = new ReadHoldingRegistersRequest($startAddress, $quantity, $slaveId);
$rtuPacket = RtuConverter::toRtu($tcpPacket);
try {
$binaryData = $connection->connect()->sendAndReceive($rtuPacket);
echo 'RTU Binary received (in hex): ' . unpack('H*', $binaryData)[1] . PHP_EOL;
$response = RtuConverter::fromRtu($binaryData);
echo 'Parsed packet (in hex): ' . $response->toHex() . PHP_EOL;
echo 'Data parsed from packet (bytes):' . PHP_EOL;
print_r($response->getData());
} catch (Exception $exception) {
echo 'An exception occurred' . PHP_EOL;
echo $exception->getMessage() . PHP_EOL;
echo $exception->getTraceAsString() . PHP_EOL;
} finally {
$connection->close();
}
?>- Environment:
- OS: Linux 5.10.0-vch1-amd64 x86_64
- PHP version: 8.2.7
- Library version 3.4.0
If I try to insert the same input data into any Windows EXE program used to test modbus RTU over TCP communication, then there is no problem, everything communicates as it should. But if I use them in the PHP code, see above, the result is always the error "An exception occurred stream_select interrupted by an incoming signal".
Specifically:
An exception occurred stream_select interrupted by an incoming signal #0 /home/www/xxx.cz/www/fve.xxx.cz/vendor/aldas/modbus-tcp-client/src/Network/BinaryStreamConnection.php(67): ModbusTcpClient\Network\BinaryStreamConnection->receiveFrom() #1 /home/www/xxx.cz/www/fve.xxx.cz/vendor/aldas/modbus-tcp-client/src/Network/BinaryStreamConnection.php(90): ModbusTcpClient\Network\BinaryStreamConnection->receive() #2 /home/www/xxx.cz/www/fve.xxx.cz/ote/rtu.php(27): ModbusTcpClient\Network\BinaryStreamConnection->sendAndReceive() #3 {main}
It looks like a library bug. Please help.