myIO.cpp - the DAQ class

implementation of most data acquisition functions


This is the most complex part of the program. Since it is grown code, it is not too structured and grouped. A clean up wouldn't have hurt. But as said already: the code was not written for beauty, but for getting a working solution. And actually it does work.
The PowerDAQ-API gets used pretty much in this class.

#ifndef __nada__ #define __nada__

#include "myIncludes.h"

// *****     ***     ***       *****     ***     ***
// **   **  ** **   ** **      **   **  ** **   ** **
// **   ** **   ** **   **     **   ** **   ** **   **
// **   ** ******* **   **     **   ** ******* **   **
// **   ** **   **  ** ***     **   ** **   **  ** ***
// *****   **   **   *** **    *****   **   **   *** **

DAQ::DAQ() : i(0), namecount (0), hAdapter(NULL), duration (640),
bAOutStop (FALSE), dwDataCnt(0), dwAoCfg ( AOB_CVSTART0 | AOB_DMAEN),
dwMode (BUF_BUFFERWRAPPED |BUF_DWORDVALUES), sinemult(160),
dwAoScanSamples (0x2), aofreq (AOFREQ), //aofreq determines the analog output frequency
dwAoFrmScans (11000*2),//@ 32kHz output freq each 1 equals 1 ms duration of the buffer
dwAoFrmSize (dwAoScanSamples*dwAoFrmScans),
dwAoBufFrm (0x8), dwAoBufferSize (dwAoFrmSize*dwAoBufFrm),
dwAoCvClkDiv ((11000000/AOFREQ)-1),// baseclock/Output frequency (11000000/6000)-1
dwEventsNotify (eFrameDone | eBufferDone | eBufferError | eStopped),go (TRUE),
delayms ((dwAoBufferSize/dwAoBufFrm) / (11000/(dwAoCvClkDiv+1))),
Pdur(4000), dwPamp(2248), // Pulsdauer & amplitude
sine(false)
{}


int DAQ::initGeneral()
{
//Anlegen von Arrays, werden in AOtestOut_step benötigt
//pdur[0]=0; //Pulse duration in [ms]
pdur[1]=2;
pdur[2]=2;
pdur[3]=2;
pdur[4]=2;
pdur[5]=2;
pdur[6]=2;
pdur[7]=2;
pdur[8]=2;

pause [1]=48; //Pause duration in [ms]
pause [2]=48;
pause [3]=48;
pause [4]=48;
pause [5]=48;
pause [6]=48;
pause [7]=48;
pause [8]=48;

offset [1]=-205; // 1V entspricht ~205 (4096/20),
offset [2]=-205; //1V entspricht Strominjektion von 1 nA (nicht mit Current sensitivity output verwechseln!!!)
offset [3]=-307;
offset [4]=0;
offset [5]=0;
offset [6]=0;
offset [7]=205;
offset [8]=205;

pamp [1]=410; // **** ACHTUNG: Werte mit setPulse() abgleichen!!! ****
pamp [2]=820;
pamp [3]=615;
pamp [4]=410;
pamp [5]=615;
pamp [6]=820;
pamp [7]=410;
pamp [8]=620;


// Open driver.
if (!PdDriverOpen(&hDriver, &dwError, &dwNumAdapters) )
{
cout<<"PdDriverOpen failed with "<<dwError<<endl;
return -1;
}
if (dwNumAdapters) cout<<"* :-) pretty, found "<<dwNumAdapters<<" suitable I/O card."<< endl<<endl;
else cout <<" What a pity - there is no suitable I/O card available :-("<<endl;

//Open the first PowerDAQ PCI adapter.
if ( !_PdAdapterOpen(0, &dwError, &hAdapter) )
cout<<"_PdAdapterOpen failed with %d."<<dwError<<endl;
return -1;
}

void DAQ::initDO()
{
// Get subsystem in use
bResult = PdAdapterAcquireSubsystem(hAdapter, &dwError, DigitalOut, 1);
if (!bResult) cout<<"DigitalOut open failed"<< dwError<<endl;
// Reset Board
bResult = _PdDOutReset(hAdapter, &dwError);
if (!bResult) cout<<"_PdDOutReset error"<<dwError<<endl;
cout <<"DO init erfolgreich!"<<endl;
//Get adapter information

// ***** Attention: Get AdapterInfo kills szFileName in DAQ.readIn switches off for now! *****

/* if (!_PdGetAdapterInfo(0, &dwError, &AdapterInfo))
cout<<"_PdGetAdapterInfo error #%d\n"<<dwError<<endl;
// cout<<"Adapterinfo = "<<(AdapterInfo.atType)<<endl;
dwValue = 0xffff;
dwValue=0; */
}

void DAQ::initAI()
{
bResult = PdAdapterAcquireSubsystem(hAdapter, &dwError, AnalogIn,1);
if (!bResult) cout<<"AnalogIn open failed "<< dwError<<endl;

myFIO.SetHandle(hAdapter); // Export des hAdapter Handles an myFIO
}

void DAQ::initAO()
{
bResult = PdAdapterAcquireSubsystem(hAdapter, &dwError, AnalogOut,1);
if (!bResult) cout<<"AnalogOut open failed "<< dwError<<endl;
}


void DAQ::preReadIn()
{
cout<<"Recording of "<<AIN_SCAN_SAMPLES<<" channels @ "<<11000/myFIO.RateDiv()<<" khz to file: "<<szFileName<<endl;
cout<<"Allocating resources.."<<endl;
}

DWORD WINAPI DAQ::readIn()
{
DWORD dwFileSize = myFIO.gimmeFS(); // Filesizeparameterübergabe
if ((hFile = myFIO.AllocateDataFile(&dwFileSize, szFileName)) != INVALID_HANDLE_VALUE)
{
cout<<"..fertig!"<<endl;
//Aufnahme!
myFIO.PD_TestRun();
CloseHandle (hFile);
}
else
{
cout<<"Something's going wrong here ... :-(";
}
return 0;
}

void DAQ::SECpara(bool startmode, int modeswdel1, int modeswdel2)
{
DAQ::startmode=startmode;
DAQ::modeswdel1=modeswdel1;
DAQ::modeswdel2=modeswdel2;
}

void DAQ::writeLog(int prog)
{
char tbuffer [9]; // buffer for current time
_strtime( tbuffer );
ofstream schreiben;
schreiben.open(szLogName);
schreiben <<"LOG-File for recording "<<szFileName<<" from "<<tbuffer<<" o'clock"<<endl<<
"recorded with program version "<<version<<endl<< // Version is passed to DAQ in CTRL
"A/D conversation clock rate is set to "<<11000 / myFIO.RateDiv() <<"khz"<<endl<<
"frame number to record is "<<myFIO.F2Acquire()<<endl<<
"This is a "<<AIN_SCAN_SAMPLES <<" channel recording"<<endl<<
"*** Recording mode: "<<prog<<" ***"<<endl<<endl;
if (startmode)
schreiben<< "Amplifier set to bridged"<<endl;
else
schreiben<< "Amplifier set to Voltage Clamp"<<endl;
if (modeswdel1)
schreiben<<"Amplifier mode switched after "<<modeswdel1<<"ms"<<endl;
if (modeswdel2)
schreiben<<"Amplifier mode switched again after another "<<modeswdel2<<"ms"<<endl;
schreiben<<
"Zuffallsarray (Sinus & Pulse):"<<endl<<
"1= "<< Z[1]<<endl<<
"2= "<< Z[2]<<endl<<
"3= "<< Z[3]<<endl<<
"4= "<< Z[4]<<endl<<
"5= "<< Z[5]<<endl<<
"6= "<< Z[6]<<endl<<
"7= "<< Z[7]<<endl<<
"8= "<< Z[8]<<endl<<
"Pulse:"<<endl<<
"1= pdur"<< pdur[Z[1]]<<" offset:"<<offset[Z[1]]<<" pause:"<<pause[Z[1]]<<" pamp:"<<pamp[Z[1]]<<endl<<
"2= pdur"<< pdur[Z[2]]<<" offset:"<<offset[Z[2]]<<" pause:"<<pause[Z[2]]<<" pamp:"<<pamp[Z[2]]<<endl<<
"3= pdur"<< pdur[Z[3]]<<" offset:"<<offset[Z[3]]<<" pause:"<<pause[Z[3]]<<" pamp:"<<pamp[Z[3]]<<endl<<
"4= pdur"<< pdur[Z[4]]<<" offset:"<<offset[Z[4]]<<" pause:"<<pause[Z[4]]<<" pamp:"<<pamp[Z[4]]<<endl<<
"5= pdur"<< pdur[Z[5]]<<" offset:"<<offset[Z[5]]<<" pause:"<<pause[Z[5]]<<" pamp:"<<pamp[Z[5]]<<endl<<
"6= pdur"<< pdur[Z[6]]<<" offset:"<<offset[Z[6]]<<" pause:"<<pause[Z[6]]<<" pamp:"<<pamp[Z[6]]<<endl<<
"7= pdur"<< pdur[Z[7]]<<" offset:"<<offset[Z[7]]<<" pause:"<<pause[Z[7]]<<" pamp:"<<pamp[Z[7]]<<endl<<
"8= pdur"<< pdur[Z[8]]<<" offset:"<<offset[Z[8]]<<" pause:"<<pause[Z[8]]<<" pamp:"<<pamp[Z[8]]<<endl;
schreiben.close();

}


//void DAQ::OpenAOfile() -> see V1.3.1

void DAQ::setSineAmp()
{ int sintemp;
cout<<"Current amplitude forced to the cell is "<<sinemult/8<<"mV"<<endl;
cout<<"Please enter new sine amplitude (mV)"<<endl; // 1 -> 5mV Analog Output
cin>>sintemp; // 1mV Amplitude am Verstärker mit 1/40
sintemp *= 8; // -> 1mV = 8
sinemult=sintemp;
}

void DAQ::zufall() // random generator for sine frequencies
{
int i, j;
//int Z[9];
bool weiter = false;
srand( (unsigned)time( NULL ));

for (i=1;i<9;i++)
{
do
{
Z[i]=(rand()%(8)+1); //war 7
weiter = true;
for (j=0; j<i; j++)
{ // durchlaufe alle bisherigen Werte
if (Z[j]==Z[i])
{ // Wenn zwei gleich:
weiter = false;
}
}
} while (!weiter);
}
cout<<"Z8="<<Z[8]<<endl;
aiZufall[Z[1]]=5093; // 1 Hz (aofreq/2pi) | values here are for 32kHz output frequency
aiZufall[Z[2]]=2546; // 2 Hz
aiZufall[Z[3]]=1273; // 4 Hz
aiZufall[Z[4]]=637; // 8 Hz
aiZufall[Z[5]]=318; // 16 Hz
aiZufall[Z[6]]=159; // 32 Hz
aiZufall[Z[7]]=106; // 48 Hz
aiZufall[Z[8]]=80; // 64 Hz
}

void DAQ::AOfillBuf(void* pwBuf, DWORD dwAoBufferSize, // S I N U S
DWORD dwClk, DWORD dwChListChan, DWORD dwMode) // fill buffer operations
{
DWORD* pdwBuffer = NULL;
WORD* pwBuffer = NULL; // sinus pattern lasting 1s each frequency
// 1/3 s 0mV holding potential
int i;

pdwBuffer = (DWORD*)pwBuf;
DWORD *myLpvResult;
myLpvResult= reinterpret_cast<DWORD*>(lpvResult);

cout<<"SINEMULT="<<sinemult<<endl;
cout<<"pdw="<<pdwBuffer<<endl; // =pMyBuf

cout<<"dwAoBufferSize = "<<dwAoBufferSize<<endl; //
int z=0;
unsigned long templ;
//dwAoBufferSize=dwAoBufferSize*2;

cout<<"Analog output frequency set to:"<<aofreq<<endl;
int spacer=11200; // spacer between sinus
for (i=0; i < dwAoBufferSize; i++)
{ //pi = 3.14159265 // *(pdwBuffer+i) = *(myLpvResult+i);
double tempd = double (z);
if (i>(spacer) && i<(aofreq+spacer)) {
++z;
tempd=sin(tempd/aiZufall[1]);} // 1 Hz ///951
else if (i>(aofreq+2*spacer) && i<(2*aofreq+2*spacer)){
++z;
tempd = sin((tempd)/aiZufall[2]);} // 2 Hz /// 475
else if (i>(2*aofreq+3*spacer) && i<(3*aofreq+3*spacer)){
++z;
tempd = sin((tempd)/aiZufall[3]);} // 4 Hz ///238
else if (i>(3*aofreq+4*spacer) && i<(4*aofreq+4*spacer)){
++z;
tempd = sin((tempd)/aiZufall[4]);} // 8 Hz /// 120
else if (i>(4*aofreq+5*spacer) && i<(5*aofreq+5*spacer)){
++z;
tempd = sin((tempd)/aiZufall[5]);} // 16 Hz
else if (i>(5*aofreq+6*spacer) && i<(6*aofreq+6*spacer)){
++z;
tempd = sin((tempd)/aiZufall[6]);} // 32 Hz
else if (i>(6*aofreq+7*spacer) && i<(7*aofreq+7*spacer)){
++z;
tempd = sin((tempd)/aiZufall[7]);} // 64 Hz
else if (i>(7*aofreq+8*spacer) && i<(8*aofreq+8*spacer)){
++z;
tempd = sin((tempd)/aiZufall[8]);} // 42 (!) Hz
else {tempd=0;z=0;} //nottig!
//cout<<"SINEMULT="<<sinemult<<endl;
tempd*= sinemult;
templ=unsigned long(tempd);
templ=templ+2048;
*(pdwBuffer+i) = templ;//
//cout<<"Sine="<<templ<<endl;
}
}

double DAQ::step (int pdur, int pause, int offset, int pamp, int z)
// z ist fortlaufender Indexwert pro Pulstirade, wird wieder auf Null gesetzt
{
double bla=0;
int blup=0;
z+=(pause*16);
pdur*=32;
pause*=32;
blup=z%(pdur+pause);
bla=offset;
if (blup<pdur)
{
bla=offset+pamp;
}

return bla;
}


void DAQ::AOfillBuf_Step(void* pwBuf, DWORD dwAoBufferSize, // S T E P
DWORD dwClk, DWORD dwChListChan, DWORD dwMode) // fill buffer operations
{
cout<<"Hi, this is the AOfillBuf_Step **STEP* routine, prepare 4 some fun"<<endl;
DWORD* pdwBuffer = NULL;
WORD* pwBuffer = NULL; // Pulsepatterns lasting 1s each
// 1/3 s pause 0mV holding potential
pdwBuffer = (DWORD*)pwBuf;
DWORD *myLpvResult;
myLpvResult= reinterpret_cast<DWORD*>(lpvResult);

cout<<"pdw="<<pdwBuffer<<endl;

cout<<"dwAoBufferSize = "<<dwAoBufferSize<<endl; //~32k Samples
int plaenge=32000; //wie lang (in samples) werden pulse appliziert? (max Wert ist "spacer")
int spacer=43200; //1.35s
int z=0; // z rettet den letzten Indexwert, z selbst wird nicht verändert
int y=0;
int i;
unsigned long templ;

for (i=0; i < dwAoBufferSize; i++)
{
double tempd = double (z); // tempd darf in einem Durchlauf modifiziert werden
if (i>(Z[1]*spacer-plaenge) && i<(Z[1]*spacer)){
++z;
tempd= step(pdur[1], pause[1], offset[1], pamp[1], z);} // step (pdur pause offset pamp z)
else if (i>(Z[2]*spacer-plaenge) && i<(Z[2]*spacer)){
++z;
tempd = step(pdur[2], pause[2], offset[2], pamp[2], z);}
else if (i>(Z[3]*spacer-plaenge) && i<(Z[3]*spacer)){
++z;
tempd= step(pdur[3], pause[3], offset[3], pamp[3], z);}
else if (i>(Z[4]*spacer-plaenge) && i<(Z[4]*spacer)){
++z;
tempd = step(pdur[4], pause[4], offset[4], pamp[4], z);}
else if (i>(Z[5]*spacer-plaenge) && i<(Z[5]*spacer)){
++z;
tempd = step(pdur[5], pause[5], offset[5], pamp[5], z);}
else if (i>(Z[6]*spacer-plaenge) && i<(Z[6]*spacer)){
++z;
tempd = step(pdur[6], pause[6], offset[6], pamp[6], z);}
else if (i>(Z[7]*spacer-plaenge) && i<(Z[7]*spacer)){
++z;
tempd = step(pdur[7], pause[7], offset[7], pamp[7], z);}
else if (i>(Z[8]*spacer-plaenge) && i<(Z[8]*spacer)){
++z;
tempd = step(pdur[8], pause[8], offset[8], pamp[8], z);}
else {tempd=0;z=0;} //nottig!
templ=unsigned long(tempd);
templ=templ+2048;
*(pdwBuffer+i) = templ;// Warum per Zeiger? Um Typecasting zu vermeiden?
}
}


DWORD WINAPI DAQ::AOtest () // Start for asynchronous, buffered analog output operations
{
if (! _PdAOutReset (hAdapter, &dwError)) cout<<"This is not your day: Anaolog Out is not resetable - reason: "<<dwError<<endl;

void *pMyBuf;
pMyBuf = reinterpret_cast<void*>(pwBuf); //Zeigerkonvertierung von PWORD zu *void
// puffer reservieren
bResult = _PdAcquireBuffer(hAdapter, &dwError,
&pMyBuf, dwAoBufFrm,
dwAoFrmScans, dwAoScanSamples,
AnalogOut, dwMode);
cout <<"pMybuf="<<pMyBuf<<endl;

// Füllen des Puffers mit DAQ.AOfillBuf()
if (sine)
{
AOfillBuf(pMyBuf, dwAoBufFrm*dwAoFrmScans*dwAoScanSamples, dwAoCvClkDiv, dwAoScanSamples, dwMode);
}
else
{
AOfillBuf_Step(pMyBuf, dwAoBufFrm*dwAoFrmScans*dwAoScanSamples, dwAoCvClkDiv, dwAoScanSamples, dwMode);
}

bResult = _PdAOutAsyncInit(hAdapter, &dwError,
dwAoCfg, dwAoCvClkDiv,
dwEventsNotify);

bResult = _PdAOutSetPrivateEvent(hAdapter, &hEvent);

bResult = _PdAOutAsyncStart(hAdapter, &dwError);

for (i=0;i<23; i++) // for "infinite" loop use "while (go)" 23
// while (go)
{
// Wait for interrupt.
if ( WaitForSingleObject(hEvent, 500) == WAIT_OBJECT_0 ) {

if (!(dwMode & BUF_BUFFERRECYCLED))
{
bResult = _PdGetUserEvents(hAdapter, &dwError,
AnalogOut, &dwAEvents);
cout<<endl<<"Events: "<< dwAEvents;

// put new scans and reenable events
/* bResult = _PdAOutGetBufState(hAdapter, &dwError,
dwAoFrmScans, &dwScanIndex,
&dwNumValidScans); // r3

cout<<"SI:"<< dwScanIndex <<"VS:"<< dwNumValidScans<<endl;*/

if (dwAEvents & eStopped) go = FALSE;

// re-set user events
// bResult = _PdSetUserEvents(hAdapter, &dwError, AnalogOut, dwEventsNotify);
}
} else {
cout<<"T.";
}

/* if (kbhit()) {
if (_getch() == 0) _getch();
cout<<"Break due to key pressed"<<endl;
break; } */
}

// wait for last frame (until straight buffer is finished)
if (!(dwMode & ~BUF_DWORDVALUES)) {
cout<<"wait...";
Sleep(delayms); }

bResult = _PdAOutAsyncStop(hAdapter, &dwError);

bResult = _PdAOutClearPrivateEvent(hAdapter, &hEvent);

bResult = _PdAOutAsyncTerm(hAdapter, &dwError);

// Release buffer
bResult = _PdReleaseBuffer(hAdapter, &dwError, AnalogOut, pMyBuf);

if (! _PdAOutReset (hAdapter, &dwError)) cout<<"This is not your day: Anaolog Out is not resetable - reason: "<<dwError<<endl;

// get rid of the buffer again
bResult= _PdFreeBuffer(pwBuf, &dwError);

bResult = VirtualFree(
lpvResult, // base address of block
0,
MEM_RELEASE);

return 0;
}

// **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** ****
// AO with single update method (Method A, see user manual pp.88)
// Okay for simple operations, but never trust a Tektronix Oscilloscope (too bad, cost me three days
// to seek for an error in my code and then it has been the oscilloscope!)
// **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** ****

DWORD WINAPI DAQ::VCramp() // Step pulse out: rising, falling, raising back to zero
{
if (! _PdAOutReset (hAdapter, &dwError)) cout<<"This is not your day: Anaolog Out is not resetable - reason: "<<dwError<<endl;

//double dStep = 0;
DWORD dwStep =2048;
Sleep(100);
int a = 1;

for (int i=0; i<=29; i++) //Augabe in 2.5 mV Schritten +/- 25mV
{
if (! _PdAOutPutValue (hAdapter, &dwError, dwStep)) cout<<"Zapperlot, kann nicht in AOut schreiben!"<<endl;
cout<<"Potential is now clamped to "<<(dwStep-2048)/8<<"mV"<<endl; //Werte noch ohne Teiler am NPI
if (a<=10) dwStep = dwStep+20;
if (a>=11 && a<=15) dwStep = dwStep-40;
if (a>=16 && a<=25) dwStep = dwStep-20;
if(a>=25) dwStep=dwStep+40;
a++;
Sleep (250);
}

if (! _PdAOutReset (hAdapter, &dwError)) cout<<"This is not your day: Anaolog Out is not resetable - reason: "<<dwError<<endl;

return 0;
}

DWORD WINAPI DAQ::VCtest12() // rectangle pulses +/- 5 & 10 & 20 mV
{
if (! _PdAOutReset (hAdapter, &dwError)) cout<<"This is not your day: Anaolog Out is not resetable - reason: "<<dwError<<endl;

int i=0;
DWORD dwStep;

for (i=0;i<12;++i)
{
switch (i)
{
case 1: dwStep=2088;
case 3: dwStep=2008;
case 5: dwStep=2128;
case 7: dwStep=1968;
case 9: dwStep=2208;
case 11: dwStep=1888;
default: dwStep=2048;
}
if (! _PdAOutPutValue (hAdapter, &dwError, dwStep)) cout<<"Zapperlot, kann nicht in AOut schreiben!"<<endl;
else cout<<"12Potential is now clamped to "<<(dwStep/8)-(2048/8)<<"mV"<<endl; //Werte noch ohne Teiler am NPI
Sleep (duration); // Muster soll pro Square 320ms stehen und 320 ms laufen
}
if (! _PdAOutReset (hAdapter, &dwError)) cout<<"This is not your day: Anaolog Out is not resetable - reason: "<<dwError<<endl;
return 0;
}


DWORD WINAPI DAQ::VCtest35() // Step pulse out rising, falling, raising back to zero

{
if (! _PdAOutReset (hAdapter, &dwError)) cout<<"This is not your day: Anaolog Out is not resetable - reason: "<<dwError<<endl;

int i=0;
DWORD dwStep;

for (i=0;i<12;++i)
{if (i==1) dwStep=2128;
else
if (i==3) dwStep=1968;
else
if (i==5) dwStep=2288;
else
if (i==7) dwStep=1808;
else
if (i==9) dwStep=2448;
else
if (i==11) dwStep=1648;
else dwStep=2048;
if (! _PdAOutPutValue (hAdapter, &dwError, dwStep)) cout<<"Zapperlot, kann nicht in AOut schreiben!"<<endl;
else cout<<"12Potential is now clamped to "<<(dwStep/8)-(2048/8)<<"mV"<<endl; //Werte noch ohne Teiler am NPI
Sleep (duration);
}
if (! _PdAOutReset (hAdapter, &dwError)) cout<<"This is not your day: Anaolog Out is not resetable - reason: "<<dwError<<endl;
return 0;
}

void DAQ::pospul()
{
DWORD temp=2048;
if (! _PdAOutPutValue (hAdapter, &dwError, dwPamp)) cout<<"Zapperlot, kann nicht in AOut schreiben!"<<endl;
else cout<<"A pulse of "<<(dwPamp/20)-(2048/20)<<"/10 nA (1V->1nA) resp. "<<(dwPamp/8)-(2048/8)<<"mV is provided now"<<endl;
Sleep(Pdur); //Pdur was 3 for pulses
if (! _PdAOutPutValue (hAdapter, &dwError, temp)) cout<<"Zapperlot, kann nicht in AOut schreiben!"<<endl;
else cout<<"A pulse of "<<(temp/20)-(2048/20)<<"/10 nA is provided now"<<endl;
Sleep(4000); // was 100 for pulses
}

void DAQ::negpul()
{
/* DWORD temp=2048; // Hyperpolarization skipped for now, activate by de-commenting when needed
if (! _PdAOutPutValue (hAdapter, &dwError, dwPamp*-1)) cout<<"Zapperlot, kann nicht in AOut schreiben!"<<endl;
else cout<<"A puls of "<<(dwPamp/-20)-(2048/20)<<"/10 nA is provided now (1V->1nA)"<<endl;
Sleep(Pdur); //Pdur was 3 for pulses
if (! _PdAOutPutValue (hAdapter, &dwError, temp)) cout<<"Zapperlot, kann nicht in AOut schreiben!"<<endl;
else cout<<"A puls of "<<(temp/20)-(2048/20)<<"/10 nA is provided now"<<endl;
Sleep(4000); // was 100 for pulses*/
cout<<"HYPER HYPER was stupid techno by Scooter, thus we skip HYPERpolorization today and do only depolarization"<<endl;

}

DWORD WINAPI DAQ::cstep() // Einfache Stepapplikation ursprünglich fuer calcium buffer experimente
{ // AOfillBuf_Step(...) per AOtest() mit sine=false ist leistungsfähiger
cout<<"Application of current steps in random order (DAQ::csstep)"<<endl;
int i, j;
int Z[5];
int tempstep [4];
bool weiter = false;
srand( (unsigned)time(NULL));

for (i=1;i<5;i++)
{
do
{
Z[i]=(rand()%(4)+1); // Funktion s.o.
weiter = true;
for (j=0; j<i; j++)
{ // durchlaufe alle bisherigen Werte
if (Z[j]==Z[i])
{ // Wenn zwei gleich:
weiter = false;
}
}
} while (!weiter);
}
int temp=dwPamp-2048;
cout<<"temp="<<temp<<endl;

tempstep [Z[1]]= 2048-temp;
tempstep [Z[2]]= 2048+temp;
tempstep [Z[3]]= 2048+temp+temp;
tempstep [Z[4]]= 2048+temp+temp+temp;

j=1;
cout<<"steps to be injected this time:"<<endl;
cout<<"1:"<<(tempstep[1]-2048)/20<<"/10 nA *** 2:"<<(tempstep[2]-2048)/20<<"/10 nA *** 3:"<<(tempstep[3]-2048)/20<<"/10 nA *** 4:"<<(tempstep[4]-2048)/20<<"/10 nA"<<endl;

if (! _PdAOutPutValue (hAdapter, &dwError, 2048)) cout<<"Zapperlot, kann nicht in AOut schreiben!"<<endl;
else cout<<"Here we go..."<<endl;
Sleep(1500);

for (i=0; i<4; i++)
{
if (! _PdAOutPutValue (hAdapter, &dwError, tempstep[j])) cout<<"Zapperlot, kann nicht in AOut schreiben!"<<endl;
else cout<<"A puls of "<<(tempstep[j]-2048)/20<<"/10 nA is provided now"<<endl;
Sleep(1000);
j++;
if (! _PdAOutPutValue (hAdapter, &dwError, 2048)) cout<<"Zapperlot, kann nicht in AOut schreiben!"<<endl;
else cout<<"No current is provided now"<<endl;
Sleep(1000);
}
if (! _PdAOutPutValue (hAdapter, &dwError, 2048)) cout<<"Zapperlot, kann nicht in AOut schreiben!"<<endl;
else cout<<";-)"<<endl;
Sleep(500);

return 0;
}


DWORD WINAPI DAQ::Papply() // Randomly alternating current pulse application (Cobalt experiments)
{
int x=0;
if (! _PdAOutReset (hAdapter, &dwError)) cout<<"This is not your day: Anaolog Out is not resetable - reason: "<<dwError<<endl;
srand( (unsigned)time( NULL ));
x=rand()%2;
Sleep(1000); //was 500
// for (int z=0;z<30;++z) //was 30 for pulses, Schleife für Pulse
if (x==1)
{
pospul();
negpul();
}
else
{
negpul();
pospul();
}
return 0;
}


void DAQ::Padjust()
{
cout<<"Please give amplitude (1/10 nA)"<<endl;
cin>>dwPamp;
dwPamp*=20;
dwPamp+=2048;
//Papply();
}

void DAQ::setPulse()
{
int x=1;

cout<<"Settings for Pulse application"<<endl;

cout <<"Multiply pulse amplitude(1) or set all (0)?"<<endl;
cin >>x;
if (x)
{
cout<<"Restore default pulse amplitudes? yes=1, no =0"<<endl;
cin >>x;
if (x)
{
pamp [1]=410; // *** ACHTUNG: Werte mit initGeneral() abgleichen!!! ***
pamp [2]=820;
pamp [3]=615;
pamp [4]=410;
pamp [5]=615;
pamp [6]=820;
pamp [7]=410;
pamp [8]=620;
}

cout<<"please give multiplication factor *100"<<endl;
cin>>x;
for (i=1;i<=8;i++)
{
pamp[i]*=x;
pamp[i]/=100;
}

}
else
{
for (i=1;i<=8;i++)
{
cout<<"Round "<< i<<"/8"<<endl;
cout<<"current settings are:"<<endl
<<"duration:"<<pdur[i]/6<<"[ms] pause:"<<pause[i]/6<<"[ms] offset:"<<offset[i]/205
<<" amplitude:"<<pamp[i]/206<<endl;
cout<<" please enter pulse duration [ms]"<<endl;
cin>>x;
//x*=6;
pdur[i]=x;
cout<<" now enter pause duration [ms]" <<endl;
cin>>x;
//x*=6;
pause[i]=x;
cout<<" and offset [0.1 nA]"<<endl;
cin>>x;
x*=20,5;
offset[i]=x;
cout<<" and pulse amplitude [0.1 nA]"<<endl;
cin>>x;
x*=20,5;
pamp[i]=x;
}
}
}

void DAQ::lang()
{
char l=0;
cout<<"long duration?";
cin>>l;
if (l=='y' || l=='Y') duration=1280;
}


void DAQ::langoff()
{
duration=640;
}


void DAQ::setrecduration(int dauer)
{
int recduration=dauer;
if (duration==1280) recduration*=2;
myFIO.setFrameNum(recduration);
}

void DAQ::sinostep(bool sot) // Sinus oder Stepmuster? Bool sine=tot=true -> Sinus
{
sine=sot;
}

void DAQ::schliessenAO() // Subsystem Analog Out schließen
{
bResult = PdAdapterAcquireSubsystem(hAdapter, &dwError, AnalogOut, 0);
if (!bResult) cout <<"PdAdapterAcquireSubsystem error"<< dwError;
}
void DAQ::schliessenDO() // Subsystem digital Out schließen
{
bResult = PdAdapterAcquireSubsystem(hAdapter, &dwError, DigitalOut, 0);
if (!bResult) cout <<"PdAdapterAcquireSubsystem error"<< dwError;
}
void DAQ::schliessenAI() // Subsystem Analog In schließen
{
bResult = PdAdapterAcquireSubsystem(hAdapter, &dwError, AnalogIn, 0);
if (!bResult) cout <<"PdAdapterAcquireSubsystem error"<< dwError;
}

void DAQ::schliessen() // Karte & den Treiber schließen
{

// Close adapter.
if ( !_PdAdapterClose(hAdapter, &dwError) )
cout <<"_PdAdapterClose failed with"<< dwError;

// Close driver.
if ( !PdDriverClose(hDriver, &dwError) )
cout<<"PdDriverClose failed with "<< dwError;
}


DWORD WINAPI DAQ::dummythread()
{
return 0;
}

// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
// *** Preferences *** Preferences *** Preferences *** Preferences *** Preferences *** Preferences ***
// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***


void DAQ::initPrefs() // init
{
cout<<"Hey dude - gimme a proper input file name, would ya be that kind please?"<<endl;
cin>>myString;
strcpy(szFileName,myString);
cout<<"WhOOt! What a brilliant name "<<szFileName<<" is. Now we're ready 2 party..."<<endl<<endl;
//namecount=0;
}

void DAQ::gimmePrefs()
{
cout<<" current settings are:"<<endl;
// cout<<" - stripe pattern speed is "<<ispeed/5<<endl;
cout<<" - sine amplitude is "<<sinemult/8<<"mV"<<endl;
cout<<" - current filename is "<<szFileName<<endl;
cout<<" - frame number to record is "<<myFIO.F2Acquire()<<endl;
cout<<" - recording is on "<<AIN_SCAN_SAMPLES <<" channels"<<endl;
cout<<" - A/D conversation clock rate is set to "<<11000 / myFIO.RateDiv() <<"khz"<<endl;
}

int DAQ::prefs() // Prefs menu & some functions
{
char pre = 0;
while (pre = true)
{
cout << " *** Welcome to the preferences menu ***"<<endl<<endl;
gimmePrefs();

cout << " s for pattern speed prefs"<< endl;
cout << " p for puls amplitude settings"<<endl;
cout << " a for sine amplitude"<<endl;
cout << " n for input file name prefs"<< endl;
cout << " c for number of channels to record"<<endl;
cout << " v for analog in sampling frequency"<<endl;
cout << " r for return to main menu"<<endl;
cin>>pre;

if (pre=='r' || pre=='R')
{
pre = false;
return 0;
}
else
if (pre=='s' || pre=='S')
{
cout<<"Speed setting currently not available. Prefs must go to CTRL"<<endl;
// speed();
}
else
if (pre=='a' || pre=='A')
{
setSineAmp();
}
else
if (pre=='n' || pre=='N')
{
cout<<"Please give file name: ";
cin>>myString;
strcpy(szFileName,myString);
namecount=0;
}
else
if (pre=='c' || pre=='C')
{
myFIO.setChannel();
}
else
if (pre=='v' || pre=='V')
{
myFIO.setAIFreq();
}
if (pre=='p' || pre=='P')
{
setPulse();
}
else
cout<<"What should "<<pre<<"mean? That is not a valid option. You better try again!"<<endl;
}

return 0;
}

void DAQ::tellPrefs(bool &nameincrement)
{
if (nameincrement) namecount++;
char suffix [5] =".fly";
char suffix2 [6] =".flog";
strcpy(szFileName,myString);
char namecountstr[2];
itoa (namecount, namecountstr,10); // itoa ist zur Typumwandlung int -> string / "10" ist für dezimalsystem
strcat (szFileName, namecountstr);
strcat (szFileName, suffix); // Voila - fertig ist der Filename
strcpy(szLogName,myString);
strcat (szLogName, namecountstr);
strcat (szLogName, suffix2); // ..und auch der Logdateiname

cout<<"current input filename: "<<szFileName<<" | Frames 2 record:"<<myFIO.F2Acquire()<<endl<<endl ;
}
#endif


back to the code manual page

back to the Blue IO main page

back to main page and contact information
--
latest change: 26-08-2009 -- (c) U. Beckers