这是我关于脂质传感器的代码。图书馆:
#include <unistd.h>
#include <sensors/sensors.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdlib.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <string.h>
#include <math.h>关于锂传感器的代码:
char sd[16384]="^\0",bf[1];
char buf2[8192]="^\0";
sensors_chip_name const* scn;
int c=0;
int t4=1;
while((scn=sensors_get_detected_chips(0,&c))!=0)
{
sensors_feature const *fea;
int f=0;
strcat(sd,scn->prefix);
printf("%s",scn->prefix);
strcat(sd,":");
strcat(sd,scn->path);
strcat(sd,"(");
while((fea=sensors_get_features(scn,&f))!=0)
{
strcat(sd,fea->name);
strcat(sd,"(");
sensors_subfeature const *sb;
int s=0;
while((sb=sensors_get_all_subfeatures(scn,fea,&s))!=0)
{
t4++;
strcat(sd,sb->name);
strcat(sd,",");
int t3=-1;
int i=0;
char t8[sizeof(sb->number)];
memcpy(&t8,&(sb->number),sizeof(sb->number));
strcat(sd,t8);
strcat(sd,"!");
}
strcat(sd,")");
}
strcat(sd,")");
}所以当我试图打印任何东西时,什么都不会发生。称为sd的char数组返回空。似乎根本就没有传感器可读。
当我从终端运行sensors时,它运行的非常好。我看到了几个核心和芯片温度。
我在这里的某个帖子中实现了这个代码,坦率地说,我并不完全理解它。
发布于 2021-07-21 07:57:28
发布https://stackoverflow.com/users/3629249/user3629249评论作为一个社区的答案。
它需要首先调用sensors_init(),否则芯片列表将为空。
这个函数需要一个sensors配置文件作为参数,或者NULL使用默认的配置文件。
此外,您还可以在这个相关问题中找到一个用法示例:Has anyone been able to use libsensors properly?
https://stackoverflow.com/questions/32854537
复制相似问题