资源简介
linux C获取PCI设备名和厂商名,编译时加上-lpci

代码片段和文件信息
#include
#include
#include
#include
#include
#include
#define PREPATH “/sys/bus/pci/devices/“
int get_pci_vendor_device_id( char *pciAddress int *vendor int *device );
int get_pci_name( int vendor int device char *name );
int
main( int argc char **argv )
{
int vendor device;
char name[ 256 ] = { 0 };
if( argc != 2 )
{
fprintf( stderr “usage: %s pciAddress\n“ argv[ 0 ] );
return -1;
}
if( get_pci_vendor_device_id( argv[ 1 ] &vendor &device ) )
{
fprintf( stderr “fail to get vendor and device id\n“ );
return -1;
}
printf( “vendor id[ %x ] device id[ %x ]\n“ vendor device );
if( get_pci_name( vendor device name ) )
{
fprintf( stderr “fail to get pci device name\n“ );
return -1;
}
return 0;
}
int
get_pci_vendor_device_id( char *pciAddress int *vendor int *device )
{
char vendorPath[ 256 ] = { 0 };
char devicePath[ 256 ] = { 0 };
char buf[ 256 ] = { 0 };
int fd len;
strcpy( vendorPath PREPATH );
strcat( vendorPath pciAddress );
strcat( vendorPath “/“ );
strcpy( devicePath vendorPath );
strcat( vendorPath “vendor“ );
strcat( devicePath “device“ );
if( ( fd = open( vendorPath O_RDONLY ) ) < 0 )
{
fprintf( stderr “path: %s\n“ vendorPath );
perror( “open“ );
return -1;
}
if( ( len = read( fd buf 256 ) ) > 0 )
{
buf[ len ] = ‘\0‘;
sscanf( buf “%x“ vendor );
}
close( fd );
if( ( fd = open( devicePath O_RDONLY ) ) < 0 )
{
fprintf( stderr “path: %s\n“ devicePath );
perror( “open“ );
return -1;
}
if( ( len = read( fd buf 256 ) ) > 0 )
{
buf[ len ] = ‘\0‘;
sscanf( buf “%x“ device );
}
close( fd );
return 0;
}
int
get_pci_name( int vendor int device char *name )
{
struct pci_access *pacc;
pacc = pci_alloc();
if( !pci_lookup_name( pacc name 256
PCI_LOOKUP_VENDOR
vendor device ) )
{
fprintf( stderr “fail to get pci vendor\n“ );
return -1;
}
printf( “vendor: %s\n“ name );
if( !pci_lookup_name( pacc name 256
PCI_LOOKUP_DEVICE
vendor device ) )
{
fprintf( stderr “fail to get pci device\n“ );
return -1;
}
printf( “device: %s\n“ name );
pci_cleanup( pacc );
return 0;
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2242 2016-02-03 16:04 PCIname\pci_name.c
目录 0 2016-02-03 16:09 PCIname
----------- --------- ---------- ----- ----
2242 2
- 上一篇:SVPWMPMSM.slx
- 下一篇:代价敏感支持向量机CSSVM
相关资源
- LinuxCNC_Getting_Started.pdf
- Linux C编程从入门到精通 光盘 源代码
- 高质量嵌入式LinuxC编程_试读版PDF电子
- linux c 编程一站式学习高清文字带目录
- Linuxcentos下的Apache安装压缩包:httpd
- LinuxCentOS6.5离线安装gcc
- linux C编程实战完整版pdf
- UNIX环境高级编程中文第三版 PDF 包含
- zw_Linuxc从入门到精通.zip
- 基于ARM平台的MP3播放器嵌入式开发设
- Linux C利用多进程或多线程模拟实现生
- linux多串口通信,usb-can控制八个电机
- linux C TCP/UDP客户端服务端的相互实时
- 精通LinuxC编程源代码
- linuxcnc插补算法函数调用关系图
- Linuxc 信号的使用
- zw_(linuxc)linux进程监控和进程守护程
- Linuxc聊天室,有日志功能可群聊可私
- 基于ARM平台Linux+Xenomai系统搭建及主站
- Linuxcentos下的Tomcat安装压缩包:apach
- Linux C 简单Shell 的实现
- QT在win10VS2017和linuxCentos7下编译的64位
- linuxc 高级编程之文件操作带截图
- LinuxC编程一站式学习.pdf
评论
共有 条评论