Irregular Acquired Speed
Posted: Thu May 28, 2015 8:43 am
Hi,
I am trying to write a program to get data from the ActiveTwo in C++. This program also synchronize the data with other two devices (EMG and MotionTracking). I am having a few problems, but the mos important is the following.
If I write something like this:
while (1){
READ_POINTER(usbHandle,&point)
if(point!=lastpoint){
fprintf(file,"%d\n",point-lastpoint);
lastpoint=point;
}
}
So basically what I am saving is how many bytes I receive each time. For this I was expecting around 282*4 = 1128 bytes. Because each packet are 282 integers.But what I get is between 131072 and 131584 bytes, so basically each time that the ActiveTwo sends data sends around 116 packets. Not that the while loop is executed way faster, if I erase the If clause the file is full with the same number over and over, and only time to time there is a step.
The ActiveTwo is working in the speed mode 4, so this means that I get a group of packets every 0.05s, is this normal? If so, the real acquisition speed is not 2048Hz but 14Hz.
Here is the only part from my code that I think is important for this is the initialization, I got it from this forum, I think. There is not much information about the C++ API anyway...
(In my case BUFFERSIZE is 34652160 =282 chanels*2048 samples/s * 15 s * 4 bytes/chanel)
if ((usbHandle=OPEN_DRIVER_ASYNC()) == (HANDLE)NULL){
printf("Can't open device driver!\n");
WSACleanup();
return;
}
INT_PTR bytes2Use = BUFFERSIZE;
if ((samBuffer=(PUCHAR)malloc(bytes2Use)) == 0){
printf("VirtualAlloc returns 0, GetLastError = %d\n",GetLastError());
WSACleanup();
return;
}
READ_MULTIPLE_SWEEPS(usbHandle, (PCHAR)samBuffer, bytes2Use);
CHAR controlBuffer[64];
for (int i=0; i<64; i++)
controlBuffer[i] = 0;
controlBuffer[0] = (CHAR)(-1);
if(USB_WRITE(usbHandle, &controlBuffer[0]) == FALSE){
printf ("usb_write for enable handshake trouble\n");
}
Thank you in advance
Jacobo
I am trying to write a program to get data from the ActiveTwo in C++. This program also synchronize the data with other two devices (EMG and MotionTracking). I am having a few problems, but the mos important is the following.
If I write something like this:
while (1){
READ_POINTER(usbHandle,&point)
if(point!=lastpoint){
fprintf(file,"%d\n",point-lastpoint);
lastpoint=point;
}
}
So basically what I am saving is how many bytes I receive each time. For this I was expecting around 282*4 = 1128 bytes. Because each packet are 282 integers.But what I get is between 131072 and 131584 bytes, so basically each time that the ActiveTwo sends data sends around 116 packets. Not that the while loop is executed way faster, if I erase the If clause the file is full with the same number over and over, and only time to time there is a step.
The ActiveTwo is working in the speed mode 4, so this means that I get a group of packets every 0.05s, is this normal? If so, the real acquisition speed is not 2048Hz but 14Hz.
Here is the only part from my code that I think is important for this is the initialization, I got it from this forum, I think. There is not much information about the C++ API anyway...
(In my case BUFFERSIZE is 34652160 =282 chanels*2048 samples/s * 15 s * 4 bytes/chanel)
if ((usbHandle=OPEN_DRIVER_ASYNC()) == (HANDLE)NULL){
printf("Can't open device driver!\n");
WSACleanup();
return;
}
INT_PTR bytes2Use = BUFFERSIZE;
if ((samBuffer=(PUCHAR)malloc(bytes2Use)) == 0){
printf("VirtualAlloc returns 0, GetLastError = %d\n",GetLastError());
WSACleanup();
return;
}
READ_MULTIPLE_SWEEPS(usbHandle, (PCHAR)samBuffer, bytes2Use);
CHAR controlBuffer[64];
for (int i=0; i<64; i++)
controlBuffer[i] = 0;
controlBuffer[0] = (CHAR)(-1);
if(USB_WRITE(usbHandle, &controlBuffer[0]) == FALSE){
printf ("usb_write for enable handshake trouble\n");
}
Thank you in advance
Jacobo