#include <stdlib.h>
#include <stdio.h>
#include "C:/Advantech/DAQNavi/Examples/C++_Console/inc/compatibility.h"
#include "C:/Advantech/DAQNavi/Inc/bdaqctrl.h"
#include <math.h>
#include <Windows.h>
using namespace Automation::BDaq;
//-----------------------------------------------------------------------------------
// Configure the following three parameters before running the example
//-----------------------------------------------------------------------------------
#define deviceDescription L"PCI-1710HG,BID#0"
#define PI 3.141592
#define N 50
int32 startChannel = 0;
const int32 channelCount = 1;
inline void waitAnyKey()
{
do { SLEEP(1); } while (!kbhit());
}
void InstantAO();
void nanoSleep()
{
}
int main(int argc, char* argv[])
{
nanoSleep();
InstantAO();
return 0;
}
void InstantAO()
{
ErrorCode ret;
// Step 1: create 'InstantAoCtrl' object
InstantAoCtrl * ctrl = AdxInstantAoCtrlCreate();
do
{
// Step 2: select the device with 'ModeWriteWithReset' mode
int deviceNumber = 0;
DeviceInformation devInfo(deviceNumber);
ret = ctrl->setSelectedDevice(devInfo);
if (ret != Success) {
printf("open device failed. error code = %x\n", ret
);
break;
}
// Step 3: *** configure the channels if needed ***
AoChannelCollection *channels = ctrl->getChannels();
for (int i = 0; i < channels->getCount(); ++i) {
channels->getItem(i).setValueRange(V_0To5);
}
// Step 4: scan the channels
int32 const chStart = 0;
int32 const chCount = 2;
// generate waveform data
double values[chCount];
double valuess[chCount];
char c;
double Am = 1;
double v[N];
double T = 0.00001; //1s
double delta = T / N;
double faza=0;
double volt;
int i = 0;
LARGE_INTEGER start, end, freq;
QueryPerformanceCounter(&start);
QueryPerformanceFrequency(&freq);
while (1)
{
if( kbhit()) {
switch (c) {
case 'w': Am += 0.1; break;
case 's':Am += -0.1; break;
case 'd': {T += 50;
break; }
case 'a': {T += -50;
break; }
case 'f': {faza += 0.1;
break; }
case 'v': {faza += -0.1;
break; }
}
}
values
[0] = Am
*sin(i
* 2*PI
/N
) +2.5;
ctrl->Write(chStart, 1, values);
valuess
[0] = Am
*sin(i
* 2 * PI
/ N
+faza
) + 2.5;
ctrl->Write(chStart+1, 1, valuess);
do{
QueryPerformanceCounter(&end);
} while (end.QuadPart < (start.QuadPart + 290));
start.QuadPart += 290;
i++;
i %= N;
}
//ctrl->Write(chStart, chCount, values);
} while (false);
// Step 5: close device and release any allocated resource.
ctrl->Cleanup();
// Step 6: destroy the object
ctrl->Dispose();
}
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}