Помощь - Поиск - Пользователи - Календарь
Полная версия этой страницы: График из СОМ порта
Форум на CrossPlatform.RU > Библиотеки > Qt > Qt Система рисования. Печать
New_Subscriber
Доброго времени суток!
Стоит довольно довольно простая задача: построить двоичных график данных, поступающих из СОМ порта.

Для получения данных использую функцию
void Receiver::slotReadyRead( )
{
   QByteArray data;
    data = m_serialPort.readAll( );
    emit signalReceivedData( data );
}


Далее привожу к десятичному виду

void MainWindow::slotReceivedData( const QByteArray &data )
{
    graphData = data;
    graphValue = graphData.toInt(&ok,16);
  }


И затем пытаюсь строить график (за основу взял пример графика реального времени из qcustomplot)

void MainWindow::realtimeDataSlot()
{
  // calculate two new data points:

  double key = QDateTime::currentDateTime().toMSecsSinceEpoch()/1000.0;

  static double lastPointKey = 0;
  if (key-lastPointKey > 0.01) // at most add point every 10 ms
  {
      double value0 = graphValue;
    // add data to lines:
    ui->customPlot->graph(0)->addData(key, value0);

    // set data of dots:
    ui->customPlot->graph(2)->clearData();
    ui->customPlot->graph(2)->addData(key, value0);

    // remove data of lines that's outside visible range:
    ui->customPlot->graph(0)->removeDataBefore(key-8);

    // rescale value (vertical) axis to fit the current data:
    ui->customPlot->graph(0)->rescaleValueAxis();

    lastPointKey = key;
  }
  // make key axis range scroll with the data (at a constant range size of 8):
  ui->customPlot->xAxis->setRange(key+0.25, 8, Qt::AlignRight);
  ui->customPlot->replot();

  // calculate frames per second:
  static double lastFpsKey;
  static int frameCount;
  ++frameCount;
  if (key-lastFpsKey > 2) // average fps over 2 seconds
  {
    ui->statusBar->showMessage(
          QString("%1 FPS, Total Data points: %2")
          .arg(frameCount/(key-lastFpsKey), 0, 'f', 0)
          .arg(ui->customPlot->graph(0)->data()->count()+ui->customPlot->graph(1)->data()->count())
          , 0);
    lastFpsKey = key;
    frameCount = 0;
  }
}


Проблема в том, что на графике выводится нулевое значение.
Может кто сталкивался с подобной проблемой?
Или поделится умной ссылкой на что-то подобное

P.S.: Пытался принимать данные побайтно как char
void Receiver::slotReadyRead( )
{
   char data[64];
   m_serialPort.read( data,1 );
   emit signalReceivedData( data );
}


но из этого тоже ничего не вышло
ingwarsmith
Цитата(New_Subscriber @ 28.6.2015, 1:32) *
Далее привожу к десятичному виду

void MainWindow::slotReceivedData( const QByteArray &data )
{
    graphData = data;
    graphValue = graphData.toInt(&ok,16);
  }


И затем пытаюсь строить график (за основу взял пример графика реального времени из qcustomplot)


Думаю, более верным будет решение:

void MainWindow::slotReceivedData( const QByteArray &data )
{
    QByteArray::Iterator it;

    for (it = arr->begin(); it != arr->end(); ++it)
    {
        vec.append((int) *it); // QVector<int> vec;
    }
}


Вместо arr следует понимать data. Простите за опечатку.
New_Subscriber
Спасибо за подсказку.
Попробую
Для просмотра полной версии этой страницы, пожалуйста, пройдите по ссылке.
Форум IP.Board © 2001-2024 IPS, Inc.