[Main Thread]
{
workerThread = new StreamToVector();
workerThread->moveToThread(frmThread);
connect(workerThread, &DataStreamToVector::destroyed, frmThread, &QThread::quit);
connect(workerThread, &DataStreamToVector::destroyed, workerThread, &DataStreamToVector::deleteLater);
connect(this, &DataStreamToBuffer::DataToVector_Signal, workerThread, &DataStreamToVector::parseStreamToVector_Slot, Qt::DirectConnection);
frmThread->start();
DataToVector_Signal(dataStream, dataSize, RecordsPerTriggerEvent);
}
[worker thread .h ]
[worker thread .cpp ]
void DataStreamToVector
::parseStreamToVector_Slot(QString dataStream,
int dataSize, uint RecordsPerTriggerEvent
) {
static QVector < QVector<QString> > cycleBuffer
(63, QVector<QString>
(MAX_CYCLE_SIZE_x10MS
));
static uint recordCnt = 1;
if ( recordCnt > RecordsPerTriggerEvent ) {
QVector < QVector<QString> > defaultBuffer
(63, QVector<QString>
(MAX_CYCLE_SIZE_x10MS
));
recordCnt = 1;
cycleBuffer.swap(defaultBuffer);
cycleBuffer.reserve(GALIL_40x0_ADDRESS_COUNT);
}
if ( recordCnt <= recPerCycle ) {
cycleBuffer[0][recordCnt].append(dataStream.mid( 12,2 )); // general Input Block 0 address
cycleBuffer[1][recordCnt].append(dataStream.mid( 14,2 ));
// recordCnt typically 350 - 800
if ( recordCnt == RecordsPerTriggerEvent )
writeRecordsToDB(RecordsPerTriggerEvent, cycleBuffer);
recordCnt++;
}
[Main Thread]
{
frmThread = new QThread;
workerThread = new StreamToVector();
workerThread->moveToThread(frmThread);
connect(workerThread, &DataStreamToVector::destroyed, frmThread, &QThread::quit);
connect(workerThread, &DataStreamToVector::destroyed, workerThread, &DataStreamToVector::deleteLater);
connect(this, &DataStreamToBuffer::DataToVector_Signal, workerThread, &DataStreamToVector::parseStreamToVector_Slot, Qt::DirectConnection);
frmThread->start();
DataToVector_Signal(dataStream, dataSize, RecordsPerTriggerEvent);
}
[worker thread .h ]
QThread *frmThread;
[worker thread .cpp ]
void DataStreamToVector::parseStreamToVector_Slot(QString dataStream, int dataSize, uint RecordsPerTriggerEvent)
{
static QVector < QVector<QString> > cycleBuffer(63, QVector<QString>(MAX_CYCLE_SIZE_x10MS));
static uint recordCnt = 1;
if ( recordCnt > RecordsPerTriggerEvent ) {
QVector < QVector<QString> > defaultBuffer(63, QVector<QString>(MAX_CYCLE_SIZE_x10MS));
recordCnt = 1;
cycleBuffer.swap(defaultBuffer);
cycleBuffer.reserve(GALIL_40x0_ADDRESS_COUNT);
}
if ( recordCnt <= recPerCycle ) {
cycleBuffer[0][recordCnt].append(dataStream.mid( 12,2 )); // general Input Block 0 address
cycleBuffer[1][recordCnt].append(dataStream.mid( 14,2 ));
// recordCnt typically 350 - 800
if ( recordCnt == RecordsPerTriggerEvent )
writeRecordsToDB(RecordsPerTriggerEvent, cycleBuffer);
recordCnt++;
}
To copy to clipboard, switch view to plain text mode
Bookmarks