-
Notifications
You must be signed in to change notification settings - Fork 103
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
Throw an exception when running wait_for_edge() in a new thread #28
Comments
@ShimmyShaman Can you check this issue please? |
As long as the two channels are different channels the usage is okay. There should've been more error detail (at least to the console) for why the edge file cannot be opened (submitted pull request addresses this). Try again with that, and at least find out why. If not then I won't get my hands on my Jetson device for another 2-3 days to check it out. |
Thanks for the reply. I added the std::perror() and tried again. sysfs/edge open: Too many open files And I checked the /proc/$pid/fd. There are hundreds of records like: /sys/devices/2200000.gpio/gpiochip0/gpio/gpio428/value |
I found it is irrelevant to multi-threading. If I run it independently on a single channel for a long time, I will get the same error. #include <chrono>
#include <thread>
#include <signal.h>
#include <sys/time.h>
#include <JetsonGPIO.h>
static bool end_this_program = false;
void signalHandler(int s) { end_this_program = true; }
void delay(int s) { std::this_thread::sleep_for(std::chrono::seconds(s)); }
int main()
{
signal(SIGINT, signalHandler);
int pwm_input = 11;
GPIO::setmode(GPIO::BOARD);
GPIO::setup(pwm_input, GPIO::IN);
struct timeval start, end;
int high;
while (!end_this_program)
{
printf("start to listen...\n");
GPIO::wait_for_edge(pwm_input, GPIO::Edge::RISING);
gettimeofday(&start,NULL);
GPIO::wait_for_edge(pwm_input, GPIO::Edge::FALLING);
gettimeofday(&end,NULL);
high = end.tv_usec - start.tv_usec;
printf("high voltage time: %d us\n", high);
if(high>1500 && high<=2000)
{
printf("received save flag\n");
}
}
GPIO::cleanup();
return 0;
} |
Yeap, right on, a file wasn't being closed when it should've been. Good error report. Added pull request. The files get closed now and the records don't pile up in /proc/$pid/fd |
Thanks! Now it runs fine. |
bug fix for issue #28 and private/PythonFunctions/format function.
@frostcza Thank you for confirming and the error report. Merged the pull request. Closed the issue. |
Hello, I'm trying to use GPIO::wait_for_edge() to calculate the high level duration of a PWM signal input like this:
` struct timeval start, end;
It works well when executed independently. But I want to check two channels at the same time. And when I create two threads to run the same function, it works well for a while (about 1 minute) and then throws the exception:
[Exception] Failure to open the /sys/class/gpio/gpio{$ch}/edge file (catched from: GPIO::wait_for_edge())
terminate called after throwing an instance of 'std::runtime_error'
what(): Failure to open the /sys/class/gpio/gpio{$ch}/edge file
Aborted (core dumped)
Do you have any clue for this? Thank you.
The text was updated successfully, but these errors were encountered: