2323
2424#include " RHD2000Thread.h"
2525#include " RHD2000Editor.h"
26+ #include " USBThread.h"
2627
2728#if defined(_WIN32)
2829#define okLIB_NAME " okFrontPanel.dll"
@@ -367,6 +368,10 @@ void RHD2000Thread::initializeBoard()
367368 {
368369 return ;
369370 }
371+
372+ // Instantiate usb thread
373+ usbThread = new USBThread (evalBoard);
374+
370375 // Initialize the board
371376 std::cout << " Initializing acquisition board." << std::endl;
372377 evalBoard->initialize ();
@@ -1403,24 +1408,31 @@ bool RHD2000Thread::startAcquisition()
14031408 // std::cout << "Setting max timestep." << std::endl;
14041409 // evalBoard->setMaxTimeStep(100);
14051410
1411+ blockSize = dataBlock->calculateDataBlockSizeInWords (evalBoard->getNumEnabledDataStreams ());
1412+ std::cout << " Expecting blocksize of " << blockSize << " for " << evalBoard->getNumEnabledDataStreams () << " streams" << std::endl;
14061413
1407- std::cout << " Starting acquisition." << std::endl;
1408- if (1 )
1409- {
1410- // evalBoard->setContinuousRunMode(false);
1411- // evalBoard->setMaxTimeStep(0);
1412- std::cout << " Flushing FIFO." << std::endl;
1413- evalBoard->flush ();
1414- evalBoard->setContinuousRunMode (true );
1415- // evalBoard->printFIFOmetrics();
1416- evalBoard->run ();
1417- // evalBoard->printFIFOmetrics();
1418- }
1414+ // evalBoard->printFIFOmetrics();
14191415
1420- blockSize = dataBlock->calculateDataBlockSizeInWords (evalBoard->getNumEnabledDataStreams ());
1421- std::cout << " Expecting blocksize of " << blockSize << " for " << evalBoard->getNumEnabledDataStreams () << " streams" << std::endl;
1416+ // evalBoard->setContinuousRunMode(false);
1417+ // evalBoard->setMaxTimeStep(0);
1418+ std::cout << " Flushing FIFO." << std::endl;
1419+ evalBoard->flush ();
1420+ std::cout << " FIFO count " << evalBoard->getNumWordsInFifo () << std::endl;
1421+
1422+ std::cout << " Starting usb thread with buffer of " << blockSize * 2 << " bytes" << std::endl;
1423+ usbThread->startAcquisition (blockSize * 2 );
1424+
1425+ std::cout << " Starting acquisition." << std::endl;
1426+ evalBoard->setContinuousRunMode (true );
1427+ // evalBoard->printFIFOmetrics();
1428+ evalBoard->run ();
14221429 // evalBoard->printFIFOmetrics();
1423- startThread ();
1430+ startThread ();
1431+
1432+
1433+
1434+
1435+
14241436
14251437
14261438 isTransmitting = true ;
@@ -1433,6 +1445,7 @@ bool RHD2000Thread::stopAcquisition()
14331445
14341446 // isTransmitting = false;
14351447 std::cout << " RHD2000 data thread stopping acquisition." << std::endl;
1448+ usbThread->stopAcquisition ();
14361449
14371450 if (isThreadRunning ())
14381451 {
@@ -1482,14 +1495,15 @@ bool RHD2000Thread::stopAcquisition()
14821495bool RHD2000Thread::updateBuffer ()
14831496{
14841497 // int chOffset;
1485- unsigned char * bufferPtr;
14861498 // cout << "Number of 16-bit words in FIFO: " << evalBoard->numWordsInFifo() << endl;
14871499 // cout << "Block size: " << blockSize << endl;
1488-
1500+ unsigned char * bufferPtr;
14891501 // std::cout << "Current number of words: " << evalBoard->numWordsInFifo() << " for " << blockSize << std::endl;
1490- bool return_code;
1502+ long return_code;
14911503
1492- return_code = evalBoard->readDataBlocksRaw (1 ,bufferPtr);
1504+ return_code = usbThread->usbRead (bufferPtr);
1505+ if (return_code == 0 )
1506+ return true ;
14931507
14941508 int index = 0 ;
14951509 int auxIndex, chanIndex;
@@ -1504,6 +1518,7 @@ bool RHD2000Thread::updateBuffer()
15041518 if (!Rhd2000DataBlockUsb3::checkUsbHeader (bufferPtr, index))
15051519 {
15061520 cerr << " Error in Rhd2000EvalBoard::readDataBlock: Incorrect header." << endl;
1521+ cerr << " Read code: " << return_code << endl;
15071522 break ;
15081523 }
15091524
@@ -1584,7 +1599,6 @@ bool RHD2000Thread::updateBuffer()
15841599
15851600 if (dacOutputShouldChange)
15861601 {
1587- std::cout << " DAC" << std::endl;
15881602 for (int k=0 ; k<8 ; k++)
15891603 {
15901604 if (dacChannelsToUpdate[k])
0 commit comments