48 IIODevice(
const std::string &devicePathIn,
const std::string &chipNameIn) {
50 devicePath=devicePathIn;
53 readDev=
"/dev/iio:device"+devicePath.substr(devicePath.find(
":device")+7);
71 std::string scanPath=devicePath+
"/scan_elements";
72 std::string extName=
"_en";
74 ds.
findAll(std::vector<std::string>());
79 for (
unsigned int i=0; i<ds.size(); i++) {
80 std::ifstream inputF((scanPath+
"/"+ds[i]).c_str());
87 iIOChannel.
chName=ds[i].substr(0,ds[i].length()-extName.length());
94 push_back(iIOChannel);
100 std::cout<<
"IIODevice : bufferSize="<<
getBufferSize()<<std::endl;
114 std::cout<<
"chip "<<chipName<<std::endl;
117 for (
unsigned int i=0; i<
getChCnt(); i++) {
118 std::cout<<
"\n channel "<<i<<
'\n';
119 operator[](i).printInfo();
128 #ifdef IIO_NONBLOCK_READS 129 int flags|=O_NONBLOCK;
141 int cntRead=0, cntWrite=0;
142 for (
unsigned int i=0; i<
size(); i++)
143 if (
operator[](i).isReadCh())
147 if (cntRead!=0 && cntWrite!=0)
152 fd=
::open(readDev.c_str(), flags);
183 uint bytesToRead=frames*bytesPerFrame;
187 #ifdef IIO_NONBLOCK_READS 188 struct pollfd pfd = { .fd =
fd, .events = POLLIN,};
192 ssize_t
N=
::read(fd, buf, bytesToRead);
193 if (N!=bytesToRead) {
195 return N/bytesPerFrame;
197 std::cout<<
"read returned "<<N<<
"\n";
199 std::cout<<
"nothing available\n";
201 std::cout<<strerror(errno)<<
"\n";
217 unsigned int frameSize=operator[](0).bitCnt/8;
218 for (
unsigned int i=1; i<
size(); i++)
219 if (
operator[](i).bitCnt/8 != frameSize)
229 std::ofstream enableFile((devicePath+
"/buffer/enable").c_str());
230 if (!enableFile.good())
241 std::ifstream lengthFile((devicePath+
"/buffer/length").c_str());
242 if (!lengthFile.good())
245 lengthFile>>bufferSize;
254 std::ofstream lengthFile((devicePath+
"/buffer/length").c_str());
255 if (!lengthFile.good())
257 lengthFile<<bufferSize;
285 #endif // IIODEVICE_H_
#define IIODEVICE_FILE_OPEN_ERROR
Error when trying to open an IIODevice subdirectory file.
#define IIODEVICE_OPEN_ERROR
Couldn't open the device.
IIODevice(const std::string &devicePathIn, const std::string &chipNameIn)
virtual int evaluateError(int errorNum)
int getChannelBufferCnt()
std::string chName
The name of each of the enabled channels.
std::string chipName
The device chip name.
#define NO_ERROR
There is no error.
#define IIODEVICE_ENABLEFILE_ERROR
There was an error when trying to open the buffer enable file.
float scale
How to scale the input value to get a real world value.
#define IIODEVICE_READ_ERROR
There was an error whilst reading from a device.
#define IIODEVICE_READANDWRITE_ERROR
Don't know how to hbandle read and write yet.
int findAll(const std::vector< std::string > &dontInclude)
int setBufferSize(int bufferSize)
std::string chGenericName
The generic name of each of the enabled channels.
#define IIODEVICE_WRITEABLE_ERROR
Don't know how to write yet.
uint getChFrameSize(void)
int read(uint frames, void *buf)
std::string devicePath
The device path.
int fd
The file descriptor of the open device.
int setChannelBufferCnt(int chBufferCnt)
int scanElements(std::string scanPath, uint cIndex)
#define IIODEVICE_NOCHANNELS_ERROR
Error when trying to open the device, but the channels aren't initialised.
void keepWithPattern(const std::string pattern)
#define IIODEVICE_FRAEMSIZE_MISMATCH_ERROR
The frame sizes differ between channels on one device.
#define IIODEVICE_LENGTHFILE_ERROR
There was an error when trying to open the buffer length file.
std::string readDev
The read buffer device, e.g. "/dev/iio:device0".