-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
connection refused #94
Comments
modbus-tcp-client/src/Network/NonBlockingClient.php Lines 121 to 156 in c39a0e5
seems the issue was here. if the connection was too fast it will return connection refused i try to add sleep(1); after line 132 everything was working. but i dont think this is the perfect solution |
i try something like this. and i dont have any error at all |
How many requests are you sending in parallel? I assume you are using examples/example_parallel_requests.php based code? If you use If doing serially is OK you could just make little helper function to send requests like that: function sendsRequests(array $requests): array
{
$connection = BinaryStreamConnection::getBuilder()
->setPort('5022')
->setHost('127.0.0.1') // we assume that port and ip is not different over requests
->setConnectTimeoutSec(1.5) // timeout when establishing connection to the server
->setWriteTimeoutSec(0.5) // timeout when writing/sending packet to the server
->setReadTimeoutSec(1.0) // timeout when waiting response from server
->build();
try {
$connection->connect();
$results = [];
foreach ($requests as $index => $request) {
$binaryData = $connection->sendAndReceive($request->getRequest()); // send/receive request serially
$response = $request->parse($binaryData);
if ($response instanceof ErrorResponse) {
throw new ModbusException('sendRequests resulted with modbus error. msg: ' . $response->getErrorMessage());
}
$result[$index] = $response;
}
$result = new ResultContainer($results, []);
return $result->getData(); // extract data to assoc array
} finally {
$connection->close();
}
}
$requests = ReadRegistersBuilder::newReadHoldingRegisters('tcp:https://127.0.0.1:5022')
->bit(256, 15, 'pump2_feedbackalarm_do')
// will be split into 2 requests as 1 request can return only range of 124 registers max
->int16(657, 'battery3_voltage_wo')
->build(); // returns array of 2 requests
print_r(sendsRequests($requests)); |
probably changing return to would help return array_merge(...$result->getData()); |
im doing something like this
|
hi, i dont really know if this an issue or not
i try to read the register from address 1 to 65 it was working fine
but then i add to read register for 2001 till 2016 it will have connection refused error
i have try to read address 1 and 2001 only and have the same error
but after i remove the 2001 everything working fine
i try to read only from 2001 to 2016 it was working fine
the problem only occur when i combine both address
===
seems the problem only occur if when the address is to big
i try to read 100 and 200 working fine
then read 100, 200 and 300 will return connection refused
but if i read 200 and 300 working fine again
The text was updated successfully, but these errors were encountered: