简体   繁体   English

在libgpiod中使用ctxless函数是否更糟或更好

[英]Are ctxless functions worse or better to use in libgpiod

Is there anyone out there familiar with libgpiod who could answer this question: 有没有人熟悉libgpiod可以回答这个问题:

Are there any draw backs to using ctxless function rather than calling individual function to manipulate chip lines (or in general)? 是否有使用ctxless函数的缺点而不是调用单个函数来操作芯片线(或一般)? For example, to turn on a line, I might write something like: 例如,要打开一行,我可能会写一些类似于:

struct gpiod_chip* chip = gpiod_chip_open_by_name("gpiochip2");
struct gpiod_line* line = gpiod_chip_get_line(chip, 10);
gpiod_line_request_output(line, "foo", 0);
gpiod_chip_close(chip);

or I could simply use a single call: 或者我可以简单地使用一个电话:

gpiod_ctxless_set_value("gpiochip2", 10, 1, false, "foo", NULL, NULL);

When would you use one over the other? 你什么时候用一个而不是另一个?

The ctxless function are great to quickly set or get the value of a GPIO. ctxless函数非常适合快速设置或获取GPIO的值。 However, I would keep that for one time use over the life cycle of your program. 但是,我会在程序的生命周期中保留一次。

The reason is that using the ctxless functions, libgpiod will have to always redo the same setup (opening the gpiochip, requesting the line, setting its direction) and then get or set the value. 原因是使用ctxless函数,libgpiod必须总是重做相同的设置(打开gpiochip,请求行,设置其方向),然后获取或设置值。

If you are reading or setting the value multiple times in your program, you should probably not use the ctxless functions. 如果您在程序中多次读取或设置该值,则可能不应使用ctxless函数。

Moreover, keeping the line requested for the life of your program is definitively a good thing at this will prevent any other program to use that GPIO. 此外,保持程序生命周期所需的行确定是一件好事,这将阻止任何其他程序使用该GPIO。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM