我如何从用户应用程序读取 sysfs 属性。它与 cat 命令的内容类似。比如我有一个标签是亮度。如何获取亮度标签的值?因为我需要从我的应用程序读取 USB 信息,并且我看到它们被导出到 sysfs,如下拓扑所示:
ls /sys/bus/usb/devices/1-1
1-1:1.0 busnum port
authorized configuration power
avoid_reset_quirk descriptors product
bConfigurationValue dev quirks
bDeviceClass devnum removable
bDeviceProtocol devpath remove
bDeviceSubClass driver serial
bMaxPacketSize0 ep_00 speed
bMaxPower idProduct subsystem
bNumConfigurations idVendor uevent
bNumInterfaces ltm_capable urbnum
bcdDevice manufacturer version
bmAttributes maxchild
最佳答案
使用例如打开文件fopen("//sys/bus/usb/devices/1-1/version", "rt")
并像读取任何其他文件一样读取其内容。不确定亮度,您没有提及它在哪个文件中,并且没有具有该名称的文件。
关于c - 我如何读取 sysfs 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33391792/