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
-
Have followed the instruction to read the string using this code, but just showing the first char. Anyone can help me?
![Screenshot (50)](https://private-user-images.githubusercontent.com/60589302/329110047-80d7fa69-70ec-43e1-9ae6-19a7f77bb599.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkyODMzMTMsIm5iZiI6MTczOTI4MzAxMywicGF0aCI6Ii82MDU4OTMwMi8zMjkxMTAwNDctODBkN2ZhNjktNzBlYy00M2UxLTlhZTYtMTlhN2Y3N2JiNTk5LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjExVDE0MTAxM1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTMwNjY2OWViOGNmNjdmYTcwODI3M2QyZDk2ZTA0MDhkZDY3MzE3MDlhZmM3NTg4NWJkNGNmZDJmYjYxMmJjMDYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.84N5_1TJNhGJOz16llPwsOzbd2lW1Fc_FvcCqwDNtZc)
Beta Was this translation helpful? Give feedback.
All reactions