|
From: amin m. <sir...@gm...> - 2007-09-01 12:20:14
|
hi all,
I use usb_bulk_read() for reading usb device sending data, but if I try to
read once again, PC will be reseted.(in below code, when I change prime
value of k to 2).
if I plug device out then plug in to pc, I can read again. Do you know why?
thanks.
int usb_test(usb_dev_handle *udev, int cnt) {
time_t start, end;
double dif=0;
ofstream ofile;
ofile.open("result.txt");
time (&start);
time (&end);
//PROBLEM IS HERE
for(int k = 1; k>0; k--){
char* rb;
char* wb;
int i=0, result;
rb = new char[4096];
wb = new char[2048];
int count = cnt;
//getting size of reading blocks;
ifstream ifile;
ifile.open("test.txt");
while(!ifile.eof()){
ifile.get();
i++;
}
ifile.close();
//reading received data
result = usb_bulk_read (udev, 2, rb, i, 1000);
if (result < 0) {
printf("\nCould not read: %s", usb_strerror());
return result;
} else {
count -= result;
printf("\nread %d bytes ", result);
}
//print read buffer
for (int j=0; j<result; j++) {
ofile << rb[j];
}
time(&end);
dif = difftime(end , start);
delete rb;
delete wb;
}
ofile.close();
return 0;
}
|