I attached the entire program below. The problem seems to be in
the line of the DB_Transfer function though because if I uncomment the
char* memtowrite and pass memtowrite in place of memorylocation, the
code works fine (albeit too slowly for my needs since I then have to
transfer from memtowrite into memory.)
void main(void)
{
cout << "This program should display out
information as to what it is taking \n in and where in the program it
currently is so that \n we can check to see where the program is
failing.\n" << endl;
// handle file I/O and get location to store data
char filename[32];
short *memorylocation;
ofstream outputfile;
u32 numberofbuffersmapped=0, numberofbuffersinfile=13000;
const u32 buffersize = 800; // sets up size of
buffer, must be divisible by 16 so that whole number of bytes can be
drawn from it
HANDLE hfile, hmemmap;
DWORD lasterror;
LPCWSTR temp = MultiCharToUniChar((char*) &"hello.txt");
hfile = CreateFile(temp, GENERIC_WRITE | GENERIC_READ, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, 0, NULL);
delete[] temp;
lasterror = GetLastError();
if ( hfile == INVALID_HANDLE_VALUE )
printf( "Cannot open file because %d \n", lasterror);
hmemmap = CreateFileMapping(hfile, NULL, PAGE_READWRITE, 0, numberofbuffersinfile*buffersize, NULL);
lasterror = GetLastError();
if ( hmemmap == INVALID_HANDLE_VALUE )
printf( "Cannot open mememap because %d \n", lasterror);
//initiate variables to be used in card interface
const i16 itimetowaitbeforeending = 6; // in seconds
i16 iStatus = 0;
i16 iRetVal = 0;
const i16 iDevice = 1;
const i16 iGroup = 1;
const i16 iGroupSize = 2;
const i16 iPort = 0;
const i16 iDir = 0;
const i16 iProtocol = 0;
const i16 iEdge = 0;
const i16 ireqPol = 1;
const i16 iackPol = 0;
const i16 iackDelayTime =0;
const i16 iPgConfig = 1;
const i16 iReqSource = 1;
const i16 iPgTB = -3;
const i16 iReqInt = 10;
const i16 iExtGate = 0;
const i16 iDBModeON = 1;
const i16 iDBModeOFF = 0;
const i16 iOldDataStop = 1;
static i16 piBuffer[buffersize]={0};
const u32 ulPtsTfr = buffersize/2;
const i16 iPartialTransfer = 0;
const i16 iIgnoreWarning = 0; //1 to ignore warning,
const i32 lTimeout = 180;
const i16 iYieldON = 1;
u32 PointsRemaining = 0;
u32 lastpointsremaining = buffersize*numberofbuffersinfile;
// char *memtowrite;
// memtowrite = new char [buffersize];
// set up time to find when timeout occurs to stop program
clock_t start = clock();
clock_t end = clock();
iStatus = DIG_Block_Clear(iDevice, iGroup);
iStatus = Timeout_Config(iDevice, lTimeout); // set to 10 seconds
iRetVal = NIDAQErrorHandler(iStatus, "Timeout_Config", iIgnoreWarning);
/* Configure group of ports as input, with handshaking. */
iStatus = DIG_Grp_Config(iDevice, iGroup, iGroupSize, iPort, iDir);
iRetVal = NIDAQErrorHandler(iStatus, "DIG_Grp_Config", iIgnoreWarning);
iStatus = DIG_Grp_Mode(iDevice, iGroup, iProtocol, iEdge, ireqPol, iackPol, iackDelayTime);
iRetVal = NIDAQErrorHandler(iStatus, "DIG_Group_Mode", iIgnoreWarning);
iStatus = DIG_Block_PG_Config(iDevice, iGroup, iPgConfig, iReqSource, iPgTB, iReqInt, iExtGate);
iRetVal = NIDAQErrorHandler(iStatus, "DIG_Block_PG_Config", iIgnoreWarning);
iStatus = DIG_DB_Config(iDevice, iGroup, iDBModeON, iOldDataStop, iPartialTransfer);
iRetVal = NIDAQErrorHandler(iStatus, "DIG_DB_Config", iIgnoreWarning);
iStatus = DIG_Block_In(iDevice, iGroup, (short*) memorylocation, buffersize);
iRetVal = NIDAQErrorHandler(iStatus, "DIG_Block_In", iIgnoreWarning);
// number of buffers mapped can't change unless the line that says how big of a file to create changes.
while ( ((end-start)/1000 <
itimetowaitbeforeending) && (numberofhalfbuffersmapped<=
numberofbuffersinfile))
{
iStatus = DIG_DB_HalfReady(iDevice, iGroup, &iHalfReady);
iRetVal = NIDAQErrorHandler(iStatus, "DIG_DB_HalfReady", iIgnoreWarning);
if ( iStatus >= 0 )
{
if
(iHalfReady) // gets half buffer to work with while rest of
buffer continues to input
{
memorylocation = (short*) MapViewOfFile(hmemmap, FILE_MAP_WRITE,
0,numberofhalfbuffersmapped*buffersize, buffersize);
iStatus = DIG_DB_Transfer(iDevice, iGroup, (char*)
memorylocation, buffersize/2);
iRetVal = NIDAQErrorHandler(iStatus,
"DIG_DB_Transfer", iIgnoreWarning);
numberofhalfbuffersmapped++;
UnmapViewOfFile(memorylocation);
start = clock(); // took in half buffer so
reset beginning of wait time
}
}
else
iRetVal = NIDAQErrorHandler(iStatus, "DIG_DB_HalfReady",
iIgnoreWarning);
}
iStatus = DIG_Block_Check (iDevice, iGroup, &PointsRemaining);
iRetVal = NIDAQErrorHandler(iStatus, "DIG_Block_Check", iIgnoreWarning);
cout << "PointsRemaining = " << PointsRemaining << endl;
UnmapViewOfFile(memorylocation);
CloseHandle(hmemmap);
CloseHandle(hfile);
iStatus = DIG_Block_Clear(iDevice, iGroup);
};