#include "mguangyingpinwidget.h" #include "gutil/qgui.h" #include "globaldefine.h" #include #include #include #include #include mGuangYingPinWidget::mGuangYingPinWidget(QWidget *parent) : QWidget(parent) { setAutoFillBackground(true); QPalette pal; pal.setBrush(QPalette::Window, QColor(0xeeeeee)); setPalette(pal); auto vBox = new VBox(this); auto hBox = new HBox(vBox); auto line = new QFrame; line->setFrameShape(QFrame::VLine); line->setFrameShadow(QFrame::Sunken); hBox->addWidget(line); groupBox_com = new QGroupBox(this); groupBox_com->setFlat(true); groupBox_com->setCheckable(true); horizontalLayout_29 = new QHBoxLayout(groupBox_com); horizontalLayout_29->setObjectName(QString::fromUtf8("horizontalLayout_29")); verticalLayout_2 = new QVBoxLayout(); verticalLayout_2->setObjectName(QString::fromUtf8("verticalLayout_2")); verticalLayout_2->setContentsMargins(-1, 0, -1, -1); groupBoxMain = new QGroupBox(groupBox_com); groupBoxMain->setObjectName(QString::fromUtf8("groupBoxMain")); groupBoxMain->setMaximumSize(QSize(200, 16777215)); groupBoxMain->setAlignment(Qt::AlignCenter); groupBoxMain->setFlat(true); verticalLayout_6 = new QVBoxLayout(groupBoxMain); verticalLayout_6->setObjectName(QString::fromUtf8("verticalLayout_6")); horizontalLayout_6 = new QHBoxLayout(); horizontalLayout_6->setObjectName(QString::fromUtf8("horizontalLayout_6")); label_PortName = new QLabel(groupBoxMain); label_PortName->setObjectName(QString::fromUtf8("label_PortName")); horizontalLayout_6->addWidget(label_PortName); comboBox_SPortName = new QComboBox(groupBoxMain); comboBox_SPortName->setObjectName(QString::fromUtf8("comboBox_SPortName")); comboBox_SPortName->setMinimumSize(QSize(80, 0)); horizontalLayout_6->addWidget(comboBox_SPortName); verticalLayout_6->addLayout(horizontalLayout_6); horizontalLayout_9 = new QHBoxLayout(); horizontalLayout_9->setObjectName(QString::fromUtf8("horizontalLayout_9")); horizontalLayout_9->setContentsMargins(-1, 0, -1, -1); label_BaudRate = new QLabel(groupBoxMain); label_BaudRate->setObjectName(QString::fromUtf8("label_BaudRate")); horizontalLayout_9->addWidget(label_BaudRate); comboBox_SPortBaud = new QComboBox(groupBoxMain); comboBox_SPortBaud->addItem("1200"); comboBox_SPortBaud->addItem("2400"); comboBox_SPortBaud->addItem("4800"); comboBox_SPortBaud->addItem("9600"); comboBox_SPortBaud->addItem("19200"); comboBox_SPortBaud->addItem("38400"); comboBox_SPortBaud->addItem("57600"); comboBox_SPortBaud->addItem("115200"); horizontalLayout_9->addWidget(comboBox_SPortBaud); verticalLayout_6->addLayout(horizontalLayout_9); horizontalLayout_15 = new QHBoxLayout(); horizontalLayout_15->setObjectName(QString::fromUtf8("horizontalLayout_15")); horizontalLayout_15->setContentsMargins(-1, 0, -1, -1); label_DataBit = new QLabel(groupBoxMain); label_DataBit->setObjectName(QString::fromUtf8("label_DataBit")); horizontalLayout_15->addWidget(label_DataBit); comboBox_SPortDataBit = new QComboBox(groupBoxMain); comboBox_SPortDataBit->addItem("5"); comboBox_SPortDataBit->addItem("6"); comboBox_SPortDataBit->addItem("7"); comboBox_SPortDataBit->addItem("8"); horizontalLayout_15->addWidget(comboBox_SPortDataBit); verticalLayout_6->addLayout(horizontalLayout_15); horizontalLayout_17 = new QHBoxLayout(); horizontalLayout_17->setObjectName(QString::fromUtf8("horizontalLayout_17")); horizontalLayout_17->setContentsMargins(-1, 0, -1, -1); label_OEBit = new QLabel(groupBoxMain); label_OEBit->setObjectName(QString::fromUtf8("label_OEBit")); horizontalLayout_17->addWidget(label_OEBit); comboBox_SPortOEBit = new QComboBox(groupBoxMain); comboBox_SPortOEBit->addItem(tr("No")); comboBox_SPortOEBit->addItem(tr("Even")); comboBox_SPortOEBit->addItem(tr("Odd")); comboBox_SPortOEBit->addItem(tr("Space")); comboBox_SPortOEBit->addItem(tr("Mark")); horizontalLayout_17->addWidget(comboBox_SPortOEBit); verticalLayout_6->addLayout(horizontalLayout_17); horizontalLayout_18 = new QHBoxLayout(); horizontalLayout_18->setObjectName(QString::fromUtf8("horizontalLayout_18")); horizontalLayout_18->setContentsMargins(-1, 0, -1, -1); label_StopBit = new QLabel(groupBoxMain); label_StopBit->setObjectName(QString::fromUtf8("label_StopBit")); horizontalLayout_18->addWidget(label_StopBit); comboBox_SPortStopBit = new QComboBox(groupBoxMain); comboBox_SPortStopBit->addItem("1"); comboBox_SPortStopBit->addItem("2"); comboBox_SPortStopBit->addItem("1.5"); horizontalLayout_18->addWidget(comboBox_SPortStopBit); verticalLayout_6->addLayout(horizontalLayout_18); horizontalLayout_22 = new QHBoxLayout(); horizontalLayout_22->setObjectName(QString::fromUtf8("horizontalLayout_22")); horizontalLayout_22->setContentsMargins(-1, 0, -1, -1); label_ComStatus = new QLabel(groupBoxMain); label_ComStatus->setObjectName(QString::fromUtf8("label_ComStatus")); horizontalLayout_22->addWidget(label_ComStatus); graphicsView_ComStatus = new QGraphicsView(groupBoxMain); graphicsView_ComStatus->setObjectName(QString::fromUtf8("graphicsView_ComStatus")); graphicsView_ComStatus->setMaximumSize(QSize(30, 30)); horizontalLayout_22->addWidget(graphicsView_ComStatus); verticalLayout_6->addLayout(horizontalLayout_22); horizontalLayout_4 = new QHBoxLayout(); horizontalLayout_4->setObjectName(QString::fromUtf8("horizontalLayout_4")); pushButtonMainOpen = new QPushButton(groupBoxMain); pushButtonMainOpen->setObjectName(QString::fromUtf8("pushButtonMainOpen")); pushButtonMainOpen->setMinimumSize(QSize(80, 30)); horizontalLayout_4->addWidget(pushButtonMainOpen); verticalLayout_6->addLayout(horizontalLayout_4); verticalLayout_2->addWidget(groupBoxMain); horizontalLayout_29->addLayout(verticalLayout_2); line = new QFrame(groupBox_com); line->setFrameShape(QFrame::VLine); line->setFrameShadow(QFrame::Sunken); horizontalLayout_29->addWidget(line); verticalLayout_3 = new QVBoxLayout(); verticalLayout_3->setObjectName(QString::fromUtf8("verticalLayout_3")); verticalLayout_3->setContentsMargins(0, -1, -1, -1); groupBoxAux = new QGroupBox(groupBox_com); groupBoxAux->setObjectName(QString::fromUtf8("groupBoxAux")); groupBoxAux->setMaximumSize(QSize(200, 16777215)); groupBoxAux->setAlignment(Qt::AlignCenter); groupBoxAux->setFlat(true); groupBoxAux->setCheckable(false); verticalLayout_8 = new QVBoxLayout(groupBoxAux); verticalLayout_8->setObjectName(QString::fromUtf8("verticalLayout_8")); horizontalLayout_7 = new QHBoxLayout(); horizontalLayout_7->setObjectName(QString::fromUtf8("horizontalLayout_7")); label_PortNameAux = new QLabel(groupBoxAux); label_PortNameAux->setObjectName(QString::fromUtf8("label_PortNameAux")); horizontalLayout_7->addWidget(label_PortNameAux); comboBox_SPortNameAux = new QComboBox(groupBoxAux); comboBox_SPortNameAux->setObjectName(QString::fromUtf8("comboBox_SPortNameAux")); comboBox_SPortNameAux->setMinimumSize(QSize(80, 0)); horizontalLayout_7->addWidget(comboBox_SPortNameAux); verticalLayout_8->addLayout(horizontalLayout_7); horizontalLayout_24 = new QHBoxLayout(); horizontalLayout_24->setObjectName(QString::fromUtf8("horizontalLayout_24")); label_BaudRateAux = new QLabel(groupBoxAux); label_BaudRateAux->setObjectName(QString::fromUtf8("label_BaudRateAux")); horizontalLayout_24->addWidget(label_BaudRateAux); comboBox_SPortBaudAux = new QComboBox(groupBoxAux); comboBox_SPortBaudAux->addItem("1200"); comboBox_SPortBaudAux->addItem("2400"); comboBox_SPortBaudAux->addItem("4800"); comboBox_SPortBaudAux->addItem("9600"); comboBox_SPortBaudAux->addItem("19200"); comboBox_SPortBaudAux->addItem("38400"); comboBox_SPortBaudAux->addItem("57600"); comboBox_SPortBaudAux->addItem("115200"); horizontalLayout_24->addWidget(comboBox_SPortBaudAux); verticalLayout_8->addLayout(horizontalLayout_24); horizontalLayout_25 = new QHBoxLayout(); horizontalLayout_25->setObjectName(QString::fromUtf8("horizontalLayout_25")); label_DataBitAux = new QLabel(groupBoxAux); label_DataBitAux->setObjectName(QString::fromUtf8("label_DataBitAux")); horizontalLayout_25->addWidget(label_DataBitAux); comboBox_SPortDataBitAux = new QComboBox(groupBoxAux); comboBox_SPortDataBitAux->addItem("5"); comboBox_SPortDataBitAux->addItem("6"); comboBox_SPortDataBitAux->addItem("7"); comboBox_SPortDataBitAux->addItem("8"); horizontalLayout_25->addWidget(comboBox_SPortDataBitAux); verticalLayout_8->addLayout(horizontalLayout_25); horizontalLayout_26 = new QHBoxLayout(); horizontalLayout_26->setObjectName(QString::fromUtf8("horizontalLayout_26")); label_OEBitAux = new QLabel(groupBoxAux); label_OEBitAux->setObjectName(QString::fromUtf8("label_OEBitAux")); horizontalLayout_26->addWidget(label_OEBitAux); comboBox_SPortOEBitAux = new QComboBox(groupBoxAux); comboBox_SPortOEBitAux->addItem(tr("No")); comboBox_SPortOEBitAux->addItem(tr("Even")); comboBox_SPortOEBitAux->addItem(tr("Odd")); comboBox_SPortOEBitAux->addItem(tr("Space")); comboBox_SPortOEBitAux->addItem(tr("Mark")); horizontalLayout_26->addWidget(comboBox_SPortOEBitAux); verticalLayout_8->addLayout(horizontalLayout_26); horizontalLayout_27 = new QHBoxLayout(); horizontalLayout_27->setObjectName(QString::fromUtf8("horizontalLayout_27")); label_StopBitAux = new QLabel(groupBoxAux); label_StopBitAux->setObjectName(QString::fromUtf8("label_StopBitAux")); horizontalLayout_27->addWidget(label_StopBitAux); comboBox_SPortStopBitAux = new QComboBox(groupBoxAux); comboBox_SPortStopBitAux->addItem("1"); comboBox_SPortStopBitAux->addItem("2"); comboBox_SPortStopBitAux->addItem("1.5"); horizontalLayout_27->addWidget(comboBox_SPortStopBitAux); verticalLayout_8->addLayout(horizontalLayout_27); horizontalLayout_28 = new QHBoxLayout(); horizontalLayout_28->setObjectName(QString::fromUtf8("horizontalLayout_28")); label_ComStatusAux = new QLabel(groupBoxAux); label_ComStatusAux->setObjectName(QString::fromUtf8("label_ComStatusAux")); horizontalLayout_28->addWidget(label_ComStatusAux); graphicsView_ComStatusAux = new QGraphicsView(groupBoxAux); graphicsView_ComStatusAux->setObjectName(QString::fromUtf8("graphicsView_ComStatusAux")); graphicsView_ComStatusAux->setMaximumSize(QSize(30, 30)); horizontalLayout_28->addWidget(graphicsView_ComStatusAux); verticalLayout_8->addLayout(horizontalLayout_28); horizontalLayout_5 = new QHBoxLayout(); horizontalLayout_5->setObjectName(QString::fromUtf8("horizontalLayout_5")); pushButtonAuxOpen = new QPushButton(groupBoxAux); pushButtonAuxOpen->setObjectName(QString::fromUtf8("pushButtonAuxOpen")); pushButtonAuxOpen->setMinimumSize(QSize(80, 30)); horizontalLayout_5->addWidget(pushButtonAuxOpen); verticalLayout_8->addLayout(horizontalLayout_5); verticalLayout_3->addWidget(groupBoxAux); horizontalLayout_29->addLayout(verticalLayout_3); pushButtonRefresh = new QPushButton(groupBox_com); pushButtonRefresh->setMinimumSize(QSize(80, 40)); horizontalLayout_29->addWidget(pushButtonRefresh); hBox->addWidget(groupBox_com); groupBox_Network = new QGroupBox(this); groupBox_Network->setObjectName(QString::fromUtf8("groupBox_Network")); groupBox_Network->setFlat(true); groupBox_Network->setCheckable(true); groupBox_Network->setChecked(false); hBox->addWidget(groupBox_Network); horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); hBox->addItem(horizontalSpacer); line = new QFrame; line->setFrameShape(QFrame::VLine); line->setFrameShadow(QFrame::Sunken); hBox->addWidget(line); verticalLayout_9 = new QVBoxLayout(); verticalLayout_9->setObjectName(QString::fromUtf8("verticalLayout_9")); verticalLayout_9->setContentsMargins(-1, 0, -1, -1); groupBoxParam = new QGroupBox; groupBoxParam->setMaximumSize(QSize(200, 16777215)); groupBoxParam->setAlignment(Qt::AlignCenter); groupBoxParam->setFlat(true); verticalLayout_10 = new QVBoxLayout(groupBoxParam); verticalLayout_10->setObjectName(QString::fromUtf8("verticalLayout_10")); horizontalLayout_20 = new QHBoxLayout(); horizontalLayout_20->setObjectName(QString::fromUtf8("horizontalLayout_20")); label_ResendTimes = new QLabel(groupBoxParam); label_ResendTimes->setObjectName(QString::fromUtf8("label_ResendTimes")); horizontalLayout_20->addWidget(label_ResendTimes); lineEdit_ResendTimes = new QLineEdit("10"); lineEdit_ResendTimes->setMaximumWidth(80); horizontalLayout_20->addWidget(lineEdit_ResendTimes); verticalLayout_10->addLayout(horizontalLayout_20); horizontalLayout_23 = new QHBoxLayout(); label_DelayMill = new QLabel(groupBoxParam); horizontalLayout_23->addWidget(label_DelayMill); lineEdit_DelayMill = new QLineEdit("10"); lineEdit_DelayMill->setMaximumWidth(80); horizontalLayout_23->addWidget(lineEdit_DelayMill); verticalLayout_10->addLayout(horizontalLayout_23); verticalLayout_9->addWidget(groupBoxParam); verticalSpacer = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding); verticalLayout_9->addItem(verticalSpacer); hBox->addLayout(verticalLayout_9); horizontalSpacer_2 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); hBox->addItem(horizontalSpacer_2); line = new QFrame; line->setFrameShape(QFrame::HLine); line->setFrameShadow(QFrame::Sunken); vBox->addWidget(line); verticalLayout_4 = new QVBoxLayout(); horizontalLayout_14 = new QHBoxLayout(); horizontalLayout_14->setContentsMargins(-1, 2, -1, -1); auto grid = new Grid(horizontalLayout_14); auto grp = new QButtonGroup(grid); for(int i=0; i<20; ++i) { auto btn = new QPushButton(QString::number(i+1)); grp->addButton(btn, i+1); btn->setFixedSize(40, 40); btn->setProperty("ssType", "progManageTool"); grid->addWidget(btn, i/5, i%5); } connect(grp, &QButtonGroup::idClicked, this, [=](int id) { if(groupBox_com->isChecked()) { if(pushButtonMainOpen->text()==tr("Close")) Set_program_buf_and_send(comboBox_SPortName->currentIndex(), id); if(pushButtonAuxOpen->text()==tr("Close")) Set_program_buf_and_send(comboBox_SPortNameAux->currentIndex(), id); } if(groupBox_Network->isChecked()) Set_program_buf_and_send_by_udp(id); }); line = new QFrame; line->setFrameShape(QFrame::VLine); line->setFrameShadow(QFrame::Sunken); horizontalLayout_14->addWidget(line); verticalLayout_7 = new QVBoxLayout(); verticalLayout_7->setContentsMargins(0, -1, -1, -1); horizontalLayout_19 = new QHBoxLayout(); horizontalLayout_19->setContentsMargins(0, -1, -1, -1); label_ProgramNum = new QLabel; label_ProgramNum->setMinimumSize(QSize(88, 0)); horizontalLayout_19->addWidget(label_ProgramNum); spinBox_ProgramIndex = new QSpinBox; spinBox_ProgramIndex->setMinimumSize(QSize(60, 0)); spinBox_ProgramIndex->setMaximum(999); spinBox_ProgramIndex->setValue(21); horizontalLayout_19->addWidget(spinBox_ProgramIndex); pushButtonSend = new QPushButton; pushButtonSend->setMinimumSize(QSize(80, 40)); horizontalLayout_19->addWidget(pushButtonSend); line = new QFrame; line->setFrameShape(QFrame::VLine); line->setFrameShadow(QFrame::Sunken); horizontalLayout_19->addWidget(line); auto pushButtonPrevious = new QPushButton; pushButtonPrevious->setMinimumSize(QSize(40, 40)); pushButtonPrevious->setIconSize(QSize(32, 32)); pushButtonPrevious->setFlat(true); horizontalLayout_19->addWidget(pushButtonPrevious); auto pushButtonNext = new QPushButton; pushButtonNext->setMinimumSize(QSize(40, 40)); pushButtonNext->setIconSize(QSize(32, 32)); pushButtonNext->setFlat(true); horizontalLayout_19->addWidget(pushButtonNext); auto btnLoop = new QPushButton(QIcon(":/res/loop.png"), QString()); btnLoop->setProperty("ssType", "progManageTool"); btnLoop->setMinimumSize(QSize(40, 40)); btnLoop->setIconSize(QSize(32, 32)); btnLoop->setFlat(true); grp->addButton(btnLoop, 0); horizontalLayout_19->addWidget(btnLoop); horizontalSpacer_7 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); horizontalLayout_19->addItem(horizontalSpacer_7); verticalLayout_7->addLayout(horizontalLayout_19); line = new QFrame; line->setFrameShape(QFrame::HLine); line->setFrameShadow(QFrame::Sunken); verticalLayout_7->addWidget(line); horizontalLayout_21 = new QHBoxLayout(); label_BrightNess = new QLabel; label_BrightNess->setMinimumSize(QSize(88, 0)); horizontalLayout_21->addWidget(label_BrightNess); spinBox_BrightnessValue = new QSpinBox; spinBox_BrightnessValue->setMinimumSize(QSize(60, 0)); spinBox_BrightnessValue->setMaximum(255); spinBox_BrightnessValue->setValue(255); horizontalLayout_21->addWidget(spinBox_BrightnessValue); pushButtonBrightnessSet = new QPushButton; pushButtonBrightnessSet->setMinimumSize(QSize(80, 40)); horizontalLayout_21->addWidget(pushButtonBrightnessSet); line = new QFrame; line->setFrameShape(QFrame::VLine); line->setFrameShadow(QFrame::Sunken); horizontalLayout_21->addWidget(line); pushButtonScreenOff = new QPushButton; pushButtonScreenOff->setMinimumSize(QSize(80, 40)); horizontalLayout_21->addWidget(pushButtonScreenOff); pushButtonScreenOn = new QPushButton; pushButtonScreenOn->setMinimumSize(QSize(80, 40)); horizontalLayout_21->addWidget(pushButtonScreenOn); horizontalSpacer_18 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); horizontalLayout_21->addItem(horizontalSpacer_18); verticalLayout_7->addLayout(horizontalLayout_21); verticalSpacer_2 = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding); verticalLayout_7->addItem(verticalSpacer_2); horizontalLayout_2 = new QHBoxLayout(); horizontalLayout_2->setContentsMargins(-1, 20, -1, -1); horizontalSpacer_3 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); horizontalLayout_2->addItem(horizontalSpacer_3); pushButtonClearLog = new QPushButton; horizontalLayout_2->addWidget(pushButtonClearLog); checkBoxDebug = new QCheckBox; checkBoxDebug->setChecked(false); horizontalLayout_2->addWidget(checkBoxDebug); verticalLayout_7->addLayout(horizontalLayout_2); horizontalLayout_14->addLayout(verticalLayout_7); verticalLayout_4->addLayout(horizontalLayout_14); vBox->addLayout(verticalLayout_4); line = new QFrame; line->setFrameShape(QFrame::HLine); line->setFrameShadow(QFrame::Sunken); vBox->addWidget(line); horizontalLayout_3 = new QHBoxLayout(); horizontalLayout_8 = new QHBoxLayout(); textEditReadBuf = new QTextEdit; textEditReadBuf->setSizeAdjustPolicy(QAbstractScrollArea::AdjustIgnored); textEditReadBuf->setUndoRedoEnabled(false); textEditReadBuf->setReadOnly(true); horizontalLayout_8->addWidget(textEditReadBuf); horizontalLayout_3->addLayout(horizontalLayout_8); vBox->addLayout(horizontalLayout_3); pushButtonSend->setProperty("ssType", "progManageTool"); pushButtonPrevious->setProperty("ssType", "progManageTool"); pushButtonPrevious->setIcon(QIcon(":/res/previous.png")); pushButtonNext->setProperty("ssType", "progManageTool"); pushButtonNext->setIcon(QIcon(":/res/next.png")); pushButtonMainOpen->setProperty("ssType", "progManageTool"); pushButtonAuxOpen->setProperty("ssType", "progManageTool"); pushButtonBrightnessSet->setProperty("ssType", "progManageTool"); pushButtonScreenOn->setProperty("ssType", "progManageTool"); pushButtonScreenOff->setProperty("ssType", "progManageTool"); pushButtonRefresh->setProperty("ssType", "progManageTool"); pushButtonClearLog->setProperty("ssType", "progManageTool"); m_recvNum = 0; m_sendNum = 0; sPortThread = new TA_SerialThread; sPortThread->SearchPort(); for(uint8_t i = 0;i < sPortThread->portCnt;i++) { comboBox_SPortName->addItem(sPortThread->m_arrSerial[i].portName()); comboBox_SPortNameAux->addItem(sPortThread->m_arrSerial[i].portName()); } //0:1200 1:2400 2:4800 3:9600 4:19200 5:38400 6:57600 7:115200 if(comboBox_SPortName->count()>=1) { comboBox_SPortBaud->setCurrentIndex(3); //0:5 1:6 2:7 3:8 comboBox_SPortDataBit->setCurrentIndex(3); //0:no p 2:e p 3:o p 4:s p 5:m p comboBox_SPortOEBit->setCurrentIndex(0); //0:1 1:2 2:1.5 comboBox_SPortStopBit->setCurrentIndex(0); graphicsView_ComStatus->setStyleSheet("background-color: rgb(255, 0, 0);"); label_ComStatus->setText(tr("State:Off")); comboBox_SPortBaudAux->setCurrentIndex(3); comboBox_SPortDataBitAux->setCurrentIndex(3); comboBox_SPortOEBitAux->setCurrentIndex(0); comboBox_SPortStopBitAux->setCurrentIndex(0); graphicsView_ComStatusAux->setStyleSheet("background-color: rgb(255, 0, 0);"); label_ComStatusAux->setText(tr("State:Off")); if(comboBox_SPortName->count()>1) { comboBox_SPortNameAux->setCurrentIndex(1); } } lineEdit_ResendTimes->setValidator(new QIntValidator(1,1000,this)); lineEdit_DelayMill->setValidator(new QIntValidator(1,1000,this)); connect(pushButtonMainOpen, SIGNAL(clicked(bool)), this, SLOT(MWOnoffPort())); connect(pushButtonAuxOpen, SIGNAL(clicked(bool)), this, SLOT(MWOnoffPortAux())); connect(pushButtonClearLog, SIGNAL(clicked()), this, SLOT(OnClearLog())); connect(pushButtonSend, SIGNAL(clicked()), this, SLOT(OnAnsyProgramCustom())); connect(pushButtonNext, SIGNAL(clicked()), this, SLOT(OnAnsyProgramNext())); connect(pushButtonPrevious, SIGNAL(clicked()), this, SLOT(OnAnsyProgramPrevious())); connect(pushButtonBrightnessSet, SIGNAL(clicked()), this, SLOT(OnBrightnessSet())); connect(pushButtonScreenOn, SIGNAL(clicked()), this, SLOT(OnScreenOn())); connect(pushButtonScreenOff, SIGNAL(clicked()), this, SLOT(OnScreenOff())); connect(spinBox_ProgramIndex, SIGNAL(valueChanged(int)), this, SLOT(OnAnsyProgramCustomByChanged(int))); connect(spinBox_BrightnessValue, SIGNAL(valueChanged(int)), this, SLOT(OnBrightnessSetByChanged(int))); connect(pushButtonRefresh, SIGNAL(clicked()), this, SLOT(OnRefresh())); transUi(); } void mGuangYingPinWidget::changeEvent(QEvent *event) { QWidget::changeEvent(event); if(event->type() == QEvent::LanguageChange) transUi(); } void mGuangYingPinWidget::transUi() { pushButtonSend->setText(tr("Send")); pushButtonMainOpen->setText(tr("Open")); pushButtonAuxOpen->setText(tr("Open")); pushButtonBrightnessSet->setText(tr("Set")); pushButtonScreenOn->setText(tr("Screen On")); pushButtonScreenOff->setText(tr("Screen Off")); pushButtonRefresh->setText(tr("Refresh")); groupBoxMain->setTitle(tr("Main")); groupBoxAux->setTitle(tr("Auxiliary")); groupBoxParam->setTitle(tr("Param configuration")); label_PortName->setText(tr("PortName")); label_BaudRate->setText(tr("BaudRate")); label_DataBit->setText(tr("DataBit")); label_OEBit->setText(tr("OEBit")); label_StopBit->setText(tr("StopBit")); label_PortNameAux->setText(tr("PortName")); label_BaudRateAux->setText(tr("BaudRate")); label_DataBitAux->setText(tr("DataBit")); label_OEBitAux->setText(tr("OEBit")); label_StopBitAux->setText(tr("StopBit")); label_ResendTimes->setText(tr("Resend times")); label_DelayMill->setText(tr("Delay millsecond")); label_ProgramNum->setText(tr("Program number")); label_BrightNess->setText(tr("Brightness")); label_ComStatus->setText(tr("State:Off")); label_ComStatusAux->setText(tr("State:Off")); pushButtonClearLog->setText(tr("Clear")); checkBoxDebug->setText(tr("Debug")); groupBox_Network->setTitle(tr("Network")); groupBox_com->setTitle(tr("Com")); } void mGuangYingPinWidget::OnClearLog(void) { textEditReadBuf->clear(); } void mGuangYingPinWidget::OnAnsyProgramCustom(void) { int id = spinBox_ProgramIndex->value(); if(groupBox_com->isChecked()) { if(pushButtonMainOpen->text()==tr("Close")) Set_program_buf_and_send(comboBox_SPortName->currentIndex(), id); if(pushButtonAuxOpen->text()==tr("Close")) Set_program_buf_and_send(comboBox_SPortNameAux->currentIndex(), id); } if(groupBox_Network->isChecked()) Set_program_buf_and_send_by_udp(id); if(checkBoxDebug->isChecked()) textEditReadBuf->append("OnAnsyProgramCustom"); } void mGuangYingPinWidget::OnAnsyProgramCustomByChanged(int id) { if(groupBox_com->isChecked()) { if(pushButtonMainOpen->text()==tr("Close")) Set_program_buf_and_send(comboBox_SPortName->currentIndex(), id); if(pushButtonAuxOpen->text()==tr("Close")) Set_program_buf_and_send(comboBox_SPortNameAux->currentIndex(), id); } if(groupBox_Network->isChecked()) Set_program_buf_and_send_by_udp(id); } void mGuangYingPinWidget::OnBrightnessSetByChanged(int icurValue) { if(pushButtonMainOpen->text()==tr("Close")) Set_Brightness_buf_and_send(comboBox_SPortName->currentIndex(),icurValue); if(pushButtonAuxOpen->text()==tr("Close")) Set_Brightness_buf_and_send(comboBox_SPortNameAux->currentIndex(),icurValue); } void mGuangYingPinWidget::OnAnsyProgramNext(void) { spinBox_ProgramIndex->setValue(spinBox_ProgramIndex->value()+1); OnAnsyProgramCustom(); } void mGuangYingPinWidget::OnAnsyProgramPrevious(void) { spinBox_ProgramIndex->setValue(spinBox_ProgramIndex->value()-1); OnAnsyProgramCustom(); } void mGuangYingPinWidget::OnBrightnessSet(void) { if(groupBox_com->isChecked()) { if(pushButtonMainOpen->text()==tr("Close")) Set_Brightness_buf_and_send(comboBox_SPortName->currentIndex(),spinBox_BrightnessValue->value()); if(pushButtonAuxOpen->text()==tr("Close")) Set_Brightness_buf_and_send(comboBox_SPortNameAux->currentIndex(),spinBox_BrightnessValue->value()); } if(groupBox_Network->isChecked()) { Set_Brightness_buf_and_send_by_udp(spinBox_BrightnessValue->value()); } } void mGuangYingPinWidget::OnScreenOn(void) { if(groupBox_com->isChecked()) { if(pushButtonMainOpen->text()==tr("Close")) Screen_OnOff_buf_and_send(comboBox_SPortName->currentIndex(),0x11); if(pushButtonAuxOpen->text()==tr("Close")) Screen_OnOff_buf_and_send(comboBox_SPortNameAux->currentIndex(),0x11); } if(groupBox_Network->isChecked()) { Screen_OnOff_buf_and_send_by_udp(0x11); } } void mGuangYingPinWidget::OnScreenOff(void) { if(groupBox_com->isChecked()) { if(pushButtonMainOpen->text()==tr("Close")) Screen_OnOff_buf_and_send(comboBox_SPortName->currentIndex(),0x10); if(pushButtonAuxOpen->text()==tr("Close")) Screen_OnOff_buf_and_send(comboBox_SPortNameAux->currentIndex(),0x10); } if(groupBox_Network->isChecked()) { Screen_OnOff_buf_and_send_by_udp(0x10); } } void mGuangYingPinWidget::OnRefresh() { bool resetAllComboxFlag=true; if(comboBox_SPortName->count()>0) resetAllComboxFlag=false; // comboBox_SPortName->clear(); // comboBox_SPortNameAux->clear(); sPortThread->SearchPort(); // for (int m=0;mportCnt;m++) { // } for(uint8_t i = 0;i < sPortThread->portCnt;i++) { bool iHaveFlag=false; for(int j=0;jcount();j++) { if(comboBox_SPortName->itemText(j)==sPortThread->m_arrSerial[i].portName()) { iHaveFlag=true; break; } } if(iHaveFlag==false) { comboBox_SPortName->addItem(sPortThread->m_arrSerial[i].portName()); } bool iHaveAuxFlag=false; for(int jj=0;jjcount();jj++) { if(comboBox_SPortNameAux->itemText(jj)==sPortThread->m_arrSerial[i].portName()) { iHaveAuxFlag=true; break; } } if(iHaveAuxFlag==false) { comboBox_SPortNameAux->addItem(sPortThread->m_arrSerial[i].portName()); if(comboBox_SPortNameAux->count()>1&&pushButtonAuxOpen->text()==tr("Open")) { comboBox_SPortNameAux->setCurrentIndex(i); } } // comboBox_SPortName->addItem(sPortThread->m_arrSerial[i].portName()); // comboBox_SPortNameAux->addItem(sPortThread->m_arrSerial[i].portName()); } if(resetAllComboxFlag) { //0:1200 1:2400 2:4800 3:9600 4:19200 5:38400 6:57600 7:115200 if(comboBox_SPortName->count()>=1) { comboBox_SPortBaud->setCurrentIndex(3); //0:5 1:6 2:7 3:8 comboBox_SPortDataBit->setCurrentIndex(3); //0:no p 2:e p 3:o p 4:s p 5:m p comboBox_SPortOEBit->setCurrentIndex(0); //0:1 1:2 2:1.5 comboBox_SPortStopBit->setCurrentIndex(0); graphicsView_ComStatus->setStyleSheet("background-color: rgb(255, 0, 0);"); label_ComStatus->setText(tr("State:Off")); comboBox_SPortBaudAux->setCurrentIndex(3); comboBox_SPortDataBitAux->setCurrentIndex(3); comboBox_SPortOEBitAux->setCurrentIndex(0); comboBox_SPortStopBitAux->setCurrentIndex(0); graphicsView_ComStatusAux->setStyleSheet("background-color: rgb(255, 0, 0);"); label_ComStatusAux->setText(tr("State:Off")); if(comboBox_SPortName->count()>1) { comboBox_SPortNameAux->setCurrentIndex(1); } } } } void mGuangYingPinWidget::MWOnoffPort(void) { uint8_t comIndex = comboBox_SPortName->currentIndex(); if(pushButtonMainOpen->text()==tr("Open")) { sPortThread->InitPortName(comIndex,comboBox_SPortName->currentText()); sPortThread->InitPortBaudRate(comIndex,comboBox_SPortBaud->currentText().toInt()); //qDebug()<currentIndex(); switch(comboBox_SPortDataBit->currentIndex()) { case 0: sPortThread->InitPortDataBits(comIndex,QSerialPort::Data5); break;//0:5 case 1: sPortThread->InitPortDataBits(comIndex,QSerialPort::Data6); break;//1:6 case 2: sPortThread->InitPortDataBits(comIndex,QSerialPort::Data7); break;//2:7 case 3: sPortThread->InitPortDataBits(comIndex,QSerialPort::Data8); break;//3:8 default: break; } switch(comboBox_SPortStopBit->currentIndex()) { case 0:sPortThread->InitPortStopBits(comIndex,QSerialPort::OneStop);break; case 1:sPortThread->InitPortStopBits(comIndex,QSerialPort::TwoStop);break; case 2:sPortThread->InitPortStopBits(comIndex,QSerialPort::OneAndHalfStop);break; default: break; } switch(comboBox_SPortOEBit->currentIndex()) { case 0:sPortThread->InitPortParity(comIndex,QSerialPort::NoParity);break; case 1:sPortThread->InitPortParity(comIndex,QSerialPort::EvenParity);break; case 2:sPortThread->InitPortParity(comIndex,QSerialPort::OddParity);break; case 3:sPortThread->InitPortParity(comIndex,QSerialPort::SpaceParity);break; case 4:sPortThread->InitPortParity(comIndex,QSerialPort::MarkParity);break; default: break; } if(sPortThread->OpenPort(comIndex)) { connect(&(sPortThread->m_arrSerial[comIndex]), SIGNAL(readyRead()), this, SLOT(MWReadData())); //参数设置禁止 comboBox_SPortName->setEnabled(false); comboBox_SPortBaud->setEnabled(false); comboBox_SPortDataBit->setEnabled(false); comboBox_SPortOEBit->setEnabled(false); comboBox_SPortStopBit->setEnabled(false); pushButtonMainOpen->setText(tr("Close")); //发送设置使能 graphicsView_ComStatus->setStyleSheet("background-color: rgb(0, 255, 0);"); label_ComStatus->setText(tr("State:On")); } else { QMessageBox::information(this, tr("Tip"), tr("OpenPort COM failed")); } } else { sPortThread->ClosePort(comIndex); //参数设置使能 comboBox_SPortName->setEnabled(true); comboBox_SPortBaud->setEnabled(true); comboBox_SPortDataBit->setEnabled(true); comboBox_SPortOEBit->setEnabled(true); comboBox_SPortStopBit->setEnabled(true); pushButtonMainOpen->setText(tr("Open")); //发送设置禁止 graphicsView_ComStatus->setStyleSheet("background-color: rgb(255, 0, 0);"); label_ComStatus->setText(tr("State:Off")); } } void mGuangYingPinWidget::MWOnoffPortAux(void) { uint8_t comIndex = comboBox_SPortNameAux->currentIndex(); if(pushButtonAuxOpen->text()==tr("Open")) { sPortThread->InitPortName(comIndex,comboBox_SPortNameAux->currentText()); sPortThread->InitPortBaudRate(comIndex,comboBox_SPortBaudAux->currentText().toInt()); //qDebug()<currentIndex(); switch(comboBox_SPortDataBitAux->currentIndex()) { case 0: sPortThread->InitPortDataBits(comIndex,QSerialPort::Data5); break;//0:5 case 1: sPortThread->InitPortDataBits(comIndex,QSerialPort::Data6); break;//1:6 case 2: sPortThread->InitPortDataBits(comIndex,QSerialPort::Data7); break;//2:7 case 3: sPortThread->InitPortDataBits(comIndex,QSerialPort::Data8); break;//3:8 default: break; } switch(comboBox_SPortStopBitAux->currentIndex()) { case 0:sPortThread->InitPortStopBits(comIndex,QSerialPort::OneStop);break; case 1:sPortThread->InitPortStopBits(comIndex,QSerialPort::TwoStop);break; case 2:sPortThread->InitPortStopBits(comIndex,QSerialPort::OneAndHalfStop);break; default: break; } switch(comboBox_SPortOEBitAux->currentIndex()) { case 0:sPortThread->InitPortParity(comIndex,QSerialPort::NoParity);break; case 1:sPortThread->InitPortParity(comIndex,QSerialPort::EvenParity);break; case 2:sPortThread->InitPortParity(comIndex,QSerialPort::OddParity);break; case 3:sPortThread->InitPortParity(comIndex,QSerialPort::SpaceParity);break; case 4:sPortThread->InitPortParity(comIndex,QSerialPort::MarkParity);break; default: break; } if(sPortThread->OpenPort(comIndex)) { connect(&(sPortThread->m_arrSerial[comIndex]), SIGNAL(readyRead()), this, SLOT(MWReadDataAux())); //参数设置禁止 comboBox_SPortNameAux->setEnabled(false); comboBox_SPortBaudAux->setEnabled(false); comboBox_SPortDataBitAux->setEnabled(false); comboBox_SPortOEBitAux->setEnabled(false); comboBox_SPortStopBitAux->setEnabled(false); pushButtonAuxOpen->setText(tr("Close")); //发送设置使能 graphicsView_ComStatusAux->setStyleSheet("background-color: rgb(0, 255, 0);"); label_ComStatusAux->setText(tr("State:On")); } else { QMessageBox::information(this, tr("Tip"), tr("OpenPort COM failed")); } } else { sPortThread->ClosePort(comIndex); //参数设置使能 comboBox_SPortNameAux->setEnabled(true); comboBox_SPortBaudAux->setEnabled(true); comboBox_SPortDataBitAux->setEnabled(true); comboBox_SPortOEBitAux->setEnabled(true); comboBox_SPortStopBitAux->setEnabled(true); pushButtonAuxOpen->setText(tr("Open")); //发送设置禁止 graphicsView_ComStatusAux->setStyleSheet("background-color: rgb(255, 0, 0);"); label_ComStatusAux->setText(tr("State:Off")); } } void mGuangYingPinWidget::Set_program_buf_and_send(int iComIndex,int iProgramIndex) { unsigned char uctemp[3]={0}; uctemp[0]=0x30+iProgramIndex; int m_uiResendTimes=lineEdit_ResendTimes->text().toInt(); int m_uimillisecond=lineEdit_DelayMill->text().toInt(); unsigned short iDelayTimes=m_uiResendTimes*m_uimillisecond; qint64 dwStart; qint64 dwStop; dwStart = QDateTime::currentMSecsSinceEpoch(); dwStop=dwStart; for(int i=0;i<(int)m_uiResendTimes;i++) { int itiaozheng=dwStop-dwStart-m_uimillisecond;//时间发送间隔和参数发送间隔的差异 if(itiaozheng<0) itiaozheng=0; unsigned short itemp=(iDelayTimes-i*m_uimillisecond)-itiaozheng;//补充差异,比如实际用了110毫秒,参数100毫秒,则发送过去的协议数据应该是让控制卡减少延时,所以在延时值上再减去补差 if(itemp<0) itemp=0; dwStart=dwStop; memcpy(&uctemp[1],(unsigned char *)&itemp,2*sizeof(unsigned char)); MWSendCmd(iComIndex,0x42,uctemp,3,g_iCountCmd); int itempDelay=0; if(itiaozheng>0) itempDelay=m_uimillisecond-itiaozheng; else itempDelay=m_uimillisecond; mymidelay(itempDelay); dwStop = QDateTime::currentMSecsSinceEpoch(); if(checkBoxDebug->isChecked()) { textEditReadBuf->append("dwStart="+QString::number(dwStart)+",dwStop="+QString::number(dwStop)+",dwStop-dwStart="+QString::number(dwStop-dwStart)+",Delay="+QString::number(itempDelay)+",buf delay value="+QString::number(itemp)+"\r\n"); } } g_iCountCmd++; } void mGuangYingPinWidget::Set_program_buf_and_send_by_udp(int iProgramIndex) { unsigned char uctemp[3]={0}; uctemp[0]=0x30+iProgramIndex; int m_uiResendTimes=lineEdit_ResendTimes->text().toInt(); int m_uimillisecond=lineEdit_DelayMill->text().toInt(); unsigned short iDelayTimes=m_uiResendTimes*m_uimillisecond; qint64 dwStart; qint64 dwStop; dwStart = QDateTime::currentMSecsSinceEpoch(); dwStop=dwStart; for(int i=0;i<(int)m_uiResendTimes;i++) { int itiaozheng=dwStop-dwStart-m_uimillisecond;//时间发送间隔和参数发送间隔的差异 if(itiaozheng<0) itiaozheng=0; unsigned short itemp=(iDelayTimes-i*m_uimillisecond)-itiaozheng;//补充差异,比如实际用了110毫秒,参数100毫秒,则发送过去的协议数据应该是让控制卡减少延时,所以在延时值上再减去补差 if(itemp<0) itemp=0; dwStart=dwStop; memcpy(&uctemp[1],(unsigned char *)&itemp,2*sizeof(unsigned char)); MWSendCmdByUdp(0x42,uctemp,3,g_iCountCmd); int itempDelay=0; if(itiaozheng>0) itempDelay=m_uimillisecond-itiaozheng; else itempDelay=m_uimillisecond; mymidelay(itempDelay); dwStop = QDateTime::currentMSecsSinceEpoch(); if(checkBoxDebug->isChecked()) { textEditReadBuf->append("dwStart="+QString::number(dwStart)+",dwStop="+QString::number(dwStop)+",dwStop-dwStart="+QString::number(dwStop-dwStart)+",Delay="+QString::number(itempDelay)+",buf delay value="+QString::number(itemp)+"\r\n"); } } g_iCountCmd++; } void mGuangYingPinWidget::Set_Brightness_buf_and_send(int iComIndex,int iBrightnessValue) { unsigned char uctemp[2]={0}; uctemp[0]=0xF1; uctemp[1]=iBrightnessValue; int m_uiResendTimes=lineEdit_ResendTimes->text().toInt(); int m_uimillisecond=lineEdit_DelayMill->text().toInt(); for(int i=0;i<(int)m_uiResendTimes;i++) { MWSendCmd(iComIndex,0x42,uctemp,2,g_iCountCmd); if(checkBoxDebug->isChecked()) { textEditReadBuf->append("SetBrightNess="+QString::number(iBrightnessValue)); } mymidelay(m_uimillisecond); } } void mGuangYingPinWidget::Set_Brightness_buf_and_send_by_udp(int iBrightnessValue) { unsigned char uctemp[2]={0}; uctemp[0]=0xF1; uctemp[1]=iBrightnessValue; int m_uiResendTimes=lineEdit_ResendTimes->text().toInt(); int m_uimillisecond=lineEdit_DelayMill->text().toInt(); for(int i=0;i<(int)m_uiResendTimes;i++) { MWSendCmdByUdp(0x42,uctemp,2,g_iCountCmd); if(checkBoxDebug->isChecked()) { textEditReadBuf->append("SetBrightNess="+QString::number(iBrightnessValue)); } mymidelay(m_uimillisecond); } } void mGuangYingPinWidget::Screen_OnOff_buf_and_send(int iComIndex,int iScreenOnOff) { unsigned char uctemp[3]={0}; uctemp[0]=iScreenOnOff; uctemp[1]=0; uctemp[2]=0; int m_uiResendTimes=lineEdit_ResendTimes->text().toInt(); int m_uimillisecond=lineEdit_DelayMill->text().toInt(); for(int i=0;i<(int)m_uiResendTimes;i++) { MWSendCmd(iComIndex,0x42,uctemp,3,g_iCountCmd); if(checkBoxDebug->isChecked()) { if(iScreenOnOff==0x11) textEditReadBuf->append("Screen On"); else textEditReadBuf->append("Screen Off"); } mymidelay(m_uimillisecond); } } void mGuangYingPinWidget::Screen_OnOff_buf_and_send_by_udp(int iScreenOnOff) { unsigned char uctemp[3]={0}; uctemp[0]=iScreenOnOff; uctemp[1]=0; uctemp[2]=0; int m_uiResendTimes=lineEdit_ResendTimes->text().toInt(); int m_uimillisecond=lineEdit_DelayMill->text().toInt(); for(int i=0;i<(int)m_uiResendTimes;i++) { MWSendCmdByUdp(0x42,uctemp,3,g_iCountCmd); if(checkBoxDebug->isChecked()) { if(iScreenOnOff==0x11) textEditReadBuf->append("Screen On"); else textEditReadBuf->append("Screen Off"); } mymidelay(m_uimillisecond); } } void mGuangYingPinWidget::NextProgram_buf_and_send(int iComIndex) { unsigned char uctemp[1]={0}; uctemp[0]=0xF3; int m_uiResendTimes=lineEdit_ResendTimes->text().toInt(); int m_uimillisecond=lineEdit_DelayMill->text().toInt(); for(int i=0;i<(int)m_uiResendTimes;i++) { MWSendCmd(iComIndex,0x42,uctemp,1,g_iCountCmd); if(checkBoxDebug->isChecked()) { textEditReadBuf->append("Next Program"); } mymidelay(m_uimillisecond); } } void mGuangYingPinWidget::NextProgram_buf_and_send_by_udp() { unsigned char uctemp[1]={0}; uctemp[0]=0xF3; int m_uiResendTimes=lineEdit_ResendTimes->text().toInt(); int m_uimillisecond=lineEdit_DelayMill->text().toInt(); for(int i=0;i<(int)m_uiResendTimes;i++) { MWSendCmdByUdp(0x42,uctemp,1,g_iCountCmd); if(checkBoxDebug->isChecked()) { textEditReadBuf->append("Next Program"); } mymidelay(m_uimillisecond); } } void mGuangYingPinWidget::mymidelay(int imlsec) { qint64 dwStart, dwStop; dwStart = QDateTime::currentMSecsSinceEpoch(); do{ dwStop = QDateTime::currentMSecsSinceEpoch(); } while(dwStop-imlsec(&tempStreadPakcet), iLenPacket); //sPortThread->SendDataBuf(iComIndex,databuf); QList networkinterfaces = QNetworkInterface::allInterfaces(); foreach (QNetworkInterface interfaces, networkinterfaces) //networkinterfaces负责提供主机的IP地址和网络接口的列表 { foreach (QNetworkAddressEntry entry, interfaces.addressEntries())//QNetworkAddressEntry存储了一个IP地址,子网掩码和广播地址 { QHostAddress broadcastAddress("255.255.255.255"); entry.setBroadcast(QHostAddress::Broadcast); QUdpSocket *tempUdpSocket= new QUdpSocket(this); if(!tempUdpSocket->bind(entry.ip())) break; int iSendLength=tempUdpSocket->writeDatagram((char *)&tempStreadPakcet,iLenPacket,broadcastAddress,31296); if(iSendLength != iLenPacket) { char *aa=reinterpret_cast(&tempStreadPakcet); tempUdpSocket->writeDatagram(&aa[iSendLength],iLenPacket-iSendLength,broadcastAddress,31296); } delete tempUdpSocket; } } if(checkBoxDebug->isChecked()) { textEditReadBuf->append("udp:"+tr(databuf.toHex())); } } void mGuangYingPinWidget::MWSendCmd(uint8_t iComIndex,unsigned char cmd,unsigned char *pUcValue,unsigned int iLength,int iCountCmd) { ST_ANSY_PROGRAM_PACKET tempStreadPakcet; tempStreadPakcet.ucCommType=cmd; tempStreadPakcet.iBaoLiu=iCountCmd; tempStreadPakcet.iLength=iLength; memcpy(tempStreadPakcet.pDataBuffer,pUcValue,iLength); tempStreadPakcet.pDataBuffer[tempStreadPakcet.iLength]=GetCheckCodeIn8(&tempStreadPakcet.ucCommType,tempStreadPakcet.iLength+sizeof(tempStreadPakcet.iBaoLiu)+sizeof(tempStreadPakcet.ucCommType)+sizeof(tempStreadPakcet.iLength)); int iLenPacket=3*sizeof(unsigned char)+sizeof(char)+sizeof(int)+sizeof(int)+tempStreadPakcet.iLength+sizeof(char);/////除正文外的协议结构大小; QByteArray databuf = QByteArray(reinterpret_cast(&tempStreadPakcet), iLenPacket); sPortThread->SendDataBuf(iComIndex,databuf); if(checkBoxDebug->isChecked()) { textEditReadBuf->append("com:"+tr(databuf.toHex())); } //sPortThread->SendDataBuf(comboBox_SPortName->currentIndex(),textEdit->toPlainText().toLatin1()); // m_sendNum += (textEdit->toPlainText().toLatin1()).length(); // MWRSNumDisplay(); } void mGuangYingPinWidget::MWReadData(void) { QByteArray buf; buf = sPortThread->GetDataBuf(comboBox_SPortName->currentIndex()); if(!buf.isEmpty()) { QString str = tr(buf.toHex()); if(checkBoxDebug->isChecked()) { textEditReadBuf->moveCursor(QTextCursor::End); textEditReadBuf->insertPlainText(str); } MWRSNumDisplay(); } buf.clear(); } void mGuangYingPinWidget::MWReadDataAux(void) { QByteArray buf; buf = sPortThread->GetDataBuf(comboBox_SPortNameAux->currentIndex()); if(!buf.isEmpty()) { QString str = tr(buf.toHex()); if(checkBoxDebug->isChecked()) { textEditReadBuf->moveCursor(QTextCursor::End); textEditReadBuf->insertPlainText(str); } MWRSNumDisplay(); } buf.clear(); } QString mGuangYingPinWidget::ByteArrayToHexString(QByteArray &ba) { QDataStream out(&ba,QIODevice::ReadWrite); //将str的数据 读到out里面去 QString buf; while(!out.atEnd()) { qint8 outChar = 0; out >> outChar; //每次一个字节的填充到 outchar QString str = QString("%1").arg(outChar&0xFF,2,16,QLatin1Char('0')).toUpper() + QString(" "); //2 字符宽度 buf += str; } return buf; } void mGuangYingPinWidget::MWClearRecv(void) { // textBrowser->clear(); // m_recvNum = 0; // m_sendNum = 0; // MWRSNumDisplay(); } void mGuangYingPinWidget::MWRSNumDisplay(void) { // label_RecvNum->setText(tr("已接收:") + QString::number(m_recvNum,10)); // label_SendNum->setText(tr("已发送:") + QString::number(m_sendNum,10)); } TA_SerialThread::TA_SerialThread() { portCnt = 0; portNewCnt=0; m_arrSerial = new QSerialPort[10]; m_arrNewSerial=new QSerialPortInfo[10]; } void TA_SerialThread::SearchPort(void) { portNewCnt=0; //查找可用的串口 foreach(const QSerialPortInfo &info, QSerialPortInfo::availablePorts()) { if(portNewCnt > 9) break; m_arrNewSerial[portNewCnt]=info; portNewCnt++; } for (int i=0;i