tic  130
tic_freq.cxx
/*
* TINA demo programm
*/
#include <iostream>
#include <iomanip>
#include "tic/tap.hxx"
#include "rio/rio.hxx"
namespace Tina=INdepTina100;
namespace Dev=INdepDev100;
namespace Rio=INdepRio100;
namespace Umi=INdepUmi100;
#ifdef MMSYS_linux
const char *szDev0 = "/dev/irio/0";
#else
const char *szDev0 = "\\\\.\\INRIO_LCL_0" ;
#endif
#if defined(MMSYS_linux)
#include <sys/select.h>
int kbhit()
{
struct timeval tv = { 0L, 0L };
fd_set fds;
FD_ZERO(&fds);
FD_SET(0, &fds);
return select(1, &fds, NULL, NULL, &tv);
}
#else
#include <conio.h>
int kbhit() { return _kbhit(); }
#endif
int main(int argc, char **argv) {
if (1) {
std::cout << "initializing " << szDev0 << std::endl;
if (!ti0) { std::cerr << "ti0 failed: " << ti0 << std::endl; return 2; }
if (1) {
/* stimulus pulse generator */
Tina::PumoFreq pm(2.0E05,0.5);
ti0.pTip()->callTicConfig(&tcm);
ti0.ptp()->callPulseConfig(&pm);
}
Tina::TinaPlex *ptp=ti0.ptp();
do {
if (1) {
Tina::ModeAvg tm(1000, 1, UmiTime(1));
tm.setLog(&std::cout);
ptp->callTinaConfig(&tm);
ti0.pTip()->callTicArm();
do {
ptp->callTinaSample(&tm);
if (!tm) {
std::cerr << "error: " << tm << std::endl;
return 2;
}
else {
/* valid data */
}
} while ( tm.isGood() && !tm.isDone() && !kbhit() );
if (!tm.isGood()) break;
std::cout << "freq=" ;
while (tm.cMeas()) std::cout << std::setprecision(8) << tm.rdFreq() << " ";
std::cout << std::endl;
}
if (1) {
//tm.setLog(&std::cout);
//tm.setLimit();
ti0.ptp()->callTinaConfig(&tm);
do {
ti0.pTip()->callTicArm(); // sample arm
ti0.ptp()->callTinaSample(&tm);
if (!tm) {
std::cerr << "error: " << tm << std::endl;
return 2;
}
} while ( tm.isGood() && !tm.isDone() && !kbhit() );
if (!tm.isGood()) break;
std::cout << "width=" ;
while (tm.cSamp()) {
double rd=tm.rdPulseWidth();
std::cout << rd << " ";
if (rd > 0.5) {
std::cerr << "width error" << std::endl;
return 2;
}
}
std::cout << std::endl;
}
if (1) {
int c=0; // isDone() broken
Tina::ModePulse tm('H', 2);
//tm.setLog(&std::cout);
ti0.ptp()->callTinaConfig(&tm);
do {
ti0.pTip()->callTicArm();
ti0.ptp()->callTinaSample(&tm);
if (!tm) {
std::cerr << "error: " << tm << std::endl;
return 2;
}
} while ( c++ < 10 && tm.isGood() && !tm.isDone() && !kbhit() );
if (!tm.isGood()) break;
std::cout << "pulse=" ;
while (tm.cSamp()) {
std::pair<double, double> pard=tm.pardPulse();
std::cout << pard.first << "," << pard.second << " ";
}
std::cout << std::endl;
}
if (1) {
//tm.setLog(&std::cout);
ti0.ptp()->callTinaConfig(&tm);
do {
//usleep(5000);
ti0.pTip()->callTicArm();
ti0.ptp()->callTinaSample(&tm);
if (!tm) {
std::cerr << "error: " << tm << std::endl;
return 2;
}
else {
/* valid data */
}
} while ( tm.isGood() && !tm.isDone() && !kbhit() );
if (!tm.isGood()) break;
std::cout << "count=" ;
while (tm.cSamp()) std::cout << tm.count() << " ";
std::cout << std::endl;
}
} while (!kbhit());
}
return 0;
}