Custom serial port settings #163
-
Hi! |
Beta Was this translation helpful? Give feedback.
Answered by
aldas
Oct 9, 2024
Replies: 1 comment 1 reply
-
just edit it in https://github.com/aldas/modbus-tcp-client/blob/master/examples/rtu_usb_to_serial.php or if you are using https://github.com/aldas/modbus-tcp-client/blob/master/examples/rtu_usb_to_serial_stream.php then pass it from constructor and you can change defaults like that $connection = BinaryStreamConnection::getBuilder()
->setUri('/dev/ttyUSB0')
->setCreateStreamCallback(function (BinaryStreamConnection $conn) {
$streamCreator = new SerialStreamCreator(['sttyModes' => SerialStreamCreator::DEFAULT_STTY_MODES]);
return $streamCreator->createStream($conn);
})
->setIsCompleteCallback(static function ($binaryData, $streamIndex): bool {
return Packet::isCompleteLengthRTU($binaryData);
})
// delay this is crucial for some serial devices and delay needs to be long as 100ms (depending on the quantity)
// or you will experience read errors ("stream_select interrupted") or invalid CRCs
->setDelayRead(100_000) // 100 milliseconds, serial devices may need delay between sending and received
->setLogger(new EchoLogger())
->build(); NB: I did not test it at the moment |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
LaQuiete1988
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
just edit it in https://github.com/aldas/modbus-tcp-client/blob/master/examples/rtu_usb_to_serial.php
or if you are using https://github.com/aldas/modbus-tcp-client/blob/master/examples/rtu_usb_to_serial_stream.php
then pass it from constructor and you can change defaults
modbus-tcp-client/src/Network/SerialStreamCreator.php
Line 54 in b18323b
like that