Chào mọi người.
Trong quá trình chạy code thì file lưu .txt ra kết quả trễ hơn file .exe , có cách nào cho xuất hiện dữ liệu đồng thời không?
Khi em ngưng chạy code, dừng toàn bộ thì kết quả 2 file mới đồng loạt giống nhau. Vậy trong quá trình chạy code, em muốn sử dụng dữ liệu của file .txt làm input cho hoạt động khác không ?
Code của em bên dưới, mong mọi người giúp đỡ !!!
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <fstream>
#include <iostream>
#include <cmath>
#include <time.h>
#include "dpcdecl.h"
#include "depp.h"
#include "dmgr.h"
using namespace std;
unsigned char data[1];
unsigned int x[7], i, sum, t_start;
static HIF hif = hifInvalid;
unsigned int Interval = 1;
unsigned int TotalTime = 5000;
unsigned int t = 0;
int main()
{ //fprintf(stderr,"Opening\n");
if(!DmgrOpen(&hif, "Basys2")) // Change in "Basys2" for the other board.
{printf("DmgrOpen failed (check the device name you provided)\n"); return 0;}
//fprintf(stderr,"Enabling\n");
if(!DeppEnable(hif)) {printf("DeppEnable failed\n"); return 0;}
//fprintf(stderr,"Outputting\n");
data[0] = 1; DeppPutRegRepeat(hif, 8, data, sizeof(data), fFalse); //8 for reset
data[0] = Interval; DeppPutRegRepeat(hif, 7, data, sizeof(data), fFalse);// 7 for Interval
ofstream savefile;
savefile.open("C:/Users/phuc/Desktop/hdk.txt");
data[0] = 0; DeppPutRegRepeat(hif, 9, data, sizeof(data), fFalse); // 9 for stop
data[0] = 0; DeppPutRegRepeat(hif, 8, data, sizeof(data), fFalse);
DeppGetRegRepeat(hif, 0, data, sizeof(data), fFalse);
t_start = data[0];
while(t < TotalTime)
{
if (GetAsyncKeyState(VK_ESCAPE))
{cout << "Cancel processing\n";
t = TotalTime;
}
else
{i=1;
DeppGetRegRepeat(hif, 0, data, sizeof(data), fFalse); x[0] = data[0];
if (x[0]-t_start != 0)
{while (i < 7)
{DeppGetRegRepeat(hif, i, data, sizeof(data), fFalse); x[i] = data[0]; i++;}
sum = 16777216*x[6] + 65536*x[5] + 256*x[4] + x[3];
t = 65536*x[2] + 256*x[1] + x[0];
cout << t << "\t" << sum <<'\n';
savefile << t << "\t" << sum << '\n';
t_start = x[0];
}
}
}
data[0] = 1; DeppPutRegRepeat(hif, 9, data, sizeof(data), fFalse);
if( (hif) != hifInvalid ){DeppDisable(hif); DmgrClose(hif);}
system("pause"); return 0;
}