I am attempting to collect data from a USB device using a DLL C# wrapper from FTDI (D3XX.NET). In particular I collect 65536 samples continuously. Each collection of 65536 samples uses the ReadPipe method and takes 8.5 ms. Once collected I immediately signal another thread using a WaitHandle (0.2uS) so it can process the data and then the collecting thread doCs the ReadPipe again. The thing is, the next ReadPipe must occur within 0.5ms otherwise data will be lost. This is because the device has an internal 4K buffer that takes 0.5ms to fill. Now what actually happens is that 2% of the time, garbage collection takes place, which takes on average 1.4ms. Therefore some data is lost. Here is the code:
while (keepGoing)
{
ftStatus = d3xxDevice.ReadPipe(0x84, myBuffer, 65536, ref bytesTransferred); //
_wait.Set();
}
And in the other thread, I have a _wait.WaitOne(). The code in this other thread will execute in less than 10 milliseconds so this is no issue. What I would like to do, and I have no idea how yet, is to have a C++ thread running in another DLL which can reference the ReadPipe from the FTDI DLL, and then when is finished reading the 65536 samples, do the _wait.Set() to allow the managed thread to process the results. This way all collection is via unmanaged code and will not be slowed by the garbage collection. So here is a summary:
1) Call a function in my own C++ DLL which will start a thread.
2) The C++ thread runs and does a ReadPipe of 65536 samples from the FTDI DLL.
3) When the sample collection is complete, this thread does the equivalent of a _wait.Set() to allow the processing thread to do its work.
4) This C++ thread immediately issues the ReadPipe again.
So can this be done? How would I call the FTDI ReadPipe method from my DLL? How would I do the _wait.Set()? Would I use a different mechanism to signal the C# thread to continue?
Thanks for any insight and help (I know no C++ yet). Tom