-
-
Notifications
You must be signed in to change notification settings - Fork 8
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
Double defined line object, cannot call getValue or setValue funciton. #4
Comments
Hello @TaylorIsAGoodboy ! you mean if, for some reason, same line gets defined twice during code execution, it will fail? please provide a small project sampling the situation so i can try it on the hardware available here. |
I wrote a nodered node based on your library. I depoyed flow, it worked ok. But when I modified something, and depoyed again it shows error. Error may be "unable to get value for this line", "Segment fault" or "double free". Url of nodered node is https://github.com/TaylorIsAGoodboy/nodered-gpiod-node |
You can run the script below at two different term.
Do we have a way to release the line before we call |
Hello @TaylorIsAGoodboy, i just merged a contributed patch and will make another release! |
Hello, @TaylorIsAGoodboy
obviously, yes.
It is described in documentation: It helps alot. BTW, if you'll do obviously, descrtructor for the first object has to be called at the second line right before "line" object will be set to the new value. I think, It fails at desctructor. Check it with my update. If you'll experience the same problem just enable the debugging at chip.hh and see the calls sequence |
I guess it'd be possible to cache the line objects internally, but that would cause plenty of other issues. From my perspective the issue is not two line objects, but both calling My guess would be, that the event handler for close runs to late (see nodejs event handling) and the second node is executed before the close event was handled (though the first line object isn't released yet). |
Dear @noctarius ! also some things are useless. For example, if you get number of pins = 200 it means nothing - 80% of them could be preallocated and not available. The really useful thing that should be added is the way to find out the list of all GPIO chips available. |
OK, I will test it tommorrow. Thank you for your efforts! |
Hi @sombriks , the issue still existed. |
Hi @dmitrydvorkin, If your nodered node was ready, please share me the url, thank you. |
@TaylorIsAGoodboy i am building a test case for your specific issue, don't know if it helps but create several instances of lines are ok, but for some reason |
we might just need to know current line direction before request intput or output mode let's look for some useful call in the source. |
Yeah, but it may be done in requestMode funtion to avoid duplicate settings.
Taylor Lee 李远朝
Software Engineer 软件工程师 | China
E-mail: ***@***.*** | Mobile: +86 138 9185 6324
深圳市瑞科慧联科技有限公司 | Shenzhen RAKwireless Technology Co.,Ltd.
深圳市南山区桃源街道平山一路新视艺创客公园B栋506室
Room 506, Bldg B, New Compark, Pingshan First Road, Taoyuan Street,
Nanshan District, Shenzhen, China
www.RAKwireless.com | Twitter | YouTube | 微信公众号/官方微博:RAK瑞科慧联
From: Leonardo Silveira
Date: 2022-04-19 10:10
To: sombriks/node-libgpiod
CC: Taylor; Mention
Subject: Re: [sombriks/node-libgpiod] Double defined line object, cannot call getValue or setValue funciton. (Issue #4)
we might just need to know current line direction before request intput or output mode
https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/tree/lib/helpers.c?h=v1.6.x
let's look for some useful call in the source.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Yes, totally agree! |
I think the issue is a different one. From my perspective it's not about the direction, but you cannot reserve a line twice, that said, the previous reservation needs to be released before a new one can be acquired. It's luckily not a US airline carrier overbooking their flights ;-) |
if you'd run the code in debug mode (I added it in my commit) you can see: Error: ::requestOutputMode() failed do you see It simply returns the reference to previously allocated gpiod_line struct. Obviously we can't call gpiod_line_close_chip(line); till we have copy of this object in some other Line instance. How to do that correctly in NodeJS? I don't know. I'm thinking about some reference counter or thomething like this. This is the task for man who have good experience in NodeJS internals. |
Do you have some test code? Normally, to prevent an object from being GC'd (and hence deconstructed) you need to hold a hard reference to the object. For example by keeping a module local cache of all loaded chips (or by keeping it referenced in some object) and export a function which uses that cache. No need to sync for concurrency, since nodejs doesn't have concurrency (do to the event loop). This is basically what I do with our Port classes. And when creating a port, I reuse previously chip instances. That way you prevent the chip object from not being referenced and garbage collected.
|
test code:
@noctarius , I think it should be fixed with |
Haven't tested / really looked at it yet. Just making sure, NaN is a different C API adapter than Napi. Not sure you can mix and match them, also not really a nodejs developer :) edit: seems like https://github.com/nodejs/nan/blob/main/doc/persistent.md NaN offers a similar functionality with NaN::Persistent |
Yes, it may be the reason. I find the c libray to call And there is a |
with C library and direct ioctl commands you'll have same issue, but with "int fd" (file descriptor). there are should be the way to do it in NodeJS I have an idea: counstructor should be object Chips should be signletone too with method to get certain chip, like: |
i think NAN will help us moving to global/persistent instances will try something later |
it should be like this: thats all! |
OK, If ok, please tell me. I will test. Thank you. |
added a testcase for the double definition issue. basically we can define and redefine a line as many times we want as long we release the line. pin is a limited resource so i think it makes sense. and finally we have a few instructions on how to run the gpio-sim, that might help to understand the issue furthermore. for now i am closing this issue because error handling either got better or libgpiod itself evolved since then. |
Hi, Leonardo
I defined line twice, then it occured "Error: Unable to get value for this line".
Is there some way to this error.
I make a nodered node which based on your node-libgpiod library. The first time is good,then move debug node and deploy again, error occurs. I think the reason it i double defined line object.
The text was updated successfully, but these errors were encountered: