#include #include #include "C:/Advantech/DAQNavi/Examples/C++_Console/inc/compatibility.h" #include "C:/Advantech/DAQNavi/Inc/bdaqctrl.h" #include #include 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; printf("Podaj faze: "); scanf("%lf", &faza); double volt; int i = 0; LARGE_INTEGER start, end, freq; QueryPerformanceCounter(&start); QueryPerformanceFrequency(&freq); printf("%ld", freq.QuadPart); while (1) { if( kbhit()) { c = getchar(); 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 'e': exit(0) ; 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(); }