diff --git a/src/asciireader.cpp b/src/asciireader.cpp --- a/src/asciireader.cpp +++ b/src/asciireader.cpp @@ -33,6 +33,7 @@ AsciiReader::AsciiReader(QIODevice* devi _numOfChannels = _settingsWidget.numOfChannels(); autoNumOfChannels = (_numOfChannels == NUMOFCHANNELS_AUTO); + delimiter = _settingsWidget.delimiter(); connect(&_settingsWidget, &AsciiReaderSettings::numOfChannelsChanged, [this](unsigned value) @@ -45,6 +46,12 @@ AsciiReader::AsciiReader(QIODevice* devi } }); + connect(&_settingsWidget, &AsciiReaderSettings::delimiterChanged, + [this](QChar d) + { + delimiter = d; + }); + connect(device, &QIODevice::aboutToClose, [this](){discardFirstLine=true;}); } @@ -90,7 +97,7 @@ void AsciiReader::onDataReady() { while(_device->canReadLine()) { - QByteArray line = _device->readLine(); + QString line = QString(_device->readLine()); // discard only once when we just started reading if (discardFirstLine) @@ -116,7 +123,7 @@ void AsciiReader::onDataReady() continue; } - auto separatedValues = line.split(','); + auto separatedValues = line.split(delimiter, QString::SkipEmptyParts); unsigned numReadChannels; // effective number of channels to read unsigned numComingChannels = separatedValues.length(); @@ -143,6 +150,7 @@ void AsciiReader::onDataReady() } // parse read line + unsigned numDataBroken = 0; double* channelSamples = new double[_numOfChannels](); for (unsigned ci = 0; ci < numReadChannels; ci++) { @@ -153,11 +161,15 @@ void AsciiReader::onDataReady() qWarning() << "Data parsing error for channel: " << ci; qWarning() << "Read line: " << line; channelSamples[ci] = 0; + numDataBroken++; } } - // commit data - addData(channelSamples, _numOfChannels); + if (numReadChannels > numDataBroken) + { + // commit data + addData(channelSamples, _numOfChannels); + } delete[] channelSamples; }