#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QPushButton>
#include <QFont>
#include <QSizePolicy>
#include <QSignalMapper>
#include <QGroupBox>
#include <QFileDialog>
#include <QtCore/qmath.h>
DCB dcb;
COMMTIMEOUTS CommTimeouts;
MainWindow
::MainWindow(QWidget *parent,
struct ProfileParams profPar
) : ui(new Ui::MainWindow)
{
memset(&dcb,0,sizeof(dcb));
dcb.DCBlength = sizeof(dcb);
dcb.BaudRate = CBR_115200;
dcb.ByteSize = 8;
dcb.Parity = NOPARITY;
dcb.StopBits = ONESTOPBIT;
memset(&CommTimeouts, 0x00, sizeof(CommTimeouts));
CommTimeouts.ReadIntervalTimeout = 20;
CommTimeouts.ReadTotalTimeoutConstant = 100;
CommTimeouts.ReadTotalTimeoutMultiplier = 10;
CommTimeouts.WriteTotalTimeoutConstant = 100;
CommTimeouts.WriteTotalTimeoutMultiplier = 10;
std::string slash = "\\\\.\\COM";
std::stringstream sstm;
sstm << slash << profPar.com;
std::string portNumber = sstm.str();
char* aaa;
aaa = new char (portNumber.size());
ComParameters ComPar = {aaa};
char* str;
str = new char(portNumber.size() + 1);
strcpy(str, portNumber.c_str());
ComPar.name = str;
ComPar.dcb = dcb;
ComPar.CommTimeouts = CommTimeouts;
if(comHandle = initCom(ComPar))
{
ui->setupUi(this);
this->showMaximized();
ui
->statusBar
->showMessage
("Port COM"+QString::number(profPar.
com)+" opened",
3000);
ui
->networkBox
->setTitle
(QString::fromStdString(profPar.
name));
QList<QLayout*> m_layouts;
int k = 0, l = 1, a = 0;
for(int b=0; b<profPar.sectors; b++)
{
groupBox->setLayout(vbox);
ui->tlayout->addWidget(groupBox);
m_layouts.append(vbox);
}
for(int j=0; j<profPar.number; j++)
{
int x
= QString::fromStdString(profPar.
nameTab[j
][2]).
toInt() - 1;
btn
[j
]->setObjectName
(QString::fromStdString(profPar.
nameTab[j
][1]));
btn
[j
]->setText
(QString::fromStdString(profPar.
nameTab[j
][1]));
btn
[j
]->setFont
(QFont("MS Shell Dlq 2",
14,
1));
sendSignalMapper->setMapping(btn[j],j);
connect(btn[j],SIGNAL(clicked()),sendSignalMapper,SLOT(map()));
m_layouts[x]->addWidget(btn[j]);
}
connect(sendSignalMapper,SIGNAL(mapped(int)),this ,SLOT(send_data(int)));
connect(ui->startButton, SIGNAL(clicked()), this, SLOT(startLstn()));
connect(ui->stopButton, SIGNAL(clicked()), this, SLOT(stopLstn()));
connect(ui->checkButton, SIGNAL(clicked()), this, SLOT(close()));
connect(ui->logButton, SIGNAL(clicked()), this, SLOT(openLog()));
}
else
{
exit(0);
}
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::send_data(int number)
{
sendDat("#WAITER_OFF", 1);
}
void MainWindow::startLstn()
{
if(startListen())
{
ui->statusBar->showMessage("Listening...");
ui->checkButton->setEnabled(false);
ui->startButton->setEnabled(false);
ui->stopButton->setEnabled(true);
ui->atButton->setEnabled(false);
ui->logButton->setEnabled(false);
}
}
void MainWindow::stopLstn()
{
if(stopListen())
{
ui->statusBar->showMessage("Stopped", 2000);
ui->checkButton->setEnabled(true);
ui->startButton->setEnabled(true);
ui->stopButton->setEnabled(false);
ui->atButton->setEnabled(true);
ui->logButton->setEnabled(true);
}
}
void MainWindow::openLog()
{
QString file = QFileDialog::getOpenFileName(this,tr
("Load log file..."),
"",tr
("Log Files (*.bin)"));
if(!file.isEmpty())
{
logfile *lgfile = new logfile(this,file);
lgfile ->show();
}
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QPushButton>
#include <QFont>
#include <QSizePolicy>
#include <QSignalMapper>
#include <QGroupBox>
#include <QFileDialog>
#include <QtCore/qmath.h>
DCB dcb;
COMMTIMEOUTS CommTimeouts;
QPushButton * btn[16];
MainWindow::MainWindow(QWidget *parent, struct ProfileParams profPar) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
memset(&dcb,0,sizeof(dcb));
dcb.DCBlength = sizeof(dcb);
dcb.BaudRate = CBR_115200;
dcb.ByteSize = 8;
dcb.Parity = NOPARITY;
dcb.StopBits = ONESTOPBIT;
memset(&CommTimeouts, 0x00, sizeof(CommTimeouts));
CommTimeouts.ReadIntervalTimeout = 20;
CommTimeouts.ReadTotalTimeoutConstant = 100;
CommTimeouts.ReadTotalTimeoutMultiplier = 10;
CommTimeouts.WriteTotalTimeoutConstant = 100;
CommTimeouts.WriteTotalTimeoutMultiplier = 10;
std::string slash = "\\\\.\\COM";
std::stringstream sstm;
sstm << slash << profPar.com;
std::string portNumber = sstm.str();
char* aaa;
aaa = new char (portNumber.size());
ComParameters ComPar = {aaa};
char* str;
str = new char(portNumber.size() + 1);
strcpy(str, portNumber.c_str());
ComPar.name = str;
ComPar.dcb = dcb;
ComPar.CommTimeouts = CommTimeouts;
if(comHandle = initCom(ComPar))
{
ui->setupUi(this);
this->showMaximized();
ui->statusBar->showMessage("Port COM"+QString::number(profPar.com)+" opened", 3000);
ui->networkBox->setTitle(QString::fromStdString(profPar.name));
QList<QLayout*> m_layouts;
QSignalMapper* sendSignalMapper = new QSignalMapper(this);//sendMessage
int k = 0, l = 1, a = 0;
for(int b=0; b<profPar.sectors; b++)
{
QGroupBox *groupBox = new QGroupBox(QString::fromStdString(profPar.sectorTab[b][1]));
groupBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
QVBoxLayout *vbox = new QVBoxLayout;
groupBox->setLayout(vbox);
ui->tlayout->addWidget(groupBox);
m_layouts.append(vbox);
}
for(int j=0; j<profPar.number; j++)
{
btn[j] = new QPushButton;
int x = QString::fromStdString(profPar.nameTab[j][2]).toInt() - 1;
btn[j]->setObjectName(QString::fromStdString(profPar.nameTab[j][1]));
btn[j]->setText(QString::fromStdString(profPar.nameTab[j][1]));
btn[j]->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
btn[j]->setFont(QFont("MS Shell Dlq 2", 14, 1));
sendSignalMapper->setMapping(btn[j],j);
connect(btn[j],SIGNAL(clicked()),sendSignalMapper,SLOT(map()));
m_layouts[x]->addWidget(btn[j]);
}
connect(sendSignalMapper,SIGNAL(mapped(int)),this ,SLOT(send_data(int)));
connect(ui->startButton, SIGNAL(clicked()), this, SLOT(startLstn()));
connect(ui->stopButton, SIGNAL(clicked()), this, SLOT(stopLstn()));
connect(ui->checkButton, SIGNAL(clicked()), this, SLOT(close()));
connect(ui->logButton, SIGNAL(clicked()), this, SLOT(openLog()));
}
else
{
QMessageBox::critical(this,"Error", "Cannot open", QMessageBox::Ok);
exit(0);
}
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::send_data(int number)
{
sendDat("#WAITER_OFF", 1);
}
void MainWindow::startLstn()
{
if(startListen())
{
ui->statusBar->showMessage("Listening...");
ui->checkButton->setEnabled(false);
ui->startButton->setEnabled(false);
ui->stopButton->setEnabled(true);
ui->atButton->setEnabled(false);
ui->logButton->setEnabled(false);
}
}
void MainWindow::stopLstn()
{
if(stopListen())
{
ui->statusBar->showMessage("Stopped", 2000);
ui->checkButton->setEnabled(true);
ui->startButton->setEnabled(true);
ui->stopButton->setEnabled(false);
ui->atButton->setEnabled(true);
ui->logButton->setEnabled(true);
}
}
void MainWindow::openLog()
{
QString file = QFileDialog::getOpenFileName(this,tr("Load log file..."),"",tr("Log Files (*.bin)"));
if(!file.isEmpty())
{
logfile *lgfile = new logfile(this,file);
lgfile ->show();
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks