找回密码
 注册

QQ登录

只需一步,快速开始

搜索

基于QT开发的串口上位机串口示波器源码

[复制链接]
Jonsa 发表于 2024-8-28 12:10:08 | 显示全部楼层 |阅读模式
QT开发软件写了一个上位机,串口示波器,既可以用串口发送接收数据,又可以图形化显示
源码 serial_net_graph.zip (22.24 MB, 售价: 1 E币)
程序.png
shot.png
部分源码:
  1. #ifndef MAINWINDOW_H
  2. #define MAINWINDOW_H

  3. #include <QMainWindow>
  4. #include <QMessageBox>
  5. #include <QSerialPort>
  6. #include <QSerialPortInfo>

  7. #include <QFile>
  8. #include <QFileDialog>

  9. #include <QtCharts>
  10. #include "QLineSeries"
  11. #include "QValueAxis"
  12. #include "QTimer"
  13. #include "QTime"
  14. #include "QList"
  15. #include "qmath.h"
  16. #include "QPointF"
  17. #include "QDebug"
  18. #include "QChartView"
  19. #include "dataprocess.h"
  20. #include <QMutex>
  21. #include <QTcpServer>
  22. #include <QTcpSocket>
  23. #include <QUdpSocket>
  24. #include <QtNetwork>

  25. QT_CHARTS_USE_NAMESPACE

  26. namespace Ui {
  27. class MainWindow;
  28. }

  29. #define Channel_number 20



  30. class MainWindow : public QMainWindow
  31. {
  32.     Q_OBJECT

  33. public:
  34.     explicit MainWindow(QWidget *parent = 0);
  35.     ~MainWindow();
  36. private slots:
  37.     void readData();
  38.     //void socket_Read_Data();
  39.     void socket_Disconnected();
  40.     void server_New_Connect();
  41.     //void udp_receive();

  42.     void on_btn_OpenSerial_clicked();

  43.     void on_btn_help_clicked();

  44.     void on_btn_StopDis_clicked();

  45.     void on_action_save_triggered();

  46.     void on_action_load_triggered();

  47.     void on_btn_ClearSeries_clicked();

  48.     void on_btn_SetXSize_clicked();

  49.     void on_CH1_stateChanged();
  50.     void on_CH2_stateChanged();
  51.     void on_CH3_stateChanged();
  52.     void on_CH4_stateChanged();
  53.     void on_CH5_stateChanged();
  54.     void on_CH6_stateChanged();
  55.     void on_CH7_stateChanged();
  56.     void on_CH8_stateChanged();
  57.     void on_CH9_stateChanged();
  58.     void on_CH10_stateChanged();
  59.     void on_CH11_stateChanged();
  60.     void on_CH12_stateChanged();
  61.     void on_CH13_stateChanged();
  62.     void on_CH14_stateChanged();
  63.     void on_CH15_stateChanged();
  64.     void on_CH16_stateChanged();
  65.     void on_CH17_stateChanged();
  66.     void on_CH18_stateChanged();
  67.     void on_CH19_stateChanged();
  68.     void on_CH20_stateChanged();

  69.     void writeData(char* data,unsigned int len);

  70.     void on_BTNSEND_clicked();

  71.     void on_HEXSND_stateChanged();

  72.     void on_pushButton_clicked();

  73.     void on_pushButton_2_clicked();

  74.     void on_pushButton_3_clicked();

  75.     void on_pushButton_4_clicked();

  76.     void on_pushButton_5_clicked();

  77.     void on_pushButton_6_clicked();

  78.     void on_periodsend_stateChanged();

  79.     void on_period_sends();

  80.     void on_cb_SerialPort_activated();


  81. private:
  82.     QString writeDataToCSV();
  83.     void readDataFromCSV(QTextStream &sDataStream);
  84.     void string2hex(QByteArray sendcoms);
  85.     void hex2string(QByteArray &rcvstring);
  86. //    void dispformat(QString appendStr);
  87. private:
  88.     bool SerialSta;
  89.     DataProcess processor;
  90.     bool chartSta;
  91.     QSerialPort *port;
  92.     Ui::MainWindow *ui;
  93.     QLabel *lb_StatusBar_SerialStatus;
  94.     QLabel *lb_StatusBar_DataRecNum;

  95.     QChart *m_chart;
  96.     QLineSeries m_series[Channel_number];
  97.     QVector<QPointF> points[Channel_number];
  98.     QValueAxis *axisX;
  99.     QValueAxis *axisY;

  100.     bool selchx[20];
  101.     unsigned long int dataRecNum=0;
  102.     int XSize = 200;
  103.     int timeId;
  104.     int Xmin=0;
  105.     int Xmax=0;
  106.     float Ymin=3.4028235e38f;
  107.     float Ymax=1.4e-45f;
  108.     QByteArray sendbuff;
  109.     QString recvbuff;
  110.     QTimer *sendTimer;// 定时器对象
  111.     uint16_t rcvmaxsize;
  112.     bool recvconvf;
  113.     QString displaystr;
  114.     QMutex mutex;
  115.     QStringList baudspeed;
  116.     uint8_t commethflag;
  117.     QTcpServer* server;
  118.     QTcpSocket* socket;
  119.     QList<QTcpSocket*> tcpClient;
  120.     QUdpSocket *uSocket;
  121.     QString ipAddr;
  122.     QTcpSocket* TCPCSocket;

  123.     QHostAddress udpfromhost;
  124.     quint16 udpfromport;
  125.     bool bditemf;
  126.     //QList<QHostAddress> ipAddressesList;

  127. };
复制代码


您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|手机版|小黑屋|ELEOK |网站地图

GMT+8, 2024-12-22 11:50

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表