Replies: 1 comment 9 replies
-
You could try to debug log what is send and what is received. Maybe it is endianess problem. Maybe charset <?php
session_start();
require __DIR__ . '/vendor/autoload.php';
require __DIR__ . '/logger.php';
use ModbusTcpClient\Composer\Read\ReadRegistersBuilder;
use ModbusTcpClient\Network\NonBlockingClient;
use ModbusTcpClient\Utils\Endian;
Endian::$defaultEndian = Endian::BIG_ENDIAN_LOW_WORD_FIRST;
$addressPLC = 'tcp://127.0.0.1:502';
// READ REGISTER DATA
$fc3 = ReadRegistersBuilder::newReadHoldingRegisters($addressPLC)
->string(4, 6, 'dataString')
->build();
try {
$responseFC3 = (new NonBlockingClient([
'readTimeoutSec' => 0.2,
'logger' => new EchoLogger()
]))->sendRequests($fc3);
$dataModbusFC3 = $responseFC3->getData();
$errorModbusFC3 = $responseFC3->getErrors();
print_r($dataModbusFC3);
} catch (Exception $exception) {
echo 'An exception occurred' . PHP_EOL;
echo $exception->getMessage() . PHP_EOL;
echo $exception->getTraceAsString() . PHP_EOL;
} That logger source is here https://github.com/aldas/modbus-tcp-client/blob/master/examples/logger.php |
Beta Was this translation helpful? Give feedback.
9 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Have followed the instruction to read the string using this code, but just showing the first char. Anyone can help me?

Beta Was this translation helpful? Give feedback.
All reactions