Linux中的libiio编程实践
来源:互联网 发布:p2psearcher这样的软件 编辑:程序博客网 时间:2024/05/06 08:38
开发板:Omapl138
AD模块:AD7606
1 交叉编译libiio
关于libiio的交叉编译,见《Linux中交叉编译libiio》。
2 简单实例
#include <iio.h>#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <string.h>/* * 功 能: 通道属性检索 * 参 数: chn —— AD 通道 * attr —— 需要检索的属性 * 返 回: true —— AD通道存在属性attr * false —— AD通道不存在属性attr */static bool channel_has_attr(struct iio_channel *chn, const char *attr){unsigned int i, nb = iio_channel_get_attrs_count(chn);for (i = 0; i < nb; i++)// printf("channel attr = %s\n", iio_channel_get_attr(chn, i));if (!strcmp(attr, iio_channel_get_attr(chn, i)))return true;return false;}/* * 功 能: 获取通道chan的采样值 * 参 数: chn —— AD 通道 * 返 回: chn 通道的采样值 */static double get_channel_value(struct iio_channel *chn){char buf[1024];double val;if (channel_has_attr(chn, "processed")) {iio_channel_attr_read(chn, "processed", buf, sizeof(buf));val = strtod(buf, NULL);} else {iio_channel_attr_read(chn, "raw", buf, sizeof(buf));val = strtod(buf, NULL);if (channel_has_attr(chn, "offset")) {iio_channel_attr_read(chn, "offset", buf, sizeof(buf));val += strtod(buf, NULL);}if (channel_has_attr(chn, "scale")) {iio_channel_attr_read(chn, "scale", buf, sizeof(buf));val *= strtod(buf, NULL);}}val = val * 5 / 32768.0;return val;}int main(void){struct iio_context *ctx;unsigned int i, nb_devices;unsigned int nb_channels;double channel_value;struct iio_device *dev;struct iio_channel *chn;// create contextctx = iio_create_local_context();if ( !ctx) {printf("create context failed\n");exit(0);}// get device countnb_devices = iio_context_get_devices_count(ctx);// get device namedev = iio_context_get_device(ctx, 0);nb_channels = iio_device_get_channels_count(dev);chn = iio_device_get_channel(dev, 0);printf("channel_value:\n");for (i = 0; i < 100000; i++) {channel_value = get_channel_value(chn);printf("%.2f\n", channel_value);sleep(1);}iio_context_destroy(ctx);return 0;}
参考资料
[1]What is libiio?
[2]libiio_Main Page
[3]About libiio
[4]iio-trig-sysfs driver
[5]IIO Command Server
[6][RFC] LIBIIO
[7]libiio buffering
[8]How to Get Analog Input on the BeagleBone Black
[9]How to use the Linux Industrial IO (IIO) interface
[10]AM335x ADC Driver's Guide
[11]AD7606: Data capture by setting sampling frequency & buffer mode
[12]IIO, a new kernel subsystem
[13]Why this program can't receive the right data?
[14]linux-3.2.20/drivers/staging/iio/industrialio-buffer.c
[15]Linux Core ADC User's Guide
[16]am335x adc调试
0 0
- Linux中的libiio编程实践
- Linux中交叉编译libiio
- linux信号编程实践
- linux网络编程实践
- Java编程中的最佳实践
- Unix/Linux编程实践教程
- Unix/Linux编程实践教程
- Linux多线程编程(实践)
- Linux编程实践教程小结
- Unix-linux编程实践教程
- Linux信号编程实践(三) 信号在内核中的表示(sigaction&sigqueue)
- JavaScript中的函数式编程实践
- JavaScript 中的函数式编程实践
- 面试中的智力题及编程实践
- JavaScript 中的函数式编程实践
- Android中的JNI和NDK编程实践
- JavaScript 中的函数式编程实践
- Linux中的curses编程
- js常用返回网页顶部几种方法
- MFC Windows编程基础( 学习记录2015.3)
- 剖析PHP中的输出缓冲 flush之类
- IOS打包发布APP的所有详细流程
- scala学习笔记06--主从构造器
- Linux中的libiio编程实践
- CALayer简介 (九)CGContext、CALayer、UIView的关系
- 第4周课后实践·阅读程序-构造函数和析构函数(4)
- HDOJ 题目A very hard Aoshu problem(暴力,DFS)
- Java关键字final、static使用总结
- scala学习笔记07--样本类(case class)和模式匹配
- Coin3D与VS2010编译过程
- 约瑟夫环问题
- 浅谈算法和数据结构: 五 优先级队列与堆排序