aldas / modbus-tcp-client

PHP client for Modbus TCP and Modbus RTU over TCP (can be used for serial)
Apache License 2.0
192 stars 55 forks source link

Extend the maximum read time of a request in higher level #44

Closed marioshtika closed 4 years ago

marioshtika commented 4 years ago

Hello @aldas ,

I am using your example on parallel request with amp. I am trying to simultaneously connect and read multiple units.

Some of the request are giving me the below error

Connecting to tcp://192.168.0.223:502 failed: timeout exceeded (10000 ms)

In the low level I am using the ->setReadTimeoutSec(20) command. Is there a way to do the same in the higher level?

Thank you in advance.

aldas commented 4 years ago

You can set Context for connect() method

            $connectContext = (new ConnectContext)->withConnectTimeout(1000); // 1sec
            /** @var \Amp\Socket\ClientSocket $socket */
            $socket = yield connect($request->getUri(), $connectContext);

but connect timeout and read timeout are different things.

aldas commented 4 years ago

Closing this ticket atm. PhpAmp library related questions are better to be asked at their repo.