-
Notifications
You must be signed in to change notification settings - Fork 6
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
Read Timeout? #3
Comments
Hey! I think this can be easily solved by initialising socket as non-blocking function readUntil(CanBus $bus, int $timeout = 500, int $delayMs = 10): ?CanFrame {
$cutOff = microtime(true) + ($timeout / 1000); // Time in the future where we should no longer wait
while(microtime(true) <= $cutOff) {
$frame = $bus->read();
if($frame !== false) {
return $frame;
}
usleep($delayMs); // Sleep some time to reduce CPU busy time
}
return null;
} Or if you'd like to return CanFrame|false: function readUntil(CanBus $bus, int $timeout = 500, int $delayMs = 10): CanFrame|bool {
$cutOff = microtime(true) + ($timeout / 1000); // Time in the future where we should no longer wait
$frame = false;
while(microtime(true) <= $cutOff && $frame === false) {
$frame = $bus->read();
if($frame === false) {
usleep($delayMs);
}
}
return $frame;
} To make it nice an clean in your project, you could extend CanBus class and add new |
@yachtwave Did it solve your problem? |
Hi, Piotr. I haven't had a chance to test it, but you can consider this
resolved. I greatly appreciate it - john
…--
Capt. John O'Keefe
FOUNDER, YACHTWAVE
USCG 100 GT MASTER
www.yachtwave.com | ***@***.*** ***@***.***>
935 N Beneva Rd, Ste 609, Sarasota, FL 34232
<https://maps.google.com/?q=935+N+Beneva+Rd,+Ste+609+PMB+2056,+Sarasota,+FL+34232>
On Mon, May 13, 2024 at 3:20 AM Piotr Adamczyk ***@***.***> wrote:
@yachtwave <https://github.com/yachtwave> Did it solve your problem?
—
Reply to this email directly, view it on GitHub
<#3 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/A7OOXAFBTKKUJ3M6W5BSUSLZCBSVBAVCNFSM6AAAAABHGGFWVWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMBWHAZTCOJWGQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Anyway, can you get a timeout on the "read"? For example, if the data on the network stops (for whatever reason), the process sits at the "read command" waiting for data. When used as a service with a watchdog, the watchdog needs to be pinged every 30 seconds, which can not happen when the code is stuck at the ->read function. please help!
The text was updated successfully, but these errors were encountered: