Оптимизация кода, начало работы с комментариями
This commit is contained in:
parent
3f1cd53e19
commit
f10f3c8927
@ -26,36 +26,31 @@ AdcGraphDialog::AdcGraphDialog(QModbusClient *modbusDevice, QWidget *parent) :
|
|||||||
m_teNumber(-1),
|
m_teNumber(-1),
|
||||||
m_adcZero(0),
|
m_adcZero(0),
|
||||||
m_adcOneVolt(4096),
|
m_adcOneVolt(4096),
|
||||||
m_series(new QLineSeries()),
|
|
||||||
m_chart(new QChart()),
|
|
||||||
m_stableStartLine(new QLineSeries()),
|
m_stableStartLine(new QLineSeries()),
|
||||||
m_stableEndLine(new QLineSeries()),
|
m_stableEndLine(new QLineSeries()),
|
||||||
m_stableStartIndex(-1),
|
m_stableStartIndex(-1),
|
||||||
m_stableEndIndex(-1),
|
m_stableEndIndex(-1),
|
||||||
|
m_series(new QLineSeries()),
|
||||||
|
m_chart(new QChart()),
|
||||||
m_startAddress(0),
|
m_startAddress(0),
|
||||||
m_registerCount(100)
|
m_registerCount(100)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
// Настройка основного графика
|
// Настройка основного графика
|
||||||
m_series->setName("АЦП данные");
|
m_series->setName("АЦП данные");
|
||||||
m_chart->addSeries(m_series);
|
m_chart->addSeries(m_series);
|
||||||
|
|
||||||
// Настройка линий стабильного участка
|
// Настройка линий стабильного участка
|
||||||
m_stableStartLine->setName("Начало стаб. участка");
|
m_stableStartLine->setName("Начало стаб. участка");
|
||||||
m_stableStartLine->setColor(Qt::red);
|
m_stableStartLine->setColor(Qt::red);
|
||||||
m_stableStartLine->setPen(QPen(Qt::red, 2, Qt::DashLine));
|
m_stableStartLine->setPen(QPen(Qt::red, 2, Qt::DashLine));
|
||||||
m_chart->addSeries(m_stableStartLine);
|
m_chart->addSeries(m_stableStartLine);
|
||||||
|
|
||||||
m_stableEndLine->setName("Конец стаб. участка");
|
m_stableEndLine->setName("Конец стаб. участка");
|
||||||
m_stableEndLine->setColor(Qt::green);
|
m_stableEndLine->setColor(Qt::green);
|
||||||
m_stableEndLine->setPen(QPen(Qt::green, 2, Qt::DashLine));
|
m_stableEndLine->setPen(QPen(Qt::green, 2, Qt::DashLine));
|
||||||
m_chart->addSeries(m_stableEndLine);
|
m_chart->addSeries(m_stableEndLine);
|
||||||
|
|
||||||
m_chart->setTitle("График АЦП");
|
m_chart->setTitle("График АЦП");
|
||||||
m_chart->legend()->setVisible(true);
|
m_chart->legend()->setVisible(true);
|
||||||
m_chart->legend()->setAlignment(Qt::AlignTop);
|
m_chart->legend()->setAlignment(Qt::AlignTop);
|
||||||
|
|
||||||
m_axisX = new QValueAxis();
|
m_axisX = new QValueAxis();
|
||||||
m_axisX->setTitleText("Отсчеты АЦП");
|
m_axisX->setTitleText("Отсчеты АЦП");
|
||||||
m_axisX->setRange(0, m_registerCount);
|
m_axisX->setRange(0, m_registerCount);
|
||||||
@ -63,7 +58,6 @@ AdcGraphDialog::AdcGraphDialog(QModbusClient *modbusDevice, QWidget *parent) :
|
|||||||
m_series->attachAxis(m_axisX);
|
m_series->attachAxis(m_axisX);
|
||||||
m_stableStartLine->attachAxis(m_axisX);
|
m_stableStartLine->attachAxis(m_axisX);
|
||||||
m_stableEndLine->attachAxis(m_axisX);
|
m_stableEndLine->attachAxis(m_axisX);
|
||||||
|
|
||||||
m_axisY = new QValueAxis();
|
m_axisY = new QValueAxis();
|
||||||
m_axisY->setTitleText("Напряжение, В");
|
m_axisY->setTitleText("Напряжение, В");
|
||||||
m_axisY->setRange(-1.3, 1.3);
|
m_axisY->setRange(-1.3, 1.3);
|
||||||
@ -71,13 +65,10 @@ AdcGraphDialog::AdcGraphDialog(QModbusClient *modbusDevice, QWidget *parent) :
|
|||||||
m_series->attachAxis(m_axisY);
|
m_series->attachAxis(m_axisY);
|
||||||
m_stableStartLine->attachAxis(m_axisY);
|
m_stableStartLine->attachAxis(m_axisY);
|
||||||
m_stableEndLine->attachAxis(m_axisY);
|
m_stableEndLine->attachAxis(m_axisY);
|
||||||
|
|
||||||
QChartView *chartView = new QChartView(m_chart);
|
QChartView *chartView = new QChartView(m_chart);
|
||||||
chartView->setRenderHint(QPainter::Antialiasing);
|
chartView->setRenderHint(QPainter::Antialiasing);
|
||||||
|
|
||||||
QVBoxLayout *layout = new QVBoxLayout(ui->plotWidget);
|
QVBoxLayout *layout = new QVBoxLayout(ui->plotWidget);
|
||||||
layout->addWidget(chartView);
|
layout->addWidget(chartView);
|
||||||
|
|
||||||
// Подключаем сигналы элементов управления диапазоном
|
// Подключаем сигналы элементов управления диапазоном
|
||||||
connect(ui->registerCountSpinBox, QOverload<int>::of(&QSpinBox::valueChanged),
|
connect(ui->registerCountSpinBox, QOverload<int>::of(&QSpinBox::valueChanged),
|
||||||
this, &AdcGraphDialog::on_registerCountChanged);
|
this, &AdcGraphDialog::on_registerCountChanged);
|
||||||
@ -85,21 +76,16 @@ AdcGraphDialog::AdcGraphDialog(QModbusClient *modbusDevice, QWidget *parent) :
|
|||||||
this, &AdcGraphDialog::on_rangeApplyClicked);
|
this, &AdcGraphDialog::on_rangeApplyClicked);
|
||||||
connect(ui->teNumberSpinBox, QOverload<int>::of(&QSpinBox::valueChanged),
|
connect(ui->teNumberSpinBox, QOverload<int>::of(&QSpinBox::valueChanged),
|
||||||
this, &AdcGraphDialog::on_teNumberChanged);
|
this, &AdcGraphDialog::on_teNumberChanged);
|
||||||
|
|
||||||
connect(m_updateTimer, &QTimer::timeout, this, &AdcGraphDialog::onUpdateTimer);
|
connect(m_updateTimer, &QTimer::timeout, this, &AdcGraphDialog::onUpdateTimer);
|
||||||
connect(ui->closeBtn, &QPushButton::clicked, this, &AdcGraphDialog::on_closeBtn_clicked);
|
connect(ui->closeBtn, &QPushButton::clicked, this, &AdcGraphDialog::on_closeBtn_clicked);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
AdcGraphDialog::~AdcGraphDialog()
|
AdcGraphDialog::~AdcGraphDialog()
|
||||||
{
|
{
|
||||||
stopGraph();
|
stopGraph();
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void AdcGraphDialog::setModbusDevice(QModbusClient *device)
|
void AdcGraphDialog::setModbusDevice(QModbusClient *device)
|
||||||
{
|
{
|
||||||
m_modbusDevice = device;
|
m_modbusDevice = device;
|
||||||
@ -113,28 +99,25 @@ void AdcGraphDialog::on_teNumberChanged(int value)
|
|||||||
|
|
||||||
void AdcGraphDialog::setTENumber(int boardID, int teNumber)
|
void AdcGraphDialog::setTENumber(int boardID, int teNumber)
|
||||||
{
|
{
|
||||||
if (m_boardAddress == -1) return;
|
if(m_boardAddress == -1)
|
||||||
|
return;
|
||||||
m_teNumber = teNumber;
|
m_teNumber = teNumber;
|
||||||
m_boardId = boardID;
|
m_boardId = boardID;
|
||||||
m_boardAddress = m_boardId + 1;
|
m_boardAddress = m_boardId + 1;
|
||||||
|
|
||||||
// Обновляем заголовок окна
|
// Обновляем заголовок окна
|
||||||
setWindowTitle(QString("График АЦП - Плата %1, ТЭ %2 (адр %3-%4)")
|
setWindowTitle(QString("График АЦП - Плата %1, ТЭ %2 (адр %3-%4)")
|
||||||
.arg(m_boardId + 1)
|
.arg(m_boardId + 1)
|
||||||
.arg(m_teNumber)
|
.arg(m_teNumber)
|
||||||
.arg(m_startAddress)
|
.arg(m_startAddress)
|
||||||
.arg(m_startAddress + m_registerCount - 1));
|
.arg(m_startAddress + m_registerCount - 1));
|
||||||
|
|
||||||
// Записываем новый номер ТЭ в устройство
|
// Записываем новый номер ТЭ в устройство
|
||||||
if (m_modbusDevice) {
|
if(m_modbusDevice) {
|
||||||
QModbusDataUnit unit(QModbusDataUnit::HoldingRegisters, REG_TE_NUMBER, 1);
|
QModbusDataUnit unit(QModbusDataUnit::HoldingRegisters, REG_TE_NUMBER, 1);
|
||||||
unit.setValue(0, teNumber);
|
unit.setValue(0, teNumber);
|
||||||
|
if(auto *reply = m_modbusDevice->sendWriteRequest(unit, m_boardAddress)) {
|
||||||
if (auto *reply = m_modbusDevice->sendWriteRequest(unit, m_boardAddress)) {
|
if(!reply->isFinished())
|
||||||
if (!reply->isFinished()) {
|
|
||||||
connect(reply, &QModbusReply::finished, this, [this, reply, teNumber]() {
|
connect(reply, &QModbusReply::finished, this, [this, reply, teNumber]() {
|
||||||
if (reply->error() == QModbusDevice::NoError) {
|
if(reply->error() == QModbusDevice::NoError) {
|
||||||
qDebug() << "TE number changed to:" << teNumber;
|
qDebug() << "TE number changed to:" << teNumber;
|
||||||
// Можно обновить данные сразу после смены ТЭ
|
// Можно обновить данные сразу после смены ТЭ
|
||||||
readAdcDataAndIndices();
|
readAdcDataAndIndices();
|
||||||
@ -143,9 +126,8 @@ void AdcGraphDialog::setTENumber(int boardID, int teNumber)
|
|||||||
}
|
}
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
});
|
});
|
||||||
} else {
|
else
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ui->teNumberSpinBox->setValue(teNumber);
|
ui->teNumberSpinBox->setValue(teNumber);
|
||||||
@ -153,130 +135,111 @@ void AdcGraphDialog::setTENumber(int boardID, int teNumber)
|
|||||||
|
|
||||||
void AdcGraphDialog::readCalibrationValues()
|
void AdcGraphDialog::readCalibrationValues()
|
||||||
{
|
{
|
||||||
if (!m_modbusDevice || m_boardAddress == -1) return;
|
if(!m_modbusDevice || m_boardAddress == -1)
|
||||||
|
return;
|
||||||
// Читаем калибровочные значения (регистры 555 и 556)
|
// Читаем калибровочные значения (регистры 555 и 556)
|
||||||
QModbusDataUnit unit(QModbusDataUnit::InputRegisters, REG_ADC_ZERO, 2);
|
QModbusDataUnit unit(QModbusDataUnit::InputRegisters, REG_ADC_ZERO, 2);
|
||||||
|
if(auto *reply = m_modbusDevice->sendReadRequest(unit, m_boardAddress)) {
|
||||||
if (auto *reply = m_modbusDevice->sendReadRequest(unit, m_boardAddress)) {
|
if(!reply->isFinished())
|
||||||
if (!reply->isFinished()) {
|
|
||||||
connect(reply, &QModbusReply::finished, this, [this, reply]() {
|
connect(reply, &QModbusReply::finished, this, [this, reply]() {
|
||||||
if (reply->error() == QModbusDevice::NoError) {
|
if(reply->error() == QModbusDevice::NoError) {
|
||||||
const QModbusDataUnit result = reply->result();
|
const QModbusDataUnit result = reply->result();
|
||||||
if (result.valueCount() >= 2) {
|
if(result.valueCount() >= 2) {
|
||||||
m_adcZero = result.value(0);
|
m_adcZero = result.value(0);
|
||||||
m_adcOneVolt = result.value(1);
|
m_adcOneVolt = result.value(1);
|
||||||
//qDebug() << "Calibration values - Zero:" << m_adcZero << "1V:" << m_adcOneVolt;
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
//qDebug() << "Error reading calibration:" << reply->errorString();
|
|
||||||
}
|
}
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
});
|
});
|
||||||
} else {
|
else
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdcGraphDialog::readStableIndices()
|
void AdcGraphDialog::readStableIndices()
|
||||||
{
|
{
|
||||||
if (!m_modbusDevice || m_boardAddress == -1) return;
|
if(!m_modbusDevice || m_boardAddress == -1)
|
||||||
|
return;
|
||||||
// Читаем индексы стабильного участка (регистры 557 и 558)
|
// Читаем индексы стабильного участка (регистры 557 и 558)
|
||||||
QModbusDataUnit unit(QModbusDataUnit::InputRegisters, REG_STABLE_START, 2);
|
QModbusDataUnit unit(QModbusDataUnit::InputRegisters, REG_STABLE_START, 2);
|
||||||
|
if(auto *reply = m_modbusDevice->sendReadRequest(unit, m_boardAddress)) {
|
||||||
if (auto *reply = m_modbusDevice->sendReadRequest(unit, m_boardAddress)) {
|
if(!reply->isFinished())
|
||||||
if (!reply->isFinished()) {
|
|
||||||
connect(reply, &QModbusReply::finished, this, &AdcGraphDialog::onStableIndicesReady);
|
connect(reply, &QModbusReply::finished, this, &AdcGraphDialog::onStableIndicesReady);
|
||||||
} else {
|
else
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdcGraphDialog::onStableIndicesReady()
|
void AdcGraphDialog::onStableIndicesReady()
|
||||||
{
|
{
|
||||||
auto *reply = qobject_cast<QModbusReply*>(sender());
|
auto *reply = qobject_cast<QModbusReply*>(sender());
|
||||||
if (!reply) return;
|
if(!reply)
|
||||||
|
return;
|
||||||
if (reply->error() == QModbusDevice::NoError) {
|
if(reply->error() == QModbusDevice::NoError) {
|
||||||
const QModbusDataUnit result = reply->result();
|
const QModbusDataUnit result = reply->result();
|
||||||
if (result.valueCount() >= 2) {
|
if(result.valueCount() >= 2) {
|
||||||
m_stableStartIndex = result.value(0);
|
m_stableStartIndex = result.value(0);
|
||||||
m_stableEndIndex = result.value(1);
|
m_stableEndIndex = result.value(1);
|
||||||
//qDebug() << "Stable indices updated - Start:" << m_stableStartIndex << "End:" << m_stableEndIndex;
|
|
||||||
updateStableLines();
|
updateStableLines();
|
||||||
|
|
||||||
// Обновляем статистику с новыми индексами
|
// Обновляем статистику с новыми индексами
|
||||||
updateStatisticsWithStableInfo();
|
updateStatisticsWithStableInfo();
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
//qDebug() << "Error reading stable indices:" << reply->errorString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdcGraphDialog::updateStatistics()
|
void AdcGraphDialog::updateStatistics()
|
||||||
{
|
{
|
||||||
if (m_series->count() > 0) {
|
if(m_series->count() > 0) {
|
||||||
double min = 1000, max = -1000, sum = 0;
|
double min = 1000, max = -1000, sum = 0;
|
||||||
for (const QPointF &point : m_series->points()) {
|
for(const QPointF &point : m_series->points()) {
|
||||||
double y = point.y();
|
double y = point.y();
|
||||||
if (y < min) min = y;
|
if(y < min)
|
||||||
if (y > max) max = y;
|
min = y;
|
||||||
|
if(y > max)
|
||||||
|
max = y;
|
||||||
sum += y;
|
sum += y;
|
||||||
}
|
}
|
||||||
double avg = sum / m_series->count();
|
double avg = sum / m_series->count();
|
||||||
|
|
||||||
ui->minLabel->setText(QString::number(min, 'f', 3) + " В");
|
ui->minLabel->setText(QString::number(min, 'f', 3) + " В");
|
||||||
ui->maxLabel->setText(QString::number(max, 'f', 3) + " В");
|
ui->maxLabel->setText(QString::number(max, 'f', 3) + " В");
|
||||||
ui->avgLabel->setText(QString::number(avg, 'f', 3) + " В");
|
ui->avgLabel->setText(QString::number(avg, 'f', 3) + " В");
|
||||||
|
|
||||||
// Обновляем информацию о стабильном участке
|
// Обновляем информацию о стабильном участке
|
||||||
updateStatisticsWithStableInfo();
|
updateStatisticsWithStableInfo();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void AdcGraphDialog::updateStatisticsWithStableInfo()
|
void AdcGraphDialog::updateStatisticsWithStableInfo()
|
||||||
{
|
{
|
||||||
if (m_series->count() > 0) {
|
if(m_series->count() > 0)
|
||||||
// Используем абсолютные индексы в формате "начальный-конечный"
|
// Используем абсолютные индексы в формате "начальный-конечный"
|
||||||
ui->samplesLabel->setText(
|
ui->samplesLabel->setText(
|
||||||
QString("%1 отсч. (адр %2-%3) [стаб: %4-%5]")
|
QString("%1 отсч. (адр %2-%3) [стаб: %4-%5]")
|
||||||
.arg(m_series->count())
|
.arg(m_series->count())
|
||||||
.arg(m_startAddress)
|
.arg(m_startAddress)
|
||||||
.arg(m_startAddress + m_registerCount - 1)
|
.arg(m_startAddress + m_registerCount - 1)
|
||||||
.arg(m_stableStartIndex) // Абсолютный начальный индекс
|
.arg(m_stableStartIndex) // Абсолютный начальный индекс
|
||||||
.arg(m_stableEndIndex) // Абсолютный конечный индекс
|
.arg(m_stableEndIndex) // Абсолютный конечный индекс
|
||||||
);
|
);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AdcGraphDialog::updateStableLines()
|
void AdcGraphDialog::updateStableLines()
|
||||||
{
|
{
|
||||||
// Очищаем предыдущие линии
|
// Очищаем предыдущие линии
|
||||||
m_stableStartLine->clear();
|
m_stableStartLine->clear();
|
||||||
m_stableEndLine->clear();
|
m_stableEndLine->clear();
|
||||||
|
|
||||||
// Получаем текущий диапазон оси Y
|
// Получаем текущий диапазон оси Y
|
||||||
double yMin = m_axisY->min();
|
double yMin = m_axisY->min();
|
||||||
double yMax = m_axisY->max();
|
double yMax = m_axisY->max();
|
||||||
|
|
||||||
// Добавляем вертикальную линию для начала стабильного участка
|
// Добавляем вертикальную линию для начала стабильного участка
|
||||||
// Учитываем текущий диапазон отображения
|
// Учитываем текущий диапазон отображения
|
||||||
if (m_stableStartIndex >= m_startAddress && m_stableStartIndex < m_startAddress + m_registerCount) {
|
if(m_stableStartIndex >= m_startAddress && m_stableStartIndex < m_startAddress + m_registerCount) {
|
||||||
int relativeStartIndex = m_stableStartIndex - m_startAddress;
|
int relativeStartIndex = m_stableStartIndex - m_startAddress;
|
||||||
m_stableStartLine->append(relativeStartIndex, yMin);
|
m_stableStartLine->append(relativeStartIndex, yMin);
|
||||||
m_stableStartLine->append(relativeStartIndex, yMax);
|
m_stableStartLine->append(relativeStartIndex, yMax);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Добавляем вертикальную линию для конца стабильного участка
|
// Добавляем вертикальную линию для конца стабильного участка
|
||||||
if (m_stableEndIndex >= m_startAddress && m_stableEndIndex < m_startAddress + m_registerCount) {
|
if(m_stableEndIndex >= m_startAddress && m_stableEndIndex < m_startAddress + m_registerCount) {
|
||||||
int relativeEndIndex = m_stableEndIndex - m_startAddress;
|
int relativeEndIndex = m_stableEndIndex - m_startAddress;
|
||||||
m_stableEndLine->append(relativeEndIndex, yMin);
|
m_stableEndLine->append(relativeEndIndex, yMin);
|
||||||
m_stableEndLine->append(relativeEndIndex, yMax);
|
m_stableEndLine->append(relativeEndIndex, yMax);
|
||||||
@ -288,111 +251,83 @@ void AdcGraphDialog::updateGraphRange()
|
|||||||
// Обновляем диапазон оси X
|
// Обновляем диапазон оси X
|
||||||
m_axisX->setRange(0, m_registerCount);
|
m_axisX->setRange(0, m_registerCount);
|
||||||
m_axisX->setTitleText(QString("Отсчеты АЦП (%1-%2)").arg(m_startAddress).arg(m_startAddress + m_registerCount - 1));
|
m_axisX->setTitleText(QString("Отсчеты АЦП (%1-%2)").arg(m_startAddress).arg(m_startAddress + m_registerCount - 1));
|
||||||
|
|
||||||
// Сбрасываем ось Y к разумному диапазону по умолчанию
|
// Сбрасываем ось Y к разумному диапазону по умолчанию
|
||||||
m_axisY->setRange(-1.2, 1.2);
|
m_axisY->setRange(-1.2, 1.2);
|
||||||
|
|
||||||
// Обновляем линии стабильного участка с учетом нового диапазона
|
// Обновляем линии стабильного участка с учетом нового диапазона
|
||||||
updateStableLines();
|
updateStableLines();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdcGraphDialog::readAdcDataAndIndices()
|
void AdcGraphDialog::readAdcDataAndIndices()
|
||||||
{
|
{
|
||||||
if (!m_modbusDevice || m_boardAddress == -1) return;
|
if(!m_modbusDevice || m_boardAddress == -1)
|
||||||
|
return;
|
||||||
// Создаем один запрос для данных АЦП + индексов стабильности
|
// Создаем один запрос для данных АЦП + индексов стабильности
|
||||||
// Адреса: данные АЦП (571+), индексы (557-558)
|
// Адреса: данные АЦП (571+), индексы (557-558)
|
||||||
int start = m_startAddress + REG_ADC_BUFFER_START;
|
int start = m_startAddress + REG_ADC_BUFFER_START;
|
||||||
int count = m_registerCount;
|
int count = m_registerCount;
|
||||||
|
|
||||||
// Читаем индексы стабильности (557-558) и данные АЦП одним запросом
|
// Читаем индексы стабильности (557-558) и данные АЦП одним запросом
|
||||||
QModbusDataUnit unit(QModbusDataUnit::InputRegisters, REG_STABLE_START,
|
QModbusDataUnit unit(QModbusDataUnit::InputRegisters, REG_STABLE_START,
|
||||||
count + (start - REG_STABLE_START));
|
count + (start - REG_STABLE_START));
|
||||||
|
if(auto *reply = m_modbusDevice->sendReadRequest(unit, m_boardAddress)) {
|
||||||
//qDebug() << "Reading combined data from address" << REG_STABLE_START << "count:" << unit.valueCount();
|
if(!reply->isFinished())
|
||||||
|
|
||||||
if (auto *reply = m_modbusDevice->sendReadRequest(unit, m_boardAddress)) {
|
|
||||||
if (!reply->isFinished()) {
|
|
||||||
connect(reply, &QModbusReply::finished, this, &AdcGraphDialog::onCombinedDataReady);
|
connect(reply, &QModbusReply::finished, this, &AdcGraphDialog::onCombinedDataReady);
|
||||||
} else {
|
else
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
}
|
|
||||||
} else {
|
|
||||||
//qDebug() << "Failed to send combined data read request";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AdcGraphDialog::onCombinedDataReady()
|
void AdcGraphDialog::onCombinedDataReady()
|
||||||
{
|
{
|
||||||
auto *reply = qobject_cast<QModbusReply*>(sender());
|
auto *reply = qobject_cast<QModbusReply*>(sender());
|
||||||
if (!reply) return;
|
if(!reply)
|
||||||
|
return;
|
||||||
if((m_adcZero == 0) || (m_adcOneVolt == 0))
|
if((m_adcZero == 0) || (m_adcOneVolt == 0)) {
|
||||||
{
|
|
||||||
readCalibrationValues();
|
readCalibrationValues();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if(reply->error() == QModbusDevice::NoError) {
|
||||||
if (reply->error() == QModbusDevice::NoError) {
|
|
||||||
const QModbusDataUnit result = reply->result();
|
const QModbusDataUnit result = reply->result();
|
||||||
|
|
||||||
// Обрабатываем индексы стабильности (первые 2 регистра)
|
// Обрабатываем индексы стабильности (первые 2 регистра)
|
||||||
if (result.valueCount() >= 2) {
|
if(result.valueCount() >= 2) {
|
||||||
m_stableStartIndex = result.value(0);
|
m_stableStartIndex = result.value(0);
|
||||||
m_stableEndIndex = result.value(1);
|
m_stableEndIndex = result.value(1);
|
||||||
//qDebug() << "Stable indices - Start:" << m_stableStartIndex << "End:" << m_stableEndIndex;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Обрабатываем данные АЦП (остальные регистры)
|
// Обрабатываем данные АЦП (остальные регистры)
|
||||||
int adcDataStartIndex = (m_startAddress + REG_ADC_BUFFER_START) - REG_STABLE_START;
|
uint adcDataStartIndex = (m_startAddress + REG_ADC_BUFFER_START) - REG_STABLE_START;
|
||||||
|
|
||||||
// Очищаем предыдущие данные
|
// Очищаем предыдущие данные
|
||||||
m_series->clear();
|
m_series->clear();
|
||||||
|
|
||||||
// Добавляем новые точки и определяем диапазон
|
// Добавляем новые точки и определяем диапазон
|
||||||
double minVoltage = 1000, maxVoltage = -1000;
|
double minVoltage = 1000, maxVoltage = -1000;
|
||||||
for (int i = 0; i < m_registerCount; ++i) {
|
for(int i = 0; i < m_registerCount; ++i) {
|
||||||
if (adcDataStartIndex + i < result.valueCount()) {
|
if(adcDataStartIndex + i < result.valueCount()) {
|
||||||
double voltage = convertAdcToVoltage(result.value(adcDataStartIndex + i));
|
double voltage = convertAdcToVoltage(result.value(adcDataStartIndex + i));
|
||||||
m_series->append(i, voltage);
|
m_series->append(i, voltage);
|
||||||
|
|
||||||
// Обновляем мин/макс для автоматического масштабирования
|
// Обновляем мин/макс для автоматического масштабирования
|
||||||
if (voltage < minVoltage) minVoltage = voltage;
|
if(voltage < minVoltage)
|
||||||
if (voltage > maxVoltage) maxVoltage = voltage;
|
minVoltage = voltage;
|
||||||
|
if(voltage > maxVoltage)
|
||||||
|
maxVoltage = voltage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Обновляем график и статистику
|
// Обновляем график и статистику
|
||||||
updateYAxisRange(minVoltage, maxVoltage);
|
updateYAxisRange(minVoltage, maxVoltage);
|
||||||
updateStableLines();
|
updateStableLines();
|
||||||
updateStatistics();
|
updateStatistics();
|
||||||
|
|
||||||
} else {
|
|
||||||
// qDebug() << "Error reading combined data:" << reply->errorString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AdcGraphDialog::readAdcBuffer()
|
void AdcGraphDialog::readAdcBuffer()
|
||||||
{
|
{
|
||||||
if (!m_modbusDevice || m_boardAddress == -1) return;
|
if(!m_modbusDevice || m_boardAddress == -1)
|
||||||
|
return;
|
||||||
// Читаем выбранный диапазон буфера АЦП
|
// Читаем выбранный диапазон буфера АЦП
|
||||||
QModbusDataUnit unit(QModbusDataUnit::InputRegisters, m_startAddress+REG_ADC_BUFFER_START, m_registerCount);
|
QModbusDataUnit unit(QModbusDataUnit::InputRegisters, m_startAddress+REG_ADC_BUFFER_START, m_registerCount);
|
||||||
|
if(auto *reply = m_modbusDevice->sendReadRequest(unit, m_boardAddress)) {
|
||||||
// qDebug() << "Reading ADC buffer from address" << m_startAddress << "count:" << m_registerCount;
|
if(!reply->isFinished())
|
||||||
|
|
||||||
if (auto *reply = m_modbusDevice->sendReadRequest(unit, m_boardAddress)) {
|
|
||||||
if (!reply->isFinished()) {
|
|
||||||
connect(reply, &QModbusReply::finished, this, &AdcGraphDialog::onReadReady);
|
connect(reply, &QModbusReply::finished, this, &AdcGraphDialog::onReadReady);
|
||||||
} else {
|
else
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// qDebug() << "Failed to send ADC buffer read request";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -401,34 +336,25 @@ void AdcGraphDialog::startGraph(int boardId, int teNumber)
|
|||||||
m_boardId = boardId;
|
m_boardId = boardId;
|
||||||
m_teNumber = teNumber;
|
m_teNumber = teNumber;
|
||||||
m_boardAddress = boardId + 1;
|
m_boardAddress = boardId + 1;
|
||||||
|
|
||||||
// Устанавливаем начальное значение в спинбокс
|
// Устанавливаем начальное значение в спинбокс
|
||||||
ui->teNumberSpinBox->setValue(teNumber);
|
ui->teNumberSpinBox->setValue(teNumber);
|
||||||
|
|
||||||
setWindowTitle(QString("График АЦП - Плата %1, ТЭ %2 (адр %3-%4)")
|
setWindowTitle(QString("График АЦП - Плата %1, ТЭ %2 (адр %3-%4)")
|
||||||
.arg(boardId + 1)
|
.arg(boardId + 1)
|
||||||
.arg(teNumber)
|
.arg(teNumber)
|
||||||
.arg(m_startAddress)
|
.arg(m_startAddress)
|
||||||
.arg(m_startAddress + m_registerCount - 1));
|
.arg(m_startAddress + m_registerCount - 1));
|
||||||
|
|
||||||
// Очищаем предыдущие данные
|
// Очищаем предыдущие данные
|
||||||
m_series->clear();
|
m_series->clear();
|
||||||
m_stableStartLine->clear();
|
m_stableStartLine->clear();
|
||||||
m_stableEndLine->clear();
|
m_stableEndLine->clear();
|
||||||
|
|
||||||
// Обновляем диапазон графика
|
// Обновляем диапазон графика
|
||||||
updateGraphRange();
|
updateGraphRange();
|
||||||
|
|
||||||
readCalibrationValues();
|
readCalibrationValues();
|
||||||
|
|
||||||
// Записываем начальный номер ТЭ
|
// Записываем начальный номер ТЭ
|
||||||
setTENumber(m_boardAddress, teNumber);
|
setTENumber(m_boardAddress, teNumber);
|
||||||
|
|
||||||
m_updateTimer->start(m_timeout);
|
m_updateTimer->start(m_timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void AdcGraphDialog::setTimeout(int timeout)
|
void AdcGraphDialog::setTimeout(int timeout)
|
||||||
{
|
{
|
||||||
m_timeout = timeout;
|
m_timeout = timeout;
|
||||||
@ -439,17 +365,15 @@ void AdcGraphDialog::stopGraph()
|
|||||||
m_updateTimer->stop();
|
m_updateTimer->stop();
|
||||||
m_boardId = -1;
|
m_boardId = -1;
|
||||||
m_boardAddress = -1;
|
m_boardAddress = -1;
|
||||||
|
|
||||||
// Отменяем все pending запросы Modbus
|
// Отменяем все pending запросы Modbus
|
||||||
if (m_modbusDevice) {
|
if(m_modbusDevice)
|
||||||
m_modbusDevice->disconnect(this); // Отключаем все сигналы
|
m_modbusDevice->disconnect(this); // Отключаем все сигналы
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdcGraphDialog::onUpdateTimer()
|
void AdcGraphDialog::onUpdateTimer()
|
||||||
{
|
{
|
||||||
if (m_boardAddress == -1) return;
|
if(m_boardAddress == -1)
|
||||||
|
return;
|
||||||
// Читаем и буфер АЦП, и индексы стабильности каждый период
|
// Читаем и буфер АЦП, и индексы стабильности каждый период
|
||||||
readAdcDataAndIndices();
|
readAdcDataAndIndices();
|
||||||
}
|
}
|
||||||
@ -457,54 +381,46 @@ void AdcGraphDialog::onUpdateTimer()
|
|||||||
void AdcGraphDialog::onReadReady()
|
void AdcGraphDialog::onReadReady()
|
||||||
{
|
{
|
||||||
auto *reply = qobject_cast<QModbusReply*>(sender());
|
auto *reply = qobject_cast<QModbusReply*>(sender());
|
||||||
if (!reply) return;
|
if(!reply)
|
||||||
|
return;
|
||||||
if (reply->error() == QModbusDevice::NoError) {
|
if(reply->error() == QModbusDevice::NoError) {
|
||||||
const QModbusDataUnit result = reply->result();
|
const QModbusDataUnit result = reply->result();
|
||||||
|
|
||||||
// Очищаем предыдущие данные
|
// Очищаем предыдущие данные
|
||||||
m_series->clear();
|
m_series->clear();
|
||||||
|
|
||||||
// Добавляем новые точки и определяем диапазон
|
// Добавляем новые точки и определяем диапазон
|
||||||
double minVoltage = 1000, maxVoltage = -1000;
|
double minVoltage = 1000, maxVoltage = -1000;
|
||||||
for (int i = 0; i < result.valueCount(); ++i) {
|
for(uint i = 0; i < result.valueCount(); ++i) {
|
||||||
double voltage = convertAdcToVoltage(result.value(i));
|
double voltage = convertAdcToVoltage(result.value(i));
|
||||||
m_series->append(i, voltage);
|
m_series->append(i, voltage);
|
||||||
|
|
||||||
// Обновляем мин/макс для автоматического масштабирования
|
// Обновляем мин/макс для автоматического масштабирования
|
||||||
if (voltage < minVoltage) minVoltage = voltage;
|
if(voltage < minVoltage)
|
||||||
if (voltage > maxVoltage) maxVoltage = voltage;
|
minVoltage = voltage;
|
||||||
|
if(voltage > maxVoltage)
|
||||||
|
maxVoltage = voltage;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Автоматически настраиваем диапазон оси Y
|
// Автоматически настраиваем диапазон оси Y
|
||||||
updateYAxisRange(minVoltage, maxVoltage);
|
updateYAxisRange(minVoltage, maxVoltage);
|
||||||
|
|
||||||
// Обновляем линии стабильного участка
|
// Обновляем линии стабильного участка
|
||||||
updateStableLines();
|
updateStableLines();
|
||||||
|
|
||||||
// Обновляем статистику
|
// Обновляем статистику
|
||||||
if (m_series->count() > 0) {
|
if(m_series->count() > 0) {
|
||||||
double min = 1000, max = -1000, sum = 0;
|
double min = 1000, max = -1000, sum = 0;
|
||||||
for (const QPointF &point : m_series->points()) {
|
for(const QPointF &point : m_series->points()) {
|
||||||
double y = point.y();
|
double y = point.y();
|
||||||
if (y < min) min = y;
|
if(y < min)
|
||||||
if (y > max) max = y;
|
min = y;
|
||||||
|
if(y > max)
|
||||||
|
max = y;
|
||||||
sum += y;
|
sum += y;
|
||||||
}
|
}
|
||||||
double avg = sum / m_series->count();
|
double avg = sum / m_series->count();
|
||||||
|
|
||||||
ui->minLabel->setText(QString::number(min, 'f', 3) + " В");
|
ui->minLabel->setText(QString::number(min, 'f', 3) + " В");
|
||||||
ui->maxLabel->setText(QString::number(max, 'f', 3) + " В");
|
ui->maxLabel->setText(QString::number(max, 'f', 3) + " В");
|
||||||
ui->avgLabel->setText(QString::number(avg, 'f', 3) + " В");
|
ui->avgLabel->setText(QString::number(avg, 'f', 3) + " В");
|
||||||
|
|
||||||
// Обновляем информацию о стабильном участке
|
// Обновляем информацию о стабильном участке
|
||||||
updateStatisticsWithStableInfo();
|
updateStatisticsWithStableInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
|
||||||
// qDebug() << "Error reading ADC buffer:" << reply->errorString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -513,65 +429,38 @@ void AdcGraphDialog::updateYAxisRange(double minVoltage, double maxVoltage)
|
|||||||
// Добавляем запас 10% к диапазону
|
// Добавляем запас 10% к диапазону
|
||||||
double range = maxVoltage - minVoltage;
|
double range = maxVoltage - minVoltage;
|
||||||
double margin = range * 0.1;
|
double margin = range * 0.1;
|
||||||
|
|
||||||
double yMin = minVoltage - margin;
|
double yMin = minVoltage - margin;
|
||||||
double yMax = maxVoltage + margin;
|
double yMax = maxVoltage + margin;
|
||||||
|
|
||||||
// Если диапазон слишком маленький или слишком большой, устанавливаем разумные пределы
|
// Если диапазон слишком маленький или слишком большой, устанавливаем разумные пределы
|
||||||
// if ((range < 0.1) || ((maxVoltage > 0.5) && (minVoltage < -0.5)))
|
yMin = -1.5;
|
||||||
// {
|
yMax = 1.5;
|
||||||
// yMin = -1.5;
|
|
||||||
// yMax = 1.5;
|
|
||||||
// }
|
|
||||||
// else if(maxVoltage > 0.5) {
|
|
||||||
// yMin = -0.1;
|
|
||||||
// yMax = 1.5;
|
|
||||||
// }
|
|
||||||
// else if(minVoltage < -0.5)
|
|
||||||
// {
|
|
||||||
// yMin = -1.5;
|
|
||||||
// yMax =0.1;
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
{
|
|
||||||
yMin = -1.5;
|
|
||||||
yMax = 1.5;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ограничиваем разумными пределами
|
// Ограничиваем разумными пределами
|
||||||
yMin = qMax(yMin, -5.0); // Не ниже -5В
|
yMin = qMax(yMin, -5.0); // Не ниже -5В
|
||||||
yMax = qMin(yMax, 5.0); // Не выше 5В
|
yMax = qMin(yMax, 5.0); // Не выше 5В
|
||||||
|
|
||||||
// Устанавливаем новый диапазон
|
// Устанавливаем новый диапазон
|
||||||
m_axisY->setRange(yMin, yMax);
|
m_axisY->setRange(yMin, yMax);
|
||||||
|
|
||||||
// Обновляем линии стабильного участка с новым диапазоном
|
// Обновляем линии стабильного участка с новым диапазоном
|
||||||
updateStableLines();
|
updateStableLines();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
double AdcGraphDialog::convertAdcToVoltage(quint16 adcValue)
|
double AdcGraphDialog::convertAdcToVoltage(quint16 adcValue)
|
||||||
{
|
{
|
||||||
if (m_adcOneVolt == m_adcZero) return 0;
|
if(m_adcOneVolt == m_adcZero)
|
||||||
|
return 0;
|
||||||
return (adcValue - m_adcZero) * 1.1 / (m_adcOneVolt - m_adcZero);
|
return (adcValue - m_adcZero) * 1.1 / (m_adcOneVolt - m_adcZero);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AdcGraphDialog::on_registerCountChanged(int value)
|
void AdcGraphDialog::on_registerCountChanged(int value)
|
||||||
{
|
{
|
||||||
m_registerCount = value;
|
m_registerCount = value;
|
||||||
// qDebug() << "Register count changed to:" << value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdcGraphDialog::on_rangeApplyClicked()
|
void AdcGraphDialog::on_rangeApplyClicked()
|
||||||
{
|
{
|
||||||
// qDebug() << "Applying new range - Start:" << m_startAddress << "Count:" << m_registerCount;
|
|
||||||
updateGraphRange();
|
updateGraphRange();
|
||||||
|
|
||||||
// Немедленно обновляем данные
|
// Немедленно обновляем данные
|
||||||
if (m_boardAddress != -1) {
|
if(m_boardAddress != -1)
|
||||||
readAdcBuffer();
|
readAdcBuffer();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdcGraphDialog::on_closeBtn_clicked()
|
void AdcGraphDialog::on_closeBtn_clicked()
|
||||||
|
|||||||
@ -19,21 +19,17 @@ class AdcGraphDialog;
|
|||||||
class AdcGraphDialog : public QDialog
|
class AdcGraphDialog : public QDialog
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit AdcGraphDialog(QModbusClient *modbusDevice, QWidget *parent = nullptr);
|
explicit AdcGraphDialog(QModbusClient *modbusDevice, QWidget *parent = nullptr);
|
||||||
~AdcGraphDialog();
|
~AdcGraphDialog();
|
||||||
|
|
||||||
void setTENumber(int boardID, int teNumber);
|
void setTENumber(int boardID, int teNumber);
|
||||||
void setModbusDevice(QModbusClient *device);
|
void setModbusDevice(QModbusClient *device);
|
||||||
void startGraph(int boardId, int teNumber);
|
void startGraph(int boardId, int teNumber);
|
||||||
void stopGraph();
|
void stopGraph();
|
||||||
void setTimeout(int timeout);
|
void setTimeout(int timeout);
|
||||||
void readyClose();
|
void readyClose();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void dialogClosed();
|
void dialogClosed();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void closeEvent(QCloseEvent *event) override {
|
void closeEvent(QCloseEvent *event) override {
|
||||||
stopGraph();
|
stopGraph();
|
||||||
@ -41,7 +37,6 @@ protected:
|
|||||||
emit dialogClosed();
|
emit dialogClosed();
|
||||||
QDialog::closeEvent(event);
|
QDialog::closeEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_teNumberChanged(int value);
|
void on_teNumberChanged(int value);
|
||||||
void onUpdateTimer();
|
void onUpdateTimer();
|
||||||
@ -50,7 +45,6 @@ private slots:
|
|||||||
void on_closeBtn_clicked();
|
void on_closeBtn_clicked();
|
||||||
void on_registerCountChanged(int value);
|
void on_registerCountChanged(int value);
|
||||||
void on_rangeApplyClicked();
|
void on_rangeApplyClicked();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::AdcGraphDialog *ui;
|
Ui::AdcGraphDialog *ui;
|
||||||
QModbusClient *m_modbusDevice;
|
QModbusClient *m_modbusDevice;
|
||||||
@ -59,27 +53,22 @@ private:
|
|||||||
int m_boardAddress;
|
int m_boardAddress;
|
||||||
int m_teNumber;
|
int m_teNumber;
|
||||||
int m_timeout;
|
int m_timeout;
|
||||||
|
|
||||||
// Калибровочные значения
|
// Калибровочные значения
|
||||||
double m_adcZero;
|
double m_adcZero;
|
||||||
double m_adcOneVolt;
|
double m_adcOneVolt;
|
||||||
|
|
||||||
// Для отображения стабильного участка
|
// Для отображения стабильного участка
|
||||||
QLineSeries *m_stableStartLine;
|
QLineSeries *m_stableStartLine;
|
||||||
QLineSeries *m_stableEndLine;
|
QLineSeries *m_stableEndLine;
|
||||||
int m_stableStartIndex;
|
int m_stableStartIndex;
|
||||||
int m_stableEndIndex;
|
int m_stableEndIndex;
|
||||||
|
|
||||||
// Данные графика
|
// Данные графика
|
||||||
QLineSeries *m_series;
|
QLineSeries *m_series;
|
||||||
QValueAxis *m_axisX;
|
QValueAxis *m_axisX;
|
||||||
QValueAxis *m_axisY;
|
QValueAxis *m_axisY;
|
||||||
QChart *m_chart; // Добавить указатель на chart
|
QChart *m_chart; // Добавить указатель на chart
|
||||||
|
|
||||||
// Управление диапазоном регистров
|
// Управление диапазоном регистров
|
||||||
int m_startAddress;
|
int m_startAddress;
|
||||||
int m_registerCount;
|
int m_registerCount;
|
||||||
|
|
||||||
void updateStatistics();
|
void updateStatistics();
|
||||||
void readAdcDataAndIndices();
|
void readAdcDataAndIndices();
|
||||||
void onCombinedDataReady();
|
void onCombinedDataReady();
|
||||||
|
|||||||
@ -17,23 +17,19 @@ DebugTerminalDialog::DebugTerminalDialog(QWidget *parent) :
|
|||||||
boards[0].error5V = ui->discErr5TestChkBox_1;
|
boards[0].error5V = ui->discErr5TestChkBox_1;
|
||||||
boards[0].error5VSCI = ui->discErr5VsciTestChkBox_1;
|
boards[0].error5VSCI = ui->discErr5VsciTestChkBox_1;
|
||||||
boards[0].error5VA = ui->discErr5VATestChkBox_1;
|
boards[0].error5VA = ui->discErr5VATestChkBox_1;
|
||||||
|
|
||||||
boards[1].error24V = ui->discErr24TestChkBox_2;
|
boards[1].error24V = ui->discErr24TestChkBox_2;
|
||||||
boards[1].error5V = ui->discErr5TestChkBox_2;
|
boards[1].error5V = ui->discErr5TestChkBox_2;
|
||||||
boards[1].error5VSCI = ui->discErr5VsciTestChkBox_2;
|
boards[1].error5VSCI = ui->discErr5VsciTestChkBox_2;
|
||||||
boards[1].error5VA = ui->discErr5VATestChkBox_2;
|
boards[1].error5VA = ui->discErr5VATestChkBox_2;
|
||||||
|
|
||||||
boards[2].error24V = ui->discErr24TestChkBox_3;
|
boards[2].error24V = ui->discErr24TestChkBox_3;
|
||||||
boards[2].error5V = ui->discErr5TestChkBox_3;
|
boards[2].error5V = ui->discErr5TestChkBox_3;
|
||||||
boards[2].error5VSCI = ui->discErr5VsciTestChkBox_3;
|
boards[2].error5VSCI = ui->discErr5VsciTestChkBox_3;
|
||||||
boards[2].error5VA = ui->discErr5VATestChkBox_3;
|
boards[2].error5VA = ui->discErr5VATestChkBox_3;
|
||||||
|
|
||||||
boards[3].error24V = ui->discErr24TestChkBox_4;
|
boards[3].error24V = ui->discErr24TestChkBox_4;
|
||||||
boards[3].error5V = ui->discErr5TestChkBox_4;
|
boards[3].error5V = ui->discErr5TestChkBox_4;
|
||||||
boards[3].error5VSCI = ui->discErr5VsciTestChkBox_4;
|
boards[3].error5VSCI = ui->discErr5VsciTestChkBox_4;
|
||||||
boards[3].error5VA = ui->discErr5VATestChkBox_4;
|
boards[3].error5VA = ui->discErr5VATestChkBox_4;
|
||||||
initializeConnections();
|
initializeConnections();
|
||||||
|
|
||||||
// Создаем AdcGraphDialog с nullptr
|
// Создаем AdcGraphDialog с nullptr
|
||||||
m_adcGraphDialog = new AdcGraphDialog(nullptr, this);
|
m_adcGraphDialog = new AdcGraphDialog(nullptr, this);
|
||||||
}
|
}
|
||||||
@ -50,9 +46,8 @@ void DebugTerminalDialog::setMainTerm(M3KTE* term)
|
|||||||
void DebugTerminalDialog::setModbusDevice(QModbusClient *device)
|
void DebugTerminalDialog::setModbusDevice(QModbusClient *device)
|
||||||
{
|
{
|
||||||
m_modbusDevice = device;
|
m_modbusDevice = device;
|
||||||
if (m_adcGraphDialog && device) {
|
if(m_adcGraphDialog && device)
|
||||||
m_adcGraphDialog->setModbusDevice(device);
|
m_adcGraphDialog->setModbusDevice(device);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DebugTerminalDialog::setDebugTerminalCoil(int enable)
|
void DebugTerminalDialog::setDebugTerminalCoil(int enable)
|
||||||
@ -67,9 +62,7 @@ void DebugTerminalDialog::showEvent(QShowEvent *event)
|
|||||||
{
|
{
|
||||||
QDialog::showEvent(event);
|
QDialog::showEvent(event);
|
||||||
// При открытии окна записываем в коил 555 значение "1"
|
// При открытии окна записываем в коил 555 значение "1"
|
||||||
|
|
||||||
resetAll();
|
resetAll();
|
||||||
|
|
||||||
setDebugTerminalCoil(1);
|
setDebugTerminalCoil(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,76 +73,7 @@ void DebugTerminalDialog::closeEvent(QCloseEvent *event)
|
|||||||
QDialog::closeEvent(event);
|
QDialog::closeEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DebugTerminalDialog::initializeConnections()
|
void DebugTerminalDialog::initializeConnections(){}
|
||||||
{
|
|
||||||
// // Подключаем кнопки OK и RestoreDefaults
|
|
||||||
// connect(ui->buttonBox, &QDialogButtonBox::clicked, this, &DebugTerminalDialog::on_buttonBox_clicked);
|
|
||||||
|
|
||||||
// // Подключаем все чекбоксы для платы 1
|
|
||||||
// connect(ui->continiusCallChkBox_1, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_continiusCallChkBox_1_stateChanged);
|
|
||||||
// connect(ui->calibrateCallChkBox_1, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_calibrateCallChkBox_1_stateChanged);
|
|
||||||
// connect(ui->pollTECallChkBox_1, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_pollTECallChkBox_1_stateChanged);
|
|
||||||
// connect(ui->resetKeyCallChkBox_1, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_resetKeyCallChkBox_1_stateChanged);
|
|
||||||
// connect(ui->resetDefaultCallChkBox_1, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_resetDefaultCallChkBox_1_stateChanged);
|
|
||||||
// connect(ui->getHardfaultCallChkBox_1, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_getHardfaultCallChkBox_1_stateChanged);
|
|
||||||
|
|
||||||
|
|
||||||
// connect(ui->enableLedTestChkBox_1, &QCheckBox::stateChanged, this, &DebugTerminalDialog::enableLedTestChkBox_1_stateChanged);
|
|
||||||
|
|
||||||
// connect(ui->discWorkTestChkBox_1, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_discWorkTestChkBox_1_stateChanged);
|
|
||||||
// connect(ui->discWarnTestChkBox_1, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_discWarnTestChkBox_1_stateChanged);
|
|
||||||
// connect(ui->discErrTestChkBox_1, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_discErrTestChkBox_1_stateChanged);
|
|
||||||
|
|
||||||
|
|
||||||
// connect(ui->discErr24TestChkBox_1, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_discErr24TestChkBox_1_stateChanged);
|
|
||||||
// ui->discErr24TestChkBox_1->setAttribute(Qt::WA_TransparentForMouseEvents, true);
|
|
||||||
// connect(ui->discErr5TestChkBox_1, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_discErr5TestChkBox_1_stateChanged);
|
|
||||||
// ui->discErr5TestChkBox_1->setAttribute(Qt::WA_TransparentForMouseEvents, true);
|
|
||||||
// connect(ui->discErr5VsciTestChkBox_1, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_discErr5VsciTestChkBox_1_stateChanged);
|
|
||||||
// ui->discErr5VsciTestChkBox_1->setAttribute(Qt::WA_TransparentForMouseEvents, true);
|
|
||||||
// connect(ui->discErr5VATestChkBox_1, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_discErr5VATestChkBox_1_stateChanged);
|
|
||||||
// ui->discErr5VATestChkBox_1->setAttribute(Qt::WA_TransparentForMouseEvents, true);
|
|
||||||
|
|
||||||
// connect(ui->ledWorkTestChkBox_1, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_ledWorkTestChkBox_1_stateChanged);
|
|
||||||
// connect(ui->ledWarnTestChkBox_1, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_ledWarnTestChkBox_1_stateChanged);
|
|
||||||
// connect(ui->ledErrTestChkBox_1, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_ledErrTestChkBox_1_stateChanged);
|
|
||||||
// connect(ui->ledConnectTestChkBox_1, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_ledConnectTestChkBox_1_stateChanged);
|
|
||||||
// connect(ui->ledVH1TestChkBox_1, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_ledVH1TestChkBox_1_stateChanged);
|
|
||||||
// connect(ui->ledVH2TestChkBox_1, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_ledVH2TestChkBox_1_stateChanged);
|
|
||||||
// connect(ui->ledVH3TestChkBox_1, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_ledVH3TestChkBox_1_stateChanged);
|
|
||||||
|
|
||||||
// // Подключаем все чекбоксы для платы 2
|
|
||||||
// connect(ui->continiusCallChkBox_2, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_continiusCallChkBox_2_stateChanged);
|
|
||||||
// connect(ui->calibrateCallChkBox_2, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_calibrateCallChkBox_2_stateChanged);
|
|
||||||
// connect(ui->pollTECallChkBox_2, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_pollTECallChkBox_2_stateChanged);
|
|
||||||
// connect(ui->resetKeyCallChkBox_2, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_resetKeyCallChkBox_2_stateChanged);
|
|
||||||
// connect(ui->resetDefaultCallChkBox_2, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_resetDefaultCallChkBox_2_stateChanged);
|
|
||||||
// connect(ui->getHardfaultCallChkBox_2, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_getHardfaultCallChkBox_2_stateChanged);
|
|
||||||
|
|
||||||
// connect(ui->enableLedTestChkBox_2, &QCheckBox::stateChanged, this, &DebugTerminalDialog::enableLedTestChkBox_2_stateChanged);
|
|
||||||
|
|
||||||
// connect(ui->discWorkTestChkBox_2, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_discWorkTestChkBox_2_stateChanged);
|
|
||||||
// connect(ui->discWarnTestChkBox_2, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_discWarnTestChkBox_2_stateChanged);
|
|
||||||
// connect(ui->discErrTestChkBox_2, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_discErrTestChkBox_2_stateChanged);
|
|
||||||
|
|
||||||
// connect(ui->discErr24TestChkBox_2, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_discErr24TestChkBox_2_stateChanged);
|
|
||||||
// ui->discErr24TestChkBox_2->setAttribute(Qt::WA_TransparentForMouseEvents, true);
|
|
||||||
// connect(ui->discErr5TestChkBox_2, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_discErr5TestChkBox_2_stateChanged);
|
|
||||||
// ui->discErr5TestChkBox_2->setAttribute(Qt::WA_TransparentForMouseEvents, true);
|
|
||||||
// connect(ui->discErr5VsciTestChkBox_2, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_discErr5VsciTestChkBox_2_stateChanged);
|
|
||||||
// ui->discErr5VsciTestChkBox_2->setAttribute(Qt::WA_TransparentForMouseEvents, true);
|
|
||||||
// connect(ui->discErr5VATestChkBox_2, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_discErr5VATestChkBox_2_stateChanged);
|
|
||||||
// ui->discErr5VATestChkBox_2->setAttribute(Qt::WA_TransparentForMouseEvents, true);
|
|
||||||
|
|
||||||
// connect(ui->ledWorkTestChkBox_2, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_ledWorkTestChkBox_2_stateChanged);
|
|
||||||
// connect(ui->ledWarnTestChkBox_2, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_ledWarnTestChkBox_2_stateChanged);
|
|
||||||
// connect(ui->ledErrTestChkBox_2, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_ledErrTestChkBox_2_stateChanged);
|
|
||||||
// connect(ui->ledConnectTestChkBox_2, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_ledConnectTestChkBox_2_stateChanged);
|
|
||||||
// connect(ui->ledVH1TestChkBox_2, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_ledVH1TestChkBox_2_stateChanged);
|
|
||||||
// connect(ui->ledVH2TestChkBox_2, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_ledVH2TestChkBox_2_stateChanged);
|
|
||||||
// connect(ui->ledVH3TestChkBox_2, &QCheckBox::stateChanged, this, &DebugTerminalDialog::on_ledVH3TestChkBox_2_stateChanged);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void DebugTerminalDialog::updateConnectionStatus(int boardID, bool connected)
|
void DebugTerminalDialog::updateConnectionStatus(int boardID, bool connected)
|
||||||
{
|
{
|
||||||
@ -568,16 +492,14 @@ void DebugTerminalDialog::on_ledVH3TestChkBox_4_stateChanged(int state)
|
|||||||
void DebugTerminalDialog::openAdc(int boardID, int teNumber)
|
void DebugTerminalDialog::openAdc(int boardID, int teNumber)
|
||||||
{
|
{
|
||||||
// Удаляем старый диалог и создаем новый
|
// Удаляем старый диалог и создаем новый
|
||||||
if (m_adcGraphDialog) {
|
if(m_adcGraphDialog) {
|
||||||
m_adcGraphDialog->deleteLater();
|
m_adcGraphDialog->deleteLater();
|
||||||
m_adcGraphDialog = nullptr;
|
m_adcGraphDialog = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_adcGraphDialog = new AdcGraphDialog(m_modbusDevice, this);
|
m_adcGraphDialog = new AdcGraphDialog(m_modbusDevice, this);
|
||||||
connect(m_adcGraphDialog, &AdcGraphDialog::dialogClosed, this, [this]() {
|
connect(m_adcGraphDialog, &AdcGraphDialog::dialogClosed, this, [this]() {
|
||||||
setDebugTerminalCoil(0);
|
setDebugTerminalCoil(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
setGraphUpdateInterval(1000);
|
setGraphUpdateInterval(1000);
|
||||||
m_adcGraphDialog->startGraph(boardID, teNumber);
|
m_adcGraphDialog->startGraph(boardID, teNumber);
|
||||||
m_adcGraphDialog->show();
|
m_adcGraphDialog->show();
|
||||||
@ -587,9 +509,8 @@ void DebugTerminalDialog::openAdc(int boardID, int teNumber)
|
|||||||
|
|
||||||
void DebugTerminalDialog::setGraphUpdateInterval(int milliseconds)
|
void DebugTerminalDialog::setGraphUpdateInterval(int milliseconds)
|
||||||
{
|
{
|
||||||
if (m_adcGraphDialog) {
|
if(m_adcGraphDialog)
|
||||||
m_adcGraphDialog->setTimeout(milliseconds);
|
m_adcGraphDialog->setTimeout(milliseconds);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DebugTerminalDialog::writeCoil(int boardID, int coil, int value)
|
void DebugTerminalDialog::writeCoil(int boardID, int coil, int value)
|
||||||
@ -624,22 +545,20 @@ void DebugTerminalDialog::setBoardActive(int boardID, bool active)
|
|||||||
case 3: boardGroup = ui->DbgPlate_4; break; // Плата 4
|
case 3: boardGroup = ui->DbgPlate_4; break; // Плата 4
|
||||||
default: return;
|
default: return;
|
||||||
}
|
}
|
||||||
if (boardGroup) {
|
if(boardGroup) {
|
||||||
boardGroup->setEnabled(active);
|
boardGroup->setEnabled(active);
|
||||||
// Можно добавить визуальное отличие неактивных плат
|
// Можно добавить визуальное отличие неактивных плат
|
||||||
if (!active) {
|
if(!active)
|
||||||
boardGroup->setStyleSheet("QGroupBox { color: gray; }");
|
boardGroup->setStyleSheet("QGroupBox { color: gray; }");
|
||||||
} else {
|
else
|
||||||
boardGroup->setStyleSheet(""); // Сброс стиля
|
boardGroup->setStyleSheet(""); // Сброс стиля
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DebugTerminalDialog::updateBoardStates(bool activeBoards[4])
|
void DebugTerminalDialog::updateBoardStates(bool activeBoards[4])
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 4; i++) {
|
for(int i = 0; i < 4; i++)
|
||||||
setBoardActive(i, activeBoards[i]);
|
setBoardActive(i, activeBoards[i]);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DebugTerminalDialog::resetAll()
|
void DebugTerminalDialog::resetAll()
|
||||||
@ -651,17 +570,14 @@ void DebugTerminalDialog::resetAll()
|
|||||||
ui->resetKeyCallChkBox_1->setChecked(false);
|
ui->resetKeyCallChkBox_1->setChecked(false);
|
||||||
ui->resetDefaultCallChkBox_1->setChecked(false);
|
ui->resetDefaultCallChkBox_1->setChecked(false);
|
||||||
ui->getHardfaultCallChkBox_1->setChecked(false);
|
ui->getHardfaultCallChkBox_1->setChecked(false);
|
||||||
|
|
||||||
ui->enableLedTestChkBox_1->setChecked(false);
|
ui->enableLedTestChkBox_1->setChecked(false);
|
||||||
ui->leds_1->setEnabled(false);
|
ui->leds_1->setEnabled(false);
|
||||||
ui->discs_1->setEnabled(false);
|
ui->discs_1->setEnabled(false);
|
||||||
|
|
||||||
ui->discWorkTestChkBox_1->setChecked(false);
|
ui->discWorkTestChkBox_1->setChecked(false);
|
||||||
// Сброс всех чекбоксов теста дискретных сигналов
|
// Сброс всех чекбоксов теста дискретных сигналов
|
||||||
ui->discWorkTestChkBox_1->setChecked(false);
|
ui->discWorkTestChkBox_1->setChecked(false);
|
||||||
ui->discWarnTestChkBox_1->setChecked(false);
|
ui->discWarnTestChkBox_1->setChecked(false);
|
||||||
ui->discErrTestChkBox_1->setChecked(false);
|
ui->discErrTestChkBox_1->setChecked(false);
|
||||||
|
|
||||||
// Сброс всех чекбоксов теста светодиодов
|
// Сброс всех чекбоксов теста светодиодов
|
||||||
ui->ledWorkTestChkBox_1->setChecked(false);
|
ui->ledWorkTestChkBox_1->setChecked(false);
|
||||||
ui->ledWarnTestChkBox_1->setChecked(false);
|
ui->ledWarnTestChkBox_1->setChecked(false);
|
||||||
@ -670,7 +586,6 @@ void DebugTerminalDialog::resetAll()
|
|||||||
ui->ledVH1TestChkBox_1->setChecked(false);
|
ui->ledVH1TestChkBox_1->setChecked(false);
|
||||||
ui->ledVH2TestChkBox_1->setChecked(false);
|
ui->ledVH2TestChkBox_1->setChecked(false);
|
||||||
ui->ledVH3TestChkBox_1->setChecked(false);
|
ui->ledVH3TestChkBox_1->setChecked(false);
|
||||||
|
|
||||||
// Сброс всех чекбоксов вызова функций
|
// Сброс всех чекбоксов вызова функций
|
||||||
ui->continiusCallChkBox_2->setChecked(false);
|
ui->continiusCallChkBox_2->setChecked(false);
|
||||||
ui->calibrateCallChkBox_2->setChecked(false);
|
ui->calibrateCallChkBox_2->setChecked(false);
|
||||||
@ -678,17 +593,14 @@ void DebugTerminalDialog::resetAll()
|
|||||||
ui->resetKeyCallChkBox_2->setChecked(false);
|
ui->resetKeyCallChkBox_2->setChecked(false);
|
||||||
ui->resetDefaultCallChkBox_2->setChecked(false);
|
ui->resetDefaultCallChkBox_2->setChecked(false);
|
||||||
ui->getHardfaultCallChkBox_2->setChecked(false);
|
ui->getHardfaultCallChkBox_2->setChecked(false);
|
||||||
|
|
||||||
ui->enableLedTestChkBox_2->setChecked(false);
|
ui->enableLedTestChkBox_2->setChecked(false);
|
||||||
ui->leds_2->setEnabled(false);
|
ui->leds_2->setEnabled(false);
|
||||||
ui->discs_2->setEnabled(false);
|
ui->discs_2->setEnabled(false);
|
||||||
|
|
||||||
ui->discWorkTestChkBox_2->setChecked(false);
|
ui->discWorkTestChkBox_2->setChecked(false);
|
||||||
// Сброс всех чекбоксов теста дискретных сигналов
|
// Сброс всех чекбоксов теста дискретных сигналов
|
||||||
ui->discWorkTestChkBox_2->setChecked(false);
|
ui->discWorkTestChkBox_2->setChecked(false);
|
||||||
ui->discWarnTestChkBox_2->setChecked(false);
|
ui->discWarnTestChkBox_2->setChecked(false);
|
||||||
ui->discErrTestChkBox_2->setChecked(false);
|
ui->discErrTestChkBox_2->setChecked(false);
|
||||||
|
|
||||||
// Сброс всех чекбоксов теста светодиодов
|
// Сброс всех чекбоксов теста светодиодов
|
||||||
ui->ledWorkTestChkBox_2->setChecked(false);
|
ui->ledWorkTestChkBox_2->setChecked(false);
|
||||||
ui->ledWarnTestChkBox_2->setChecked(false);
|
ui->ledWarnTestChkBox_2->setChecked(false);
|
||||||
@ -697,7 +609,6 @@ void DebugTerminalDialog::resetAll()
|
|||||||
ui->ledVH1TestChkBox_2->setChecked(false);
|
ui->ledVH1TestChkBox_2->setChecked(false);
|
||||||
ui->ledVH2TestChkBox_2->setChecked(false);
|
ui->ledVH2TestChkBox_2->setChecked(false);
|
||||||
ui->ledVH3TestChkBox_2->setChecked(false);
|
ui->ledVH3TestChkBox_2->setChecked(false);
|
||||||
|
|
||||||
// Сброс всех чекбоксов вызова функций
|
// Сброс всех чекбоксов вызова функций
|
||||||
ui->continiusCallChkBox_3->setChecked(false);
|
ui->continiusCallChkBox_3->setChecked(false);
|
||||||
ui->calibrateCallChkBox_3->setChecked(false);
|
ui->calibrateCallChkBox_3->setChecked(false);
|
||||||
@ -705,17 +616,14 @@ void DebugTerminalDialog::resetAll()
|
|||||||
ui->resetKeyCallChkBox_3->setChecked(false);
|
ui->resetKeyCallChkBox_3->setChecked(false);
|
||||||
ui->resetDefaultCallChkBox_3->setChecked(false);
|
ui->resetDefaultCallChkBox_3->setChecked(false);
|
||||||
ui->getHardfaultCallChkBox_3->setChecked(false);
|
ui->getHardfaultCallChkBox_3->setChecked(false);
|
||||||
|
|
||||||
ui->enableLedTestChkBox_3->setChecked(false);
|
ui->enableLedTestChkBox_3->setChecked(false);
|
||||||
ui->leds_3->setEnabled(false);
|
ui->leds_3->setEnabled(false);
|
||||||
ui->discs_3->setEnabled(false);
|
ui->discs_3->setEnabled(false);
|
||||||
|
|
||||||
ui->discWorkTestChkBox_3->setChecked(false);
|
ui->discWorkTestChkBox_3->setChecked(false);
|
||||||
// Сброс всех чекбоксов теста дискретных сигналов
|
// Сброс всех чекбоксов теста дискретных сигналов
|
||||||
ui->discWorkTestChkBox_3->setChecked(false);
|
ui->discWorkTestChkBox_3->setChecked(false);
|
||||||
ui->discWarnTestChkBox_3->setChecked(false);
|
ui->discWarnTestChkBox_3->setChecked(false);
|
||||||
ui->discErrTestChkBox_3->setChecked(false);
|
ui->discErrTestChkBox_3->setChecked(false);
|
||||||
|
|
||||||
// Сброс всех чекбоксов теста светодиодов
|
// Сброс всех чекбоксов теста светодиодов
|
||||||
ui->ledWorkTestChkBox_3->setChecked(false);
|
ui->ledWorkTestChkBox_3->setChecked(false);
|
||||||
ui->ledWarnTestChkBox_3->setChecked(false);
|
ui->ledWarnTestChkBox_3->setChecked(false);
|
||||||
@ -724,7 +632,6 @@ void DebugTerminalDialog::resetAll()
|
|||||||
ui->ledVH1TestChkBox_3->setChecked(false);
|
ui->ledVH1TestChkBox_3->setChecked(false);
|
||||||
ui->ledVH2TestChkBox_3->setChecked(false);
|
ui->ledVH2TestChkBox_3->setChecked(false);
|
||||||
ui->ledVH3TestChkBox_3->setChecked(false);
|
ui->ledVH3TestChkBox_3->setChecked(false);
|
||||||
|
|
||||||
// Сброс всех чекбоксов вызова функций
|
// Сброс всех чекбоксов вызова функций
|
||||||
ui->continiusCallChkBox_4->setChecked(false);
|
ui->continiusCallChkBox_4->setChecked(false);
|
||||||
ui->calibrateCallChkBox_4->setChecked(false);
|
ui->calibrateCallChkBox_4->setChecked(false);
|
||||||
@ -732,17 +639,14 @@ void DebugTerminalDialog::resetAll()
|
|||||||
ui->resetKeyCallChkBox_4->setChecked(false);
|
ui->resetKeyCallChkBox_4->setChecked(false);
|
||||||
ui->resetDefaultCallChkBox_4->setChecked(false);
|
ui->resetDefaultCallChkBox_4->setChecked(false);
|
||||||
ui->getHardfaultCallChkBox_4->setChecked(false);
|
ui->getHardfaultCallChkBox_4->setChecked(false);
|
||||||
|
|
||||||
ui->enableLedTestChkBox_4->setChecked(false);
|
ui->enableLedTestChkBox_4->setChecked(false);
|
||||||
ui->leds_4->setEnabled(false);
|
ui->leds_4->setEnabled(false);
|
||||||
ui->discs_4->setEnabled(false);
|
ui->discs_4->setEnabled(false);
|
||||||
|
|
||||||
ui->discWorkTestChkBox_4->setChecked(false);
|
ui->discWorkTestChkBox_4->setChecked(false);
|
||||||
// Сброс всех чекбоксов теста дискретных сигналов
|
// Сброс всех чекбоксов теста дискретных сигналов
|
||||||
ui->discWorkTestChkBox_4->setChecked(false);
|
ui->discWorkTestChkBox_4->setChecked(false);
|
||||||
ui->discWarnTestChkBox_4->setChecked(false);
|
ui->discWarnTestChkBox_4->setChecked(false);
|
||||||
ui->discErrTestChkBox_4->setChecked(false);
|
ui->discErrTestChkBox_4->setChecked(false);
|
||||||
|
|
||||||
// Сброс всех чекбоксов теста светодиодов
|
// Сброс всех чекбоксов теста светодиодов
|
||||||
ui->ledWorkTestChkBox_4->setChecked(false);
|
ui->ledWorkTestChkBox_4->setChecked(false);
|
||||||
ui->ledWarnTestChkBox_4->setChecked(false);
|
ui->ledWarnTestChkBox_4->setChecked(false);
|
||||||
@ -757,13 +661,10 @@ void DebugTerminalDialog::boardDebugReading(int boardID)
|
|||||||
{
|
{
|
||||||
if(mainTerm == nullptr)
|
if(mainTerm == nullptr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(!boards[boardID].isActive)
|
if(!boards[boardID].isActive)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(!this->isVisible())
|
if(!this->isVisible())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QModbusReply *_24V = mainTerm->readSingleCoil(boardID, 603);
|
QModbusReply *_24V = mainTerm->readSingleCoil(boardID, 603);
|
||||||
if(_24V != nullptr)
|
if(_24V != nullptr)
|
||||||
connect(_24V, &QModbusReply::finished, this, [this, boardID, _24V]() {
|
connect(_24V, &QModbusReply::finished, this, [this, boardID, _24V]() {
|
||||||
@ -771,7 +672,6 @@ void DebugTerminalDialog::boardDebugReading(int boardID)
|
|||||||
boards[boardID].error24V->setChecked(_24V->result().value(0));
|
boards[boardID].error24V->setChecked(_24V->result().value(0));
|
||||||
_24V->deleteLater();
|
_24V->deleteLater();
|
||||||
});
|
});
|
||||||
|
|
||||||
QModbusReply *_5V = mainTerm->readSingleCoil(boardID, 604);
|
QModbusReply *_5V = mainTerm->readSingleCoil(boardID, 604);
|
||||||
if(_5V != nullptr)
|
if(_5V != nullptr)
|
||||||
connect(_5V, &QModbusReply::finished, this, [this, boardID, _5V]() {
|
connect(_5V, &QModbusReply::finished, this, [this, boardID, _5V]() {
|
||||||
@ -779,7 +679,6 @@ void DebugTerminalDialog::boardDebugReading(int boardID)
|
|||||||
boards[boardID].error5V->setChecked(_5V->result().value(0));
|
boards[boardID].error5V->setChecked(_5V->result().value(0));
|
||||||
_5V->deleteLater();
|
_5V->deleteLater();
|
||||||
});
|
});
|
||||||
|
|
||||||
QModbusReply *_5VSCI = mainTerm->readSingleCoil(boardID, 605);
|
QModbusReply *_5VSCI = mainTerm->readSingleCoil(boardID, 605);
|
||||||
if(_5VSCI != nullptr)
|
if(_5VSCI != nullptr)
|
||||||
connect(_5VSCI, &QModbusReply::finished, this, [this, boardID, _5VSCI]() {
|
connect(_5VSCI, &QModbusReply::finished, this, [this, boardID, _5VSCI]() {
|
||||||
@ -787,7 +686,6 @@ void DebugTerminalDialog::boardDebugReading(int boardID)
|
|||||||
boards[boardID].error5VSCI->setChecked(_5VSCI->result().value(0));
|
boards[boardID].error5VSCI->setChecked(_5VSCI->result().value(0));
|
||||||
_5VSCI->deleteLater();
|
_5VSCI->deleteLater();
|
||||||
});
|
});
|
||||||
|
|
||||||
QModbusReply *_5VA = mainTerm->readSingleCoil(boardID, 606);
|
QModbusReply *_5VA = mainTerm->readSingleCoil(boardID, 606);
|
||||||
if(_5VA != nullptr)
|
if(_5VA != nullptr)
|
||||||
connect(_5VA, &QModbusReply::finished, this, [this, boardID, _5VA]() {
|
connect(_5VA, &QModbusReply::finished, this, [this, boardID, _5VA]() {
|
||||||
@ -805,7 +703,5 @@ void DebugTerminalDialog::setScanBoardActive(bool flag, int boardID)
|
|||||||
void DebugTerminalDialog::offAllBoard()
|
void DebugTerminalDialog::offAllBoard()
|
||||||
{
|
{
|
||||||
for(int i = 0; i < 4; i++)
|
for(int i = 0; i < 4; i++)
|
||||||
{
|
|
||||||
boards[i].isActive = false;
|
boards[i].isActive = false;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -45,8 +45,6 @@ class AdcGraphDialog;
|
|||||||
|
|
||||||
#define REGISTER_TE_NUMB 564
|
#define REGISTER_TE_NUMB 564
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class DebugTerminalDialog;
|
class DebugTerminalDialog;
|
||||||
}
|
}
|
||||||
@ -54,7 +52,6 @@ class DebugTerminalDialog;
|
|||||||
class DebugTerminalDialog : public QDialog
|
class DebugTerminalDialog : public QDialog
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit DebugTerminalDialog(QWidget *parent = nullptr);
|
explicit DebugTerminalDialog(QWidget *parent = nullptr);
|
||||||
~DebugTerminalDialog();
|
~DebugTerminalDialog();
|
||||||
@ -68,21 +65,15 @@ public:
|
|||||||
void writeTENumber(int boardId, int teNumber);
|
void writeTENumber(int boardId, int teNumber);
|
||||||
void openAdc(int boardID, int teNumber);
|
void openAdc(int boardID, int teNumber);
|
||||||
void setMainTerm(M3KTE* term);
|
void setMainTerm(M3KTE* term);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void boardDebugReading(int boardID);
|
void boardDebugReading(int boardID);
|
||||||
void setScanBoardActive(bool flag, int boardID);
|
void setScanBoardActive(bool flag, int boardID);
|
||||||
void offAllBoard();
|
void offAllBoard();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void showEvent(QShowEvent *event) override;
|
void showEvent(QShowEvent *event) override;
|
||||||
void closeEvent(QCloseEvent *event) override;
|
void closeEvent(QCloseEvent *event) override;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|
||||||
|
|
||||||
void on_buttonBox_clicked(QAbstractButton *button);
|
void on_buttonBox_clicked(QAbstractButton *button);
|
||||||
|
|
||||||
// Плата 1
|
// Плата 1
|
||||||
void on_continiusCallChkBox_1_stateChanged(int state);
|
void on_continiusCallChkBox_1_stateChanged(int state);
|
||||||
void on_calibrateCallChkBox_1_stateChanged(int state);
|
void on_calibrateCallChkBox_1_stateChanged(int state);
|
||||||
@ -90,9 +81,7 @@ private slots:
|
|||||||
void on_resetKeyCallChkBox_1_stateChanged(int state);
|
void on_resetKeyCallChkBox_1_stateChanged(int state);
|
||||||
void on_resetDefaultCallChkBox_1_stateChanged(int state);
|
void on_resetDefaultCallChkBox_1_stateChanged(int state);
|
||||||
void on_getHardfaultCallChkBox_1_stateChanged(int state);
|
void on_getHardfaultCallChkBox_1_stateChanged(int state);
|
||||||
|
|
||||||
void on_enableLedTestChkBox_1_stateChanged(int state);
|
void on_enableLedTestChkBox_1_stateChanged(int state);
|
||||||
|
|
||||||
void on_discWorkTestChkBox_1_stateChanged(int state);
|
void on_discWorkTestChkBox_1_stateChanged(int state);
|
||||||
void on_discWarnTestChkBox_1_stateChanged(int state);
|
void on_discWarnTestChkBox_1_stateChanged(int state);
|
||||||
void on_discErrTestChkBox_1_stateChanged(int state);
|
void on_discErrTestChkBox_1_stateChanged(int state);
|
||||||
@ -100,7 +89,6 @@ private slots:
|
|||||||
void on_discErr5TestChkBox_1_stateChanged(int state);
|
void on_discErr5TestChkBox_1_stateChanged(int state);
|
||||||
void on_discErr5VsciTestChkBox_1_stateChanged(int state);
|
void on_discErr5VsciTestChkBox_1_stateChanged(int state);
|
||||||
void on_discErr5VATestChkBox_1_stateChanged(int state);
|
void on_discErr5VATestChkBox_1_stateChanged(int state);
|
||||||
|
|
||||||
void on_ledWorkTestChkBox_1_stateChanged(int state);
|
void on_ledWorkTestChkBox_1_stateChanged(int state);
|
||||||
void on_ledWarnTestChkBox_1_stateChanged(int state);
|
void on_ledWarnTestChkBox_1_stateChanged(int state);
|
||||||
void on_ledErrTestChkBox_1_stateChanged(int state);
|
void on_ledErrTestChkBox_1_stateChanged(int state);
|
||||||
@ -108,7 +96,6 @@ private slots:
|
|||||||
void on_ledVH1TestChkBox_1_stateChanged(int state);
|
void on_ledVH1TestChkBox_1_stateChanged(int state);
|
||||||
void on_ledVH2TestChkBox_1_stateChanged(int state);
|
void on_ledVH2TestChkBox_1_stateChanged(int state);
|
||||||
void on_ledVH3TestChkBox_1_stateChanged(int state);
|
void on_ledVH3TestChkBox_1_stateChanged(int state);
|
||||||
|
|
||||||
// Плата 2
|
// Плата 2
|
||||||
void on_continiusCallChkBox_2_stateChanged(int state);
|
void on_continiusCallChkBox_2_stateChanged(int state);
|
||||||
void on_calibrateCallChkBox_2_stateChanged(int state);
|
void on_calibrateCallChkBox_2_stateChanged(int state);
|
||||||
@ -116,9 +103,7 @@ private slots:
|
|||||||
void on_resetKeyCallChkBox_2_stateChanged(int state);
|
void on_resetKeyCallChkBox_2_stateChanged(int state);
|
||||||
void on_resetDefaultCallChkBox_2_stateChanged(int state);
|
void on_resetDefaultCallChkBox_2_stateChanged(int state);
|
||||||
void on_getHardfaultCallChkBox_2_stateChanged(int state);
|
void on_getHardfaultCallChkBox_2_stateChanged(int state);
|
||||||
|
|
||||||
void on_enableLedTestChkBox_2_stateChanged(int state);
|
void on_enableLedTestChkBox_2_stateChanged(int state);
|
||||||
|
|
||||||
void on_discWorkTestChkBox_2_stateChanged(int state);
|
void on_discWorkTestChkBox_2_stateChanged(int state);
|
||||||
void on_discWarnTestChkBox_2_stateChanged(int state);
|
void on_discWarnTestChkBox_2_stateChanged(int state);
|
||||||
void on_discErrTestChkBox_2_stateChanged(int state);
|
void on_discErrTestChkBox_2_stateChanged(int state);
|
||||||
@ -126,7 +111,6 @@ private slots:
|
|||||||
void on_discErr5TestChkBox_2_stateChanged(int state);
|
void on_discErr5TestChkBox_2_stateChanged(int state);
|
||||||
void on_discErr5VsciTestChkBox_2_stateChanged(int state);
|
void on_discErr5VsciTestChkBox_2_stateChanged(int state);
|
||||||
void on_discErr5VATestChkBox_2_stateChanged(int state);
|
void on_discErr5VATestChkBox_2_stateChanged(int state);
|
||||||
|
|
||||||
void on_ledWorkTestChkBox_2_stateChanged(int state);
|
void on_ledWorkTestChkBox_2_stateChanged(int state);
|
||||||
void on_ledWarnTestChkBox_2_stateChanged(int state);
|
void on_ledWarnTestChkBox_2_stateChanged(int state);
|
||||||
void on_ledErrTestChkBox_2_stateChanged(int state);
|
void on_ledErrTestChkBox_2_stateChanged(int state);
|
||||||
@ -134,8 +118,6 @@ private slots:
|
|||||||
void on_ledVH1TestChkBox_2_stateChanged(int state);
|
void on_ledVH1TestChkBox_2_stateChanged(int state);
|
||||||
void on_ledVH2TestChkBox_2_stateChanged(int state);
|
void on_ledVH2TestChkBox_2_stateChanged(int state);
|
||||||
void on_ledVH3TestChkBox_2_stateChanged(int state);
|
void on_ledVH3TestChkBox_2_stateChanged(int state);
|
||||||
|
|
||||||
|
|
||||||
// Плата 3
|
// Плата 3
|
||||||
void on_continiusCallChkBox_3_stateChanged(int state);
|
void on_continiusCallChkBox_3_stateChanged(int state);
|
||||||
void on_calibrateCallChkBox_3_stateChanged(int state);
|
void on_calibrateCallChkBox_3_stateChanged(int state);
|
||||||
@ -143,9 +125,7 @@ private slots:
|
|||||||
void on_resetKeyCallChkBox_3_stateChanged(int state);
|
void on_resetKeyCallChkBox_3_stateChanged(int state);
|
||||||
void on_resetDefaultCallChkBox_3_stateChanged(int state);
|
void on_resetDefaultCallChkBox_3_stateChanged(int state);
|
||||||
void on_getHardfaultCallChkBox_3_stateChanged(int state);
|
void on_getHardfaultCallChkBox_3_stateChanged(int state);
|
||||||
|
|
||||||
void on_enableLedTestChkBox_3_stateChanged(int state);
|
void on_enableLedTestChkBox_3_stateChanged(int state);
|
||||||
|
|
||||||
void on_discWorkTestChkBox_3_stateChanged(int state);
|
void on_discWorkTestChkBox_3_stateChanged(int state);
|
||||||
void on_discWarnTestChkBox_3_stateChanged(int state);
|
void on_discWarnTestChkBox_3_stateChanged(int state);
|
||||||
void on_discErrTestChkBox_3_stateChanged(int state);
|
void on_discErrTestChkBox_3_stateChanged(int state);
|
||||||
@ -153,7 +133,6 @@ private slots:
|
|||||||
void on_discErr5TestChkBox_3_stateChanged(int state);
|
void on_discErr5TestChkBox_3_stateChanged(int state);
|
||||||
void on_discErr5VsciTestChkBox_3_stateChanged(int state);
|
void on_discErr5VsciTestChkBox_3_stateChanged(int state);
|
||||||
void on_discErr5VATestChkBox_3_stateChanged(int state);
|
void on_discErr5VATestChkBox_3_stateChanged(int state);
|
||||||
|
|
||||||
void on_ledWorkTestChkBox_3_stateChanged(int state);
|
void on_ledWorkTestChkBox_3_stateChanged(int state);
|
||||||
void on_ledWarnTestChkBox_3_stateChanged(int state);
|
void on_ledWarnTestChkBox_3_stateChanged(int state);
|
||||||
void on_ledErrTestChkBox_3_stateChanged(int state);
|
void on_ledErrTestChkBox_3_stateChanged(int state);
|
||||||
@ -161,7 +140,6 @@ private slots:
|
|||||||
void on_ledVH1TestChkBox_3_stateChanged(int state);
|
void on_ledVH1TestChkBox_3_stateChanged(int state);
|
||||||
void on_ledVH2TestChkBox_3_stateChanged(int state);
|
void on_ledVH2TestChkBox_3_stateChanged(int state);
|
||||||
void on_ledVH3TestChkBox_3_stateChanged(int state);
|
void on_ledVH3TestChkBox_3_stateChanged(int state);
|
||||||
|
|
||||||
// Плата 4
|
// Плата 4
|
||||||
void on_continiusCallChkBox_4_stateChanged(int state);
|
void on_continiusCallChkBox_4_stateChanged(int state);
|
||||||
void on_calibrateCallChkBox_4_stateChanged(int state);
|
void on_calibrateCallChkBox_4_stateChanged(int state);
|
||||||
@ -169,9 +147,7 @@ private slots:
|
|||||||
void on_resetKeyCallChkBox_4_stateChanged(int state);
|
void on_resetKeyCallChkBox_4_stateChanged(int state);
|
||||||
void on_resetDefaultCallChkBox_4_stateChanged(int state);
|
void on_resetDefaultCallChkBox_4_stateChanged(int state);
|
||||||
void on_getHardfaultCallChkBox_4_stateChanged(int state);
|
void on_getHardfaultCallChkBox_4_stateChanged(int state);
|
||||||
|
|
||||||
void on_enableLedTestChkBox_4_stateChanged(int state);
|
void on_enableLedTestChkBox_4_stateChanged(int state);
|
||||||
|
|
||||||
void on_discWorkTestChkBox_4_stateChanged(int state);
|
void on_discWorkTestChkBox_4_stateChanged(int state);
|
||||||
void on_discWarnTestChkBox_4_stateChanged(int state);
|
void on_discWarnTestChkBox_4_stateChanged(int state);
|
||||||
void on_discErrTestChkBox_4_stateChanged(int state);
|
void on_discErrTestChkBox_4_stateChanged(int state);
|
||||||
@ -179,7 +155,6 @@ private slots:
|
|||||||
void on_discErr5TestChkBox_4_stateChanged(int state);
|
void on_discErr5TestChkBox_4_stateChanged(int state);
|
||||||
void on_discErr5VsciTestChkBox_4_stateChanged(int state);
|
void on_discErr5VsciTestChkBox_4_stateChanged(int state);
|
||||||
void on_discErr5VATestChkBox_4_stateChanged(int state);
|
void on_discErr5VATestChkBox_4_stateChanged(int state);
|
||||||
|
|
||||||
void on_ledWorkTestChkBox_4_stateChanged(int state);
|
void on_ledWorkTestChkBox_4_stateChanged(int state);
|
||||||
void on_ledWarnTestChkBox_4_stateChanged(int state);
|
void on_ledWarnTestChkBox_4_stateChanged(int state);
|
||||||
void on_ledErrTestChkBox_4_stateChanged(int state);
|
void on_ledErrTestChkBox_4_stateChanged(int state);
|
||||||
@ -187,25 +162,20 @@ private slots:
|
|||||||
void on_ledVH1TestChkBox_4_stateChanged(int state);
|
void on_ledVH1TestChkBox_4_stateChanged(int state);
|
||||||
void on_ledVH2TestChkBox_4_stateChanged(int state);
|
void on_ledVH2TestChkBox_4_stateChanged(int state);
|
||||||
void on_ledVH3TestChkBox_4_stateChanged(int state);
|
void on_ledVH3TestChkBox_4_stateChanged(int state);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void coilValueChanged(int boardID, int coil, int value);
|
void coilValueChanged(int boardID, int coil, int value);
|
||||||
void writeRegister(int boardID, int reg, int value);
|
void writeRegister(int boardID, int reg, int value);
|
||||||
void readCoil(int boardID, int coil, QModbusReply *reply);
|
void readCoil(int boardID, int coil, QModbusReply *reply);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::DebugTerminalDialog *ui;
|
Ui::DebugTerminalDialog *ui;
|
||||||
QModbusClient *m_modbusDevice; // Храним указатель здесь
|
QModbusClient *m_modbusDevice; // Храним указатель здесь
|
||||||
M3KTE* mainTerm = nullptr;
|
M3KTE* mainTerm = nullptr;
|
||||||
|
|
||||||
// Карты для хранения состояний
|
// Карты для хранения состояний
|
||||||
QMap<int, bool> m_functionCalls; // boardId -> coil -> state
|
QMap<int, bool> m_functionCalls; // boardId -> coil -> state
|
||||||
QMap<int, bool> m_discreteTests; // boardId -> coil -> state
|
QMap<int, bool> m_discreteTests; // boardId -> coil -> state
|
||||||
QMap<int, bool> m_ledTests; // boardId -> coil -> state
|
QMap<int, bool> m_ledTests; // boardId -> coil -> state
|
||||||
|
|
||||||
// Номера ТЭ для каждой платы
|
// Номера ТЭ для каждой платы
|
||||||
int m_teNumbers[4] = {0, 0, 0, 0};
|
int m_teNumbers[4] = {0, 0, 0, 0};
|
||||||
|
|
||||||
struct boardErrorLinks{
|
struct boardErrorLinks{
|
||||||
bool isActive = false;
|
bool isActive = false;
|
||||||
QCheckBox* error24V = nullptr;
|
QCheckBox* error24V = nullptr;
|
||||||
@ -214,9 +184,7 @@ private:
|
|||||||
QCheckBox* error5VA = nullptr;
|
QCheckBox* error5VA = nullptr;
|
||||||
};
|
};
|
||||||
boardErrorLinks boards[4];
|
boardErrorLinks boards[4];
|
||||||
|
|
||||||
void initializeConnections();
|
void initializeConnections();
|
||||||
|
|
||||||
void writeCoil(int boardID, int coil, int value);
|
void writeCoil(int boardID, int coil, int value);
|
||||||
//void readCoil(int coil);
|
//void readCoil(int coil);
|
||||||
void resetAll();
|
void resetAll();
|
||||||
|
|||||||
@ -10,17 +10,14 @@ DeviceSettingsDialog::DeviceSettingsDialog(QWidget *parent) :
|
|||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
on_buttonApplyChangeTimer_clicked();
|
on_buttonApplyChangeTimer_clicked();
|
||||||
{
|
_m_timer[0] = ui->spinTimerBoard_1;
|
||||||
_m_timer[0] = ui->spinTimerBoard_1;
|
_m_timer[1] = ui->spinTimerBoard_2;
|
||||||
_m_timer[1] = ui->spinTimerBoard_2;
|
_m_timer[2] = ui->spinTimerBoard_3;
|
||||||
_m_timer[2] = ui->spinTimerBoard_3;
|
_m_timer[3] = ui->spinTimerBoard_4;
|
||||||
_m_timer[3] = ui->spinTimerBoard_4;
|
|
||||||
}
|
|
||||||
_currentSpeed = ui->speedBox->currentText().toUInt();
|
_currentSpeed = ui->speedBox->currentText().toUInt();
|
||||||
_currentParity = ui->parityBox->currentIndex();
|
_currentParity = ui->parityBox->currentIndex();
|
||||||
for(int i = 0; i < 4; i++) {
|
for(int i = 0; i < 4; i++)
|
||||||
_currentAdrs[i] = i+1;
|
_currentAdrs[i] = i+1;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceSettingsDialog::~DeviceSettingsDialog()
|
DeviceSettingsDialog::~DeviceSettingsDialog()
|
||||||
@ -74,7 +71,7 @@ unsigned short DeviceSettingsDialog::currentParity()
|
|||||||
void DeviceSettingsDialog::updateSettingsAfterConnection(unsigned tmp_speed, unsigned tmp_parity, unsigned *tmp_adr, bool *ActiveDevices)
|
void DeviceSettingsDialog::updateSettingsAfterConnection(unsigned tmp_speed, unsigned tmp_parity, unsigned *tmp_adr, bool *ActiveDevices)
|
||||||
{
|
{
|
||||||
ui->speedBox->setCurrentText(QString::number(_currentSpeed=tmp_speed, 10));
|
ui->speedBox->setCurrentText(QString::number(_currentSpeed=tmp_speed, 10));
|
||||||
if(tmp_parity>0)
|
if(tmp_parity > 0)
|
||||||
tmp_parity--;
|
tmp_parity--;
|
||||||
ui->parityBox->setCurrentIndex(_currentParity = tmp_parity);
|
ui->parityBox->setCurrentIndex(_currentParity = tmp_parity);
|
||||||
for(int i = 0; i < 4; i++) {
|
for(int i = 0; i < 4; i++) {
|
||||||
@ -82,9 +79,8 @@ void DeviceSettingsDialog::updateSettingsAfterConnection(unsigned tmp_speed, uns
|
|||||||
_m_timer[i]->setEnabled(true);
|
_m_timer[i]->setEnabled(true);
|
||||||
ui->idComboBox->addItem(QString::number(i));
|
ui->idComboBox->addItem(QString::number(i));
|
||||||
_currentAdrs[i] = tmp_adr[i];
|
_currentAdrs[i] = tmp_adr[i];
|
||||||
} else {
|
} else
|
||||||
_m_timer[i]->setEnabled(false);
|
_m_timer[i]->setEnabled(false);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
on_idComboBox_currentIndexChanged(ui->idComboBox->currentIndex());
|
on_idComboBox_currentIndexChanged(ui->idComboBox->currentIndex());
|
||||||
}
|
}
|
||||||
@ -107,9 +103,8 @@ void DeviceSettingsDialog::on_buttonBox_clicked(QAbstractButton *button)
|
|||||||
_currentSpeed = ui->speedBox->currentText().toUInt();
|
_currentSpeed = ui->speedBox->currentText().toUInt();
|
||||||
ui->parityBox->setCurrentIndex(0);
|
ui->parityBox->setCurrentIndex(0);
|
||||||
_currentParity = ui->parityBox->currentIndex();
|
_currentParity = ui->parityBox->currentIndex();
|
||||||
for(int i = 0; i < 4; i++) {
|
for(int i = 0; i < 4; i++)
|
||||||
_currentAdrs[i] = i+1;
|
_currentAdrs[i] = i + 1;
|
||||||
}
|
|
||||||
ui->adrSpinBox->setValue(_currentAdrs[ui->idComboBox->currentIndex()]);
|
ui->adrSpinBox->setValue(_currentAdrs[ui->idComboBox->currentIndex()]);
|
||||||
break;
|
break;
|
||||||
case QDialogButtonBox::AcceptRole:
|
case QDialogButtonBox::AcceptRole:
|
||||||
@ -122,7 +117,7 @@ void DeviceSettingsDialog::on_buttonBox_clicked(QAbstractButton *button)
|
|||||||
|
|
||||||
void DeviceSettingsDialog::initPollForBoard(unsigned boardID, unsigned boardAdr)
|
void DeviceSettingsDialog::initPollForBoard(unsigned boardID, unsigned boardAdr)
|
||||||
{
|
{
|
||||||
ui->idPollComboBox->addItem(QString("Плата №%1 (ID %2)").arg(boardID+1).arg(boardAdr), QVariant(boardID));
|
ui->idPollComboBox->addItem(QString("Плата №%1 (ID %2)").arg(boardID + 1).arg(boardAdr), QVariant(boardID));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceSettingsDialog::updatePollStatus(unsigned boardID, bool status)
|
void DeviceSettingsDialog::updatePollStatus(unsigned boardID, bool status)
|
||||||
|
|||||||
@ -12,10 +12,8 @@ class BoardIdHasBeenChanged : public QEvent
|
|||||||
public:
|
public:
|
||||||
BoardIdHasBeenChanged(const short num, const short newId) : QEvent(QEvent::User) {_BoardNum = num; _BoardNewID = newId;}
|
BoardIdHasBeenChanged(const short num, const short newId) : QEvent(QEvent::User) {_BoardNum = num; _BoardNewID = newId;}
|
||||||
~BoardIdHasBeenChanged() {}
|
~BoardIdHasBeenChanged() {}
|
||||||
|
|
||||||
short BoardNum() const {return _BoardNum;}
|
short BoardNum() const {return _BoardNum;}
|
||||||
short BoardNewID() const {return _BoardNewID;}
|
short BoardNewID() const {return _BoardNewID;}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
short _BoardNum;
|
short _BoardNum;
|
||||||
short _BoardNewID;
|
short _BoardNewID;
|
||||||
@ -26,10 +24,8 @@ class pollStatusChange : public QEvent
|
|||||||
public:
|
public:
|
||||||
pollStatusChange(unsigned BoardID, bool Stat) : QEvent((QEvent::Type)1001) {_BoardID = BoardID; _Status = Stat;}
|
pollStatusChange(unsigned BoardID, bool Stat) : QEvent((QEvent::Type)1001) {_BoardID = BoardID; _Status = Stat;}
|
||||||
~pollStatusChange() {}
|
~pollStatusChange() {}
|
||||||
|
|
||||||
unsigned BoardID() const {return _BoardID;}
|
unsigned BoardID() const {return _BoardID;}
|
||||||
bool Status() const {return _Status;}
|
bool Status() const {return _Status;}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
unsigned _BoardID;
|
unsigned _BoardID;
|
||||||
bool _Status;
|
bool _Status;
|
||||||
@ -42,11 +38,9 @@ class DeviceSettingsDialog;
|
|||||||
class DeviceSettingsDialog : public QDialog
|
class DeviceSettingsDialog : public QDialog
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit DeviceSettingsDialog(QWidget *parent = nullptr);
|
explicit DeviceSettingsDialog(QWidget *parent = nullptr);
|
||||||
~DeviceSettingsDialog();
|
~DeviceSettingsDialog();
|
||||||
|
|
||||||
unsigned currentBoardTimer(unsigned short _ID);
|
unsigned currentBoardTimer(unsigned short _ID);
|
||||||
unsigned currentSpeed();
|
unsigned currentSpeed();
|
||||||
unsigned short currentParity();
|
unsigned short currentParity();
|
||||||
@ -58,30 +52,19 @@ public:
|
|||||||
signals:
|
signals:
|
||||||
void parityChanged();
|
void parityChanged();
|
||||||
void speedChanged();
|
void speedChanged();
|
||||||
|
|
||||||
void firstBoardAdrHasBeenChanged();
|
void firstBoardAdrHasBeenChanged();
|
||||||
void secondBoardAdrHasBeenChanged();
|
void secondBoardAdrHasBeenChanged();
|
||||||
void thirdBoardAdrHasBeenChanged();
|
void thirdBoardAdrHasBeenChanged();
|
||||||
void fourthBoardAdrHasBeenChanged();
|
void fourthBoardAdrHasBeenChanged();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|
||||||
void on_buttonApplyChangeTimer_clicked();
|
void on_buttonApplyChangeTimer_clicked();
|
||||||
|
|
||||||
void on_buttonApplyChangeSpeed_clicked();
|
void on_buttonApplyChangeSpeed_clicked();
|
||||||
|
|
||||||
void on_buttonApplyChangeParity_clicked();
|
void on_buttonApplyChangeParity_clicked();
|
||||||
|
|
||||||
void on_buttonApplyChangeAdr_clicked();
|
void on_buttonApplyChangeAdr_clicked();
|
||||||
|
|
||||||
void on_idComboBox_currentIndexChanged(int index);
|
void on_idComboBox_currentIndexChanged(int index);
|
||||||
|
|
||||||
void on_buttonBox_clicked(QAbstractButton *button);
|
void on_buttonBox_clicked(QAbstractButton *button);
|
||||||
|
|
||||||
void on_buttonApplyChangePoll_clicked();
|
void on_buttonApplyChangePoll_clicked();
|
||||||
|
|
||||||
void on_idPollComboBox_currentIndexChanged(int index);
|
void on_idPollComboBox_currentIndexChanged(int index);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QSpinBox *_m_timer[4];
|
QSpinBox *_m_timer[4];
|
||||||
unsigned _currentBoardTimers[4];
|
unsigned _currentBoardTimers[4];
|
||||||
@ -89,7 +72,6 @@ private:
|
|||||||
unsigned short _currentParity;
|
unsigned short _currentParity;
|
||||||
unsigned _currentAdrs[4];
|
unsigned _currentAdrs[4];
|
||||||
bool _currentPollStatus[4];
|
bool _currentPollStatus[4];
|
||||||
|
|
||||||
Ui::DeviceSettingsDialog *ui;
|
Ui::DeviceSettingsDialog *ui;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -6,11 +6,10 @@ LineRinger::LineRinger(QWidget *parent) :
|
|||||||
ui(new Ui::LineRinger)
|
ui(new Ui::LineRinger)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
const auto listPorts = QSerialPortInfo::availablePorts();
|
const auto listPorts = QSerialPortInfo::availablePorts();
|
||||||
for (const auto& port: listPorts) {
|
for(const auto& port: listPorts)
|
||||||
ui->comBox->addItem(QString(port.portName() + ": " + port.manufacturer()), QVariant(port.portName()));
|
ui->comBox->addItem(QString(port.portName() + ": " + port.manufacturer()), QVariant(port.portName()));
|
||||||
}
|
//чётность
|
||||||
{
|
{
|
||||||
ui->parityControlBox->addItem("No", QVariant(QSerialPort::NoParity));
|
ui->parityControlBox->addItem("No", QVariant(QSerialPort::NoParity));
|
||||||
ui->parityControlBox->addItem("Even", QVariant(QSerialPort::EvenParity));
|
ui->parityControlBox->addItem("Even", QVariant(QSerialPort::EvenParity));
|
||||||
@ -18,6 +17,7 @@ LineRinger::LineRinger(QWidget *parent) :
|
|||||||
ui->parityControlBox->addItem("Space", QVariant(QSerialPort::SpaceParity));
|
ui->parityControlBox->addItem("Space", QVariant(QSerialPort::SpaceParity));
|
||||||
ui->parityControlBox->addItem("Mark", QVariant(QSerialPort::MarkParity));
|
ui->parityControlBox->addItem("Mark", QVariant(QSerialPort::MarkParity));
|
||||||
}
|
}
|
||||||
|
//данные
|
||||||
{
|
{
|
||||||
ui->dataBox->addItem("Data5", QVariant(QSerialPort::Data5));
|
ui->dataBox->addItem("Data5", QVariant(QSerialPort::Data5));
|
||||||
ui->dataBox->addItem("Data6", QVariant(QSerialPort::Data6));
|
ui->dataBox->addItem("Data6", QVariant(QSerialPort::Data6));
|
||||||
@ -25,6 +25,7 @@ LineRinger::LineRinger(QWidget *parent) :
|
|||||||
ui->dataBox->addItem("Data8", QVariant(QSerialPort::Data8));
|
ui->dataBox->addItem("Data8", QVariant(QSerialPort::Data8));
|
||||||
ui->dataBox->setCurrentIndex(3);
|
ui->dataBox->setCurrentIndex(3);
|
||||||
}
|
}
|
||||||
|
//стопбиты
|
||||||
{
|
{
|
||||||
ui->stopBox->addItem("One", QVariant(QSerialPort::OneStop));
|
ui->stopBox->addItem("One", QVariant(QSerialPort::OneStop));
|
||||||
ui->stopBox->addItem("OneAndHalf", QVariant(QSerialPort::OneAndHalfStop));
|
ui->stopBox->addItem("OneAndHalf", QVariant(QSerialPort::OneAndHalfStop));
|
||||||
@ -33,15 +34,13 @@ LineRinger::LineRinger(QWidget *parent) :
|
|||||||
ui->deviceOnlineView->horizontalHeader()->setVisible(true);
|
ui->deviceOnlineView->horizontalHeader()->setVisible(true);
|
||||||
syncColumnHeaders();
|
syncColumnHeaders();
|
||||||
ui->deviceOnlineView->setColumnHidden(1, true);
|
ui->deviceOnlineView->setColumnHidden(1, true);
|
||||||
|
|
||||||
ui->ringButton->setEnabled(false);
|
ui->ringButton->setEnabled(false);
|
||||||
|
|
||||||
modbusDevice = new QModbusRtuSerialMaster(this);
|
modbusDevice = new QModbusRtuSerialMaster(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
LineRinger::~LineRinger()
|
LineRinger::~LineRinger()
|
||||||
{
|
{
|
||||||
if (modbusDevice->state() == QModbusDevice::ConnectedState)
|
if(modbusDevice->state() == QModbusDevice::ConnectedState)
|
||||||
on_connectButton_clicked();
|
on_connectButton_clicked();
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
@ -73,9 +72,9 @@ void LineRinger::on_connectButton_clicked()
|
|||||||
#endif
|
#endif
|
||||||
modbusDevice->setTimeout(50);
|
modbusDevice->setTimeout(50);
|
||||||
modbusDevice->setNumberOfRetries(0);
|
modbusDevice->setNumberOfRetries(0);
|
||||||
if(!modbusDevice->connectDevice()) {
|
if(!modbusDevice->connectDevice())
|
||||||
QMessageBox::warning(this, "Ошибка", "Произошла ошибка при попытке подключения.");
|
QMessageBox::warning(this, "Ошибка", "Произошла ошибка при попытке подключения.");
|
||||||
} else {
|
else {
|
||||||
ui->connectButton->setText(tr("Отключить"));
|
ui->connectButton->setText(tr("Отключить"));
|
||||||
ui->ringButton->setEnabled(true);
|
ui->ringButton->setEnabled(true);
|
||||||
currentBaudRate = ui->baudRateBox->currentText().toUInt(nullptr, 10);
|
currentBaudRate = ui->baudRateBox->currentText().toUInt(nullptr, 10);
|
||||||
@ -99,13 +98,13 @@ LineRinger::callStatus LineRinger::lineCall()
|
|||||||
*tmp_isRun = true;
|
*tmp_isRun = true;
|
||||||
});
|
});
|
||||||
connect(this, &LineRinger::stopLineCall, this, [tmp_isRun]() {
|
connect(this, &LineRinger::stopLineCall, this, [tmp_isRun]() {
|
||||||
*tmp_isRun = true;
|
*tmp_isRun = true;
|
||||||
});
|
});
|
||||||
bar->setLabelText(tr("Поиск устройств... Текущий адрес: %1").arg(tmp_adr));
|
bar->setLabelText(tr("Поиск устройств... Текущий адрес: %1").arg(tmp_adr));
|
||||||
bar->setCancelButton(nullptr);
|
bar->setCancelButton(nullptr);
|
||||||
bar->setRange(1, 247);
|
bar->setRange(1, 247);
|
||||||
bar->setMinimumDuration(100);
|
bar->setMinimumDuration(100);
|
||||||
for(tmp_adr = 1; tmp_adr<248; tmp_adr++) {
|
for(tmp_adr = 1; tmp_adr < 248; tmp_adr++) {
|
||||||
bar->setValue(tmp_adr);
|
bar->setValue(tmp_adr);
|
||||||
bar->setLabelText(tr("Поиск устройств... Текущий адрес: %1/247").arg(tmp_adr));
|
bar->setLabelText(tr("Поиск устройств... Текущий адрес: %1/247").arg(tmp_adr));
|
||||||
auto *reply = modbusDevice->sendRawRequest(readDeviceBasicIdentification, tmp_adr);
|
auto *reply = modbusDevice->sendRawRequest(readDeviceBasicIdentification, tmp_adr);
|
||||||
@ -130,7 +129,7 @@ LineRinger::callStatus LineRinger::lineCall()
|
|||||||
return callStatus::INTERRUPT;
|
return callStatus::INTERRUPT;
|
||||||
} else if(!isRun) {
|
} else if(!isRun) {
|
||||||
//Нужна проверка типа устройства
|
//Нужна проверка типа устройства
|
||||||
if(reply->error()!=QModbusDevice::TimeoutError) {
|
if(reply->error() != QModbusDevice::TimeoutError) {
|
||||||
deviceOnLine currentDevice;
|
deviceOnLine currentDevice;
|
||||||
currentDevice.adr = tmp_adr;
|
currentDevice.adr = tmp_adr;
|
||||||
currentDevice.baudRate = currentBaudRate;
|
currentDevice.baudRate = currentBaudRate;
|
||||||
@ -143,17 +142,16 @@ LineRinger::callStatus LineRinger::lineCall()
|
|||||||
for(int tmp_obj = 0; tmp_obj < numOfObject; tmp_obj++) {
|
for(int tmp_obj = 0; tmp_obj < numOfObject; tmp_obj++) {
|
||||||
uint8_t objectID = result.at(0);
|
uint8_t objectID = result.at(0);
|
||||||
uint8_t lengthOfObject = result.at(1);
|
uint8_t lengthOfObject = result.at(1);
|
||||||
if(lengthOfObject>0) {
|
if(lengthOfObject > 0)
|
||||||
currentDevice.fields[objectID].clear();
|
currentDevice.fields[objectID].clear();
|
||||||
}
|
for(int i = 0; i < lengthOfObject; i++)
|
||||||
for(int i = 0; i < lengthOfObject; i++) {
|
currentDevice.fields[objectID] += QString(result.at(2 + i));
|
||||||
currentDevice.fields[objectID] += QString(result.at(2+i));
|
result.remove(0, lengthOfObject + 2);
|
||||||
}
|
|
||||||
result.remove(0, lengthOfObject+2);
|
|
||||||
}
|
}
|
||||||
auto *regularReply = modbusDevice->sendRawRequest(readDeviceRegularIdentification, tmp_adr);
|
auto *regularReply = modbusDevice->sendRawRequest(readDeviceRegularIdentification, tmp_adr);
|
||||||
if(regularReply == nullptr) {
|
if(regularReply == nullptr) {
|
||||||
QMessageBox::warning(this, "Ошибка при сканировании.", QString("%1: %2").arg(modbusDevice->error()).arg(modbusDevice->errorString()));
|
QMessageBox::warning(this, "Ошибка при сканировании.",
|
||||||
|
QString("%1: %2").arg(modbusDevice->error()).arg(modbusDevice->errorString()));
|
||||||
bar->close();
|
bar->close();
|
||||||
bar->deleteLater();
|
bar->deleteLater();
|
||||||
return callStatus::ERROR;
|
return callStatus::ERROR;
|
||||||
@ -183,13 +181,11 @@ LineRinger::callStatus LineRinger::lineCall()
|
|||||||
if(objectID > 0x06)
|
if(objectID > 0x06)
|
||||||
continue;
|
continue;
|
||||||
uint8_t lengthOfObject = regularResult.at(1);
|
uint8_t lengthOfObject = regularResult.at(1);
|
||||||
if(lengthOfObject>0) {
|
if(lengthOfObject > 0)
|
||||||
currentDevice.fields[objectID].clear();
|
currentDevice.fields[objectID].clear();
|
||||||
}
|
for(int i = 0; i < lengthOfObject; i++)
|
||||||
for (int i = 0; i < lengthOfObject; i++) {
|
currentDevice.fields[objectID] += QString(regularResult.at(2 + i));
|
||||||
currentDevice.fields[objectID] += QString(regularResult.at(2+i));
|
regularResult.remove(0, lengthOfObject + 2);
|
||||||
}
|
|
||||||
regularResult.remove(0, lengthOfObject+2);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -199,14 +195,12 @@ LineRinger::callStatus LineRinger::lineCall()
|
|||||||
ui->deviceOnlineView->insertRow(newRow);
|
ui->deviceOnlineView->insertRow(newRow);
|
||||||
ui->deviceOnlineView->setItem(newRow, 0, new QTableWidgetItem(QString::number(currentDevice.adr)));
|
ui->deviceOnlineView->setItem(newRow, 0, new QTableWidgetItem(QString::number(currentDevice.adr)));
|
||||||
ui->deviceOnlineView->setItem(newRow, 1, new QTableWidgetItem(QString::number(currentDevice.baudRate)));
|
ui->deviceOnlineView->setItem(newRow, 1, new QTableWidgetItem(QString::number(currentDevice.baudRate)));
|
||||||
for (int i = 0; i < 7; i++) {
|
for(int i = 0; i < 7; i++)
|
||||||
ui->deviceOnlineView->setItem(newRow, i+2, new QTableWidgetItem(currentDevice.fields[i]));
|
ui->deviceOnlineView->setItem(newRow, i + 2, new QTableWidgetItem(currentDevice.fields[i]));
|
||||||
}
|
if(reply->error()!=QModbusDevice::NoError)
|
||||||
if(reply->error()!=QModbusDevice::NoError) {
|
|
||||||
ui->deviceOnlineView->setItem(newRow, 9, new QTableWidgetItem(QString("%1: %2").arg(reply->error()).arg(reply->errorString())));
|
ui->deviceOnlineView->setItem(newRow, 9, new QTableWidgetItem(QString("%1: %2").arg(reply->error()).arg(reply->errorString())));
|
||||||
} else if(regularReplyError) {
|
else if(regularReplyError)
|
||||||
ui->deviceOnlineView->setItem(newRow, 9, new QTableWidgetItem(regularReplyErrorString));
|
ui->deviceOnlineView->setItem(newRow, 9, new QTableWidgetItem(regularReplyErrorString));
|
||||||
}
|
|
||||||
ui->deviceOnlineView->resizeColumnsToContents();
|
ui->deviceOnlineView->resizeColumnsToContents();
|
||||||
syncColumnHeaders();
|
syncColumnHeaders();
|
||||||
}
|
}
|
||||||
@ -221,8 +215,8 @@ void LineRinger::on_ringButton_clicked()
|
|||||||
ui->deviceOnlineView->clear();
|
ui->deviceOnlineView->clear();
|
||||||
devicesList.clear();
|
devicesList.clear();
|
||||||
syncColumnHeaders();
|
syncColumnHeaders();
|
||||||
while(ui->deviceOnlineView->rowCount()!=0)
|
while(ui->deviceOnlineView->rowCount() != 0)
|
||||||
ui->deviceOnlineView->removeRow(ui->deviceOnlineView->rowCount()-1);
|
ui->deviceOnlineView->removeRow(ui->deviceOnlineView->rowCount() - 1);
|
||||||
if(isAutoBaud) {
|
if(isAutoBaud) {
|
||||||
auto bar = new QProgressDialog(this);
|
auto bar = new QProgressDialog(this);
|
||||||
bar->setLabelText(tr("Поиск устройств... Текущая скорость: %1").arg(currentBaudRate));
|
bar->setLabelText(tr("Поиск устройств... Текущая скорость: %1").arg(currentBaudRate));
|
||||||
@ -231,16 +225,16 @@ void LineRinger::on_ringButton_clicked()
|
|||||||
bar->setMinimumDuration(0);
|
bar->setMinimumDuration(0);
|
||||||
bar->setCancelButton(nullptr);
|
bar->setCancelButton(nullptr);
|
||||||
connect(bar, &QProgressDialog::canceled, this, [this]() {
|
connect(bar, &QProgressDialog::canceled, this, [this]() {
|
||||||
emit stopLineCall();
|
emit stopLineCall();
|
||||||
});
|
});
|
||||||
bar->setValue(0);
|
bar->setValue(0);
|
||||||
ui->deviceOnlineView->setColumnHidden(1, false);
|
ui->deviceOnlineView->setColumnHidden(1, false);
|
||||||
modbusDevice->disconnectDevice();
|
modbusDevice->disconnectDevice();
|
||||||
for (int i = 0; i < ui->baudRateBox->count(); i++) {
|
for(int i = 0; i < ui->baudRateBox->count(); i++) {
|
||||||
bar->setValue(i+1);
|
bar->setValue(i + 1);
|
||||||
modbusDevice->setConnectionParameter(QModbusDevice::SerialBaudRateParameter,
|
modbusDevice->setConnectionParameter(QModbusDevice::SerialBaudRateParameter,
|
||||||
ui->baudRateBox->itemText(i).toInt(nullptr, 10));
|
ui->baudRateBox->itemText(i).toInt(nullptr, 10));
|
||||||
if (!modbusDevice->connectDevice()) {
|
if(!modbusDevice->connectDevice()) {
|
||||||
QMessageBox::warning(this, "Ошибка", "Произошла ошибка при попытке подключения.");
|
QMessageBox::warning(this, "Ошибка", "Произошла ошибка при попытке подключения.");
|
||||||
on_connectButton_clicked();
|
on_connectButton_clicked();
|
||||||
break;
|
break;
|
||||||
@ -248,7 +242,8 @@ void LineRinger::on_ringButton_clicked()
|
|||||||
currentBaudRate = ui->baudRateBox->itemText(i).toUInt(nullptr, 10);
|
currentBaudRate = ui->baudRateBox->itemText(i).toUInt(nullptr, 10);
|
||||||
bar->setLabelText(tr("Поиск устройств... Текущая скорость: %1").arg(currentBaudRate));
|
bar->setLabelText(tr("Поиск устройств... Текущая скорость: %1").arg(currentBaudRate));
|
||||||
if(lineCall() == callStatus::INTERRUPT) {
|
if(lineCall() == callStatus::INTERRUPT) {
|
||||||
QMessageBox::warning(this, "Уведомление", QString("Досрочное завершение опроса. Найдено %1 устройств.").arg(devicesList.count()));
|
QMessageBox::warning(this, "Уведомление",
|
||||||
|
QString("Досрочное завершение опроса. Найдено %1 устройств.").arg(devicesList.count()));
|
||||||
modbusDevice->disconnectDevice();
|
modbusDevice->disconnectDevice();
|
||||||
on_connectButton_clicked();
|
on_connectButton_clicked();
|
||||||
bar->close();
|
bar->close();
|
||||||
@ -262,9 +257,9 @@ void LineRinger::on_ringButton_clicked()
|
|||||||
on_connectButton_clicked();
|
on_connectButton_clicked();
|
||||||
} else {
|
} else {
|
||||||
ui->deviceOnlineView->setColumnHidden(1, true);
|
ui->deviceOnlineView->setColumnHidden(1, true);
|
||||||
if(lineCall() == callStatus::INTERRUPT) {
|
if(lineCall() == callStatus::INTERRUPT)
|
||||||
QMessageBox::warning(this, "Уведомление", QString("Досрочное завершение опроса. Найдено %1 устройств.").arg(devicesList.count()));
|
QMessageBox::warning(this, "Уведомление",
|
||||||
}
|
QString("Досрочное завершение опроса. Найдено %1 устройств.").arg(devicesList.count()));
|
||||||
}
|
}
|
||||||
ui->timer->setTime(QTime::currentTime());
|
ui->timer->setTime(QTime::currentTime());
|
||||||
ui->timer->setDate(QDate::currentDate());
|
ui->timer->setDate(QDate::currentDate());
|
||||||
|
|||||||
@ -16,35 +16,25 @@ class LineRinger;
|
|||||||
class LineRinger : public QWidget
|
class LineRinger : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum callStatus{
|
enum callStatus{
|
||||||
NOERROR = 0,
|
NOERROR = 0,
|
||||||
ERROR = 1,
|
ERROR = 1,
|
||||||
INTERRUPT = 2
|
INTERRUPT = 2
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit LineRinger(QWidget *parent = nullptr);
|
explicit LineRinger(QWidget *parent = nullptr);
|
||||||
~LineRinger();
|
~LineRinger();
|
||||||
callStatus lineCall();
|
callStatus lineCall();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void stopLineCall();
|
void stopLineCall();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_connectButton_clicked();
|
void on_connectButton_clicked();
|
||||||
|
|
||||||
void on_ringButton_clicked();
|
void on_ringButton_clicked();
|
||||||
|
|
||||||
void on_checkAutoBaud_stateChanged(int arg1);
|
void on_checkAutoBaud_stateChanged(int arg1);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::LineRinger *ui;
|
Ui::LineRinger *ui;
|
||||||
|
|
||||||
void syncColumnHeaders();
|
void syncColumnHeaders();
|
||||||
|
struct deviceOnLine{
|
||||||
struct deviceOnLine
|
|
||||||
{
|
|
||||||
uint8_t adr;
|
uint8_t adr;
|
||||||
unsigned baudRate;
|
unsigned baudRate;
|
||||||
QString fields[7] = {"Undefined", "Undefined", "Undefined", "Undefined", "Undefined", "Undefined", "Undefined"};
|
QString fields[7] = {"Undefined", "Undefined", "Undefined", "Undefined", "Undefined", "Undefined", "Undefined"};
|
||||||
@ -52,7 +42,6 @@ private:
|
|||||||
QVector<deviceOnLine>devicesList;
|
QVector<deviceOnLine>devicesList;
|
||||||
bool isAutoBaud = false;
|
bool isAutoBaud = false;
|
||||||
unsigned currentBaudRate;
|
unsigned currentBaudRate;
|
||||||
|
|
||||||
QModbusClient *modbusDevice = nullptr;
|
QModbusClient *modbusDevice = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
1044
M3KTE_TERM/m3kte.cpp
1044
M3KTE_TERM/m3kte.cpp
File diff suppressed because it is too large
Load Diff
@ -59,6 +59,7 @@ private:
|
|||||||
QModbusDataUnit writeRequest() const;
|
QModbusDataUnit writeRequest() const;
|
||||||
void changeTable(int board, int tabletype);
|
void changeTable(int board, int tabletype);
|
||||||
bool event(QEvent* event);
|
bool event(QEvent* event);
|
||||||
|
bool deadPing(QProgressDialog *bar);
|
||||||
bool pingNetworkDevices();
|
bool pingNetworkDevices();
|
||||||
void beginScanBoards();
|
void beginScanBoards();
|
||||||
void stopScanBoard();
|
void stopScanBoard();
|
||||||
|
|||||||
@ -25,34 +25,34 @@ void MultipleSettings::on_buttonBox_clicked(QAbstractButton *button)
|
|||||||
countReg = ui->countBox->value();
|
countReg = ui->countBox->value();
|
||||||
boardId = ui->boardBox->currentIndex();
|
boardId = ui->boardBox->currentIndex();
|
||||||
emit write();
|
emit write();
|
||||||
} else if (button == ui->buttonBox->button(QDialogButtonBox::SaveAll)) {
|
} else if(button == ui->buttonBox->button(QDialogButtonBox::SaveAll)) {
|
||||||
newValue = ui->regValueLine->text().toInt(nullptr, 16);
|
newValue = ui->regValueLine->text().toInt(nullptr, 16);
|
||||||
typeReg = ui->regTypeBox->currentIndex();
|
typeReg = ui->regTypeBox->currentIndex();
|
||||||
startAdr = ui->adrBox->value();
|
startAdr = ui->adrBox->value();
|
||||||
countReg = ui->countBox->value();
|
countReg = ui->countBox->value();
|
||||||
boardId = ui->boardBox->currentIndex();
|
boardId = ui->boardBox->currentIndex();
|
||||||
emit writeAndSend();
|
emit writeAndSend();
|
||||||
} else {}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MultipleSettings::on_regTypeBox_currentIndexChanged(int index)
|
void MultipleSettings::on_regTypeBox_currentIndexChanged(int index)
|
||||||
{
|
{
|
||||||
short maxRange = 0;
|
short maxRange = 0;
|
||||||
switch (ui->boardBox->currentIndex()) {
|
switch(ui->boardBox->currentIndex()) {
|
||||||
case 3:
|
case 3:
|
||||||
maxRange = 64;
|
maxRange = 64;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
maxRange = 84;
|
maxRange = 84;
|
||||||
}
|
}
|
||||||
switch (index) {
|
switch(index) {
|
||||||
case 0:
|
case 0:
|
||||||
case 1:
|
case 1:
|
||||||
ui->adrBox->setRange(0, maxRange);
|
ui->adrBox->setRange(0, maxRange);
|
||||||
ui->adrBox->setValue(0);
|
ui->adrBox->setValue(0);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
ui->adrBox->setRange(85, 85+maxRange);
|
ui->adrBox->setRange(85, 85 + maxRange);
|
||||||
ui->adrBox->setValue(85);
|
ui->adrBox->setValue(85);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -66,5 +66,6 @@ void MultipleSettings::on_boardBox_currentIndexChanged(int index)
|
|||||||
|
|
||||||
void MultipleSettings::on_adrBox_valueChanged(int arg1)
|
void MultipleSettings::on_adrBox_valueChanged(int arg1)
|
||||||
{
|
{
|
||||||
ui->countBox->setRange(1, ((85-(20*(ui->boardBox->currentIndex()/3)))*(1+(ui->regTypeBox->currentIndex()/2))-arg1));
|
ui->countBox->setRange(1, ((85 - (20 * (ui->boardBox->currentIndex() / 3)))
|
||||||
|
* (1 + (ui->regTypeBox->currentIndex() / 2)) - arg1));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,7 +11,6 @@ class MultipleSettings;
|
|||||||
class MultipleSettings : public QDialog
|
class MultipleSettings : public QDialog
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit MultipleSettings(QWidget *parent = nullptr);
|
explicit MultipleSettings(QWidget *parent = nullptr);
|
||||||
~MultipleSettings();
|
~MultipleSettings();
|
||||||
@ -23,16 +22,11 @@ public:
|
|||||||
signals:
|
signals:
|
||||||
void write();
|
void write();
|
||||||
void writeAndSend();
|
void writeAndSend();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_buttonBox_clicked(QAbstractButton *button);
|
void on_buttonBox_clicked(QAbstractButton *button);
|
||||||
|
|
||||||
void on_regTypeBox_currentIndexChanged(int index);
|
void on_regTypeBox_currentIndexChanged(int index);
|
||||||
|
|
||||||
void on_boardBox_currentIndexChanged(int index);
|
void on_boardBox_currentIndexChanged(int index);
|
||||||
|
|
||||||
void on_adrBox_valueChanged(int arg1);
|
void on_adrBox_valueChanged(int arg1);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::MultipleSettings *ui;
|
Ui::MultipleSettings *ui;
|
||||||
quint16 newValue = 0;
|
quint16 newValue = 0;
|
||||||
|
|||||||
@ -8,7 +8,7 @@ ParameterBox::ParameterBox(QWidget *parent, pboxMode Mode, quint16 objectID) :
|
|||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
boxMode = Mode;
|
boxMode = Mode;
|
||||||
ID = objectID;
|
ID = objectID;
|
||||||
switch (boxMode) {
|
switch(boxMode) {
|
||||||
case Info:
|
case Info:
|
||||||
ui->adrLine->setHidden(true);
|
ui->adrLine->setHidden(true);
|
||||||
ui->valueBox->setHidden(true);
|
ui->valueBox->setHidden(true);
|
||||||
@ -17,7 +17,6 @@ ParameterBox::ParameterBox(QWidget *parent, pboxMode Mode, quint16 objectID) :
|
|||||||
case MTemplate:
|
case MTemplate:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
ui->objectIdLabel->setText("0x" + QString::number(ID, 16));
|
ui->objectIdLabel->setText("0x" + QString::number(ID, 16));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,9 +28,7 @@ ParameterBox::~ParameterBox()
|
|||||||
void ParameterBox::on_sendButton_clicked()
|
void ParameterBox::on_sendButton_clicked()
|
||||||
{
|
{
|
||||||
if(ui->valueBox->currentText().isEmpty())
|
if(ui->valueBox->currentText().isEmpty())
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
emit writeParameter(ui->adrLine->text().toInt(), ui->valueBox->currentText().toInt(nullptr, 16));
|
emit writeParameter(ui->adrLine->text().toInt(), ui->valueBox->currentText().toInt(nullptr, 16));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,7 +39,7 @@ void ParameterBox::setData(QString data)
|
|||||||
|
|
||||||
void ParameterBox::setData(QString name, QString adr, QStringList values)
|
void ParameterBox::setData(QString name, QString adr, QStringList values)
|
||||||
{
|
{
|
||||||
switch (boxMode) {
|
switch(boxMode) {
|
||||||
case Info:
|
case Info:
|
||||||
ui->nameLine->setText(name);
|
ui->nameLine->setText(name);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@ -10,7 +10,6 @@ class ParameterBox;
|
|||||||
class ParameterBox : public QWidget
|
class ParameterBox : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum pboxMode{
|
enum pboxMode{
|
||||||
Info = 0,
|
Info = 0,
|
||||||
@ -20,10 +19,8 @@ public:
|
|||||||
Coil = 0,
|
Coil = 0,
|
||||||
HR = 1
|
HR = 1
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit ParameterBox(QWidget *parent = nullptr, pboxMode Mode = Info, quint16 objectID = 0x80);
|
explicit ParameterBox(QWidget *parent = nullptr, pboxMode Mode = Info, quint16 objectID = 0x80);
|
||||||
~ParameterBox();
|
~ParameterBox();
|
||||||
|
|
||||||
void setData(QString data);
|
void setData(QString data);
|
||||||
void setData(QString name, QString adr, QStringList values);
|
void setData(QString name, QString adr, QStringList values);
|
||||||
quint16 getID(){return ID;}
|
quint16 getID(){return ID;}
|
||||||
@ -32,7 +29,6 @@ signals:
|
|||||||
void writeParameter(int adr, quint16 value);
|
void writeParameter(int adr, quint16 value);
|
||||||
private slots:
|
private slots:
|
||||||
void on_sendButton_clicked();
|
void on_sendButton_clicked();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
quint16 ID;
|
quint16 ID;
|
||||||
pboxMode boxMode;
|
pboxMode boxMode;
|
||||||
|
|||||||
@ -3,9 +3,9 @@
|
|||||||
|
|
||||||
void sortParameterBoxesByID(QVector<ParameterBox*>& parameterBoxes) {
|
void sortParameterBoxesByID(QVector<ParameterBox*>& parameterBoxes) {
|
||||||
std::sort(parameterBoxes.begin(), parameterBoxes.end(),
|
std::sort(parameterBoxes.begin(), parameterBoxes.end(),
|
||||||
[](ParameterBox* a, ParameterBox* b) {
|
[](ParameterBox* a, ParameterBox* b) {
|
||||||
return a->getID() < b->getID();
|
return a->getID() < b->getID();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ParameterDevice::ParameterDevice(QWidget *parent) :
|
ParameterDevice::ParameterDevice(QWidget *parent) :
|
||||||
@ -13,10 +13,6 @@ ParameterDevice::ParameterDevice(QWidget *parent) :
|
|||||||
ui(new Ui::ParameterDevice)
|
ui(new Ui::ParameterDevice)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
updateTimer = new QTimer(this);
|
|
||||||
updateTimer->setSingleShot(true);
|
|
||||||
connect(updateTimer, &QTimer::timeout, this, &ParameterDevice::sortScrollArea);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ParameterDevice::~ParameterDevice()
|
ParameterDevice::~ParameterDevice()
|
||||||
@ -38,46 +34,62 @@ void ParameterDevice::on_fullRadio_clicked()
|
|||||||
|
|
||||||
void ParameterDevice::on_checkButton_clicked()
|
void ParameterDevice::on_checkButton_clicked()
|
||||||
{
|
{
|
||||||
for (ParameterBox* box : parameterBoxes) {
|
for(ParameterBox* box : parameterBoxes)
|
||||||
if (box) {
|
if(box)
|
||||||
box->deleteLater();
|
box->deleteLater();
|
||||||
}
|
|
||||||
}
|
|
||||||
parameterBoxes.clear();
|
parameterBoxes.clear();
|
||||||
quint16 strAdr;
|
quint16 strAdr;
|
||||||
int cnt;
|
int cnt = 0;
|
||||||
strAdr = ui->adrSpin->value();
|
strAdr = ui->adrSpin->value();
|
||||||
switch (mode) {
|
switch(mode) {
|
||||||
case fullRequest:
|
case fullRequest:
|
||||||
strAdr = 0x80;
|
strAdr = 0x80;
|
||||||
cnt = 128;
|
cnt = 128;
|
||||||
break;
|
break;
|
||||||
case selectiveRequest:
|
case selectiveRequest:
|
||||||
cnt = ui->countSpin->value();
|
cnt = ui->countSpin->value();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
QElapsedTimer timer;
|
||||||
QProgressDialog progressDialog("Обработка...", "Отмена", 0, cnt, this);
|
QProgressDialog progressDialog("Обработка...", "Отмена", 0, cnt, this);
|
||||||
progressDialog.setWindowModality(Qt::WindowModal);
|
progressDialog.setWindowModality(Qt::WindowModal);
|
||||||
progressDialog.setMinimumDuration(0); // показывать сразу
|
progressDialog.setMinimumDuration(0); // показывать сразу
|
||||||
QEventLoop loop;
|
QEventLoop loop;
|
||||||
connect(this, &ParameterDevice::transmitEnd, &loop, &QEventLoop::quit);
|
connect(this, &ParameterDevice::transmitEnd, &loop, &QEventLoop::quit);
|
||||||
for (int i = 0; i < cnt; i ++) {
|
timer.start();
|
||||||
|
for(int i = 0; i < cnt; i ++) {
|
||||||
// Обновляем прогресс
|
// Обновляем прогресс
|
||||||
progressDialog.setValue(i);
|
progressDialog.setValue(i);
|
||||||
if (progressDialog.wasCanceled()) {
|
if(progressDialog.wasCanceled())
|
||||||
break; // пользователь отменил
|
break; // пользователь отменил
|
||||||
}
|
|
||||||
QByteArray data = QByteArray::fromHex("0E04");
|
QByteArray data = QByteArray::fromHex("0E04");
|
||||||
data.append(strAdr+i);
|
data.append(strAdr+i);
|
||||||
QModbusRequest request(QModbusRequest::EncapsulatedInterfaceTransport, data);
|
QModbusRequest request(QModbusRequest::EncapsulatedInterfaceTransport, data);
|
||||||
emit read(request, strAdr+i);
|
emit read(request, strAdr+i);
|
||||||
loop.exec();
|
loop.exec();
|
||||||
if(errorAtTransmit)
|
if(errorAtTransmit) {
|
||||||
{
|
|
||||||
errorAtTransmit = false;
|
errorAtTransmit = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
qint64 elapsedNanoSeconds = timer.nsecsElapsed();
|
||||||
|
// Вычисляем компоненты времени
|
||||||
|
qint64 totalMicroseconds = elapsedNanoSeconds / 1000; // Микросекунды
|
||||||
|
qint64 totalMilliseconds = totalMicroseconds / 1000; // Миллисекунды
|
||||||
|
qint64 totalSeconds = totalMilliseconds / 1000; // Секунды
|
||||||
|
qint64 totalMinutes = totalSeconds / 60; // Минуты
|
||||||
|
// Остатки после деления
|
||||||
|
qint64 remainingMicroseconds = totalMicroseconds % 1000;
|
||||||
|
qint64 remainingMilliseconds = totalMilliseconds % 1000;
|
||||||
|
qint64 remainingSeconds = totalSeconds % 60;
|
||||||
|
// Форматируем строку для отображения
|
||||||
|
QString timeString = QString("%1 мин %2 сек %3 мс %4 мкс")
|
||||||
|
.arg(totalMinutes)
|
||||||
|
.arg(remainingSeconds)
|
||||||
|
.arg(remainingMilliseconds)
|
||||||
|
.arg(remainingMicroseconds);
|
||||||
|
// Выводим
|
||||||
|
QMessageBox::information(this, "Общее время выполнения", timeString);
|
||||||
progressDialog.setValue(cnt);
|
progressDialog.setValue(cnt);
|
||||||
sortParameterBoxesByID(parameterBoxes);
|
sortParameterBoxesByID(parameterBoxes);
|
||||||
sortScrollArea();
|
sortScrollArea();
|
||||||
@ -85,7 +97,6 @@ void ParameterDevice::on_checkButton_clicked()
|
|||||||
|
|
||||||
void ParameterDevice::setError(QString error)
|
void ParameterDevice::setError(QString error)
|
||||||
{
|
{
|
||||||
|
|
||||||
QMessageBox::information(nullptr, "Получен ответ", error);
|
QMessageBox::information(nullptr, "Получен ответ", error);
|
||||||
errorAtTransmit = true;
|
errorAtTransmit = true;
|
||||||
emit transmitEnd();
|
emit transmitEnd();
|
||||||
@ -93,14 +104,14 @@ void ParameterDevice::setError(QString error)
|
|||||||
|
|
||||||
void ParameterDevice::on_adrSpin_valueChanged(int arg1)
|
void ParameterDevice::on_adrSpin_valueChanged(int arg1)
|
||||||
{
|
{
|
||||||
ui->countSpin->setRange(1, 256-arg1);
|
ui->countSpin->setRange(1, 256 - arg1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParameterDevice::setAnswer(QString reply, quint16 objectID)
|
void ParameterDevice::setAnswer(QString reply, quint16 objectID)
|
||||||
{
|
{
|
||||||
ParameterBox *newbox = new ParameterBox(nullptr, ParameterBox::Info, objectID);
|
ParameterBox *newbox = new ParameterBox(nullptr, ParameterBox::Info, objectID);
|
||||||
newbox->setData(reply);
|
newbox->setData(reply);
|
||||||
switch (newbox->getType()) {
|
switch(newbox->getType()) {
|
||||||
case ParameterBox::Coil:
|
case ParameterBox::Coil:
|
||||||
connect(newbox, &ParameterBox::writeParameter, this, [this](int adr, quint16 value){
|
connect(newbox, &ParameterBox::writeParameter, this, [this](int adr, quint16 value){
|
||||||
emit writeSingleCoil(adr, (bool)value);
|
emit writeSingleCoil(adr, (bool)value);
|
||||||
@ -114,36 +125,20 @@ void ParameterDevice::setAnswer(QString reply, quint16 objectID)
|
|||||||
}
|
}
|
||||||
parameterBoxes.append(newbox);
|
parameterBoxes.append(newbox);
|
||||||
emit transmitEnd();
|
emit transmitEnd();
|
||||||
|
|
||||||
// // Остановить, если уже запущен
|
|
||||||
// if (updateTimer->isActive()) {
|
|
||||||
// updateTimer->stop();
|
|
||||||
// }
|
|
||||||
// // Запустить с задержкой 6 секунд
|
|
||||||
// updateTimer->start(6000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParameterDevice::sortScrollArea()
|
void ParameterDevice::sortScrollArea()
|
||||||
{
|
{
|
||||||
//sortParameterBoxesByID(parameterBoxes);
|
|
||||||
//ui->parameterBoxHubContents->layout()->deleteLater();
|
|
||||||
QLayout* pblayout = ui->parameterBoxHubContents->layout();
|
QLayout* pblayout = ui->parameterBoxHubContents->layout();
|
||||||
if (!pblayout) {
|
if(!pblayout) {
|
||||||
// Создайте новый лейаут, если его нет
|
// Создайте новый лейаут, если его нет
|
||||||
pblayout = new QVBoxLayout(ui->parameterBoxHubContents);
|
pblayout = new QVBoxLayout(ui->parameterBoxHubContents);
|
||||||
ui->parameterBoxHubContents->setLayout(pblayout);
|
ui->parameterBoxHubContents->setLayout(pblayout);
|
||||||
}
|
}
|
||||||
QLayoutItem *item;
|
QLayoutItem *item;
|
||||||
while ((item = pblayout->takeAt(0)) != nullptr){
|
while((item = pblayout->takeAt(0)) != nullptr){}
|
||||||
//delete item;
|
for(int i = 0; i < parameterBoxes.count(); i++)
|
||||||
}
|
|
||||||
|
|
||||||
//ui->parameterBoxHubContents->setLayout(pblayout);
|
|
||||||
|
|
||||||
for (int i = 0; i < parameterBoxes.count(); i++) {
|
|
||||||
pblayout->addWidget(parameterBoxes.at(i));
|
pblayout->addWidget(parameterBoxes.at(i));
|
||||||
}
|
|
||||||
|
|
||||||
ui->parameterBoxHubContents->update();
|
ui->parameterBoxHubContents->update();
|
||||||
ui->parameterBoxHubContents->adjustSize();
|
ui->parameterBoxHubContents->adjustSize();
|
||||||
ui->scrollArea->updateGeometry();
|
ui->scrollArea->updateGeometry();
|
||||||
|
|||||||
@ -9,6 +9,7 @@
|
|||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QProgressDialog>
|
#include <QProgressDialog>
|
||||||
|
#include <QElapsedTimer>
|
||||||
|
|
||||||
void sortParameterBoxesByID(QVector<ParameterBox*>& parameterBoxes);
|
void sortParameterBoxesByID(QVector<ParameterBox*>& parameterBoxes);
|
||||||
|
|
||||||
@ -19,7 +20,6 @@ class ParameterDevice;
|
|||||||
class ParameterDevice : public QWidget
|
class ParameterDevice : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum requestMode{
|
enum requestMode{
|
||||||
fullRequest = 0,
|
fullRequest = 0,
|
||||||
@ -37,24 +37,16 @@ signals:
|
|||||||
void writeSingleCoil(int coilAddress, bool value);
|
void writeSingleCoil(int coilAddress, bool value);
|
||||||
void writeSingleRegister(int registerAddress, quint16 value);
|
void writeSingleRegister(int registerAddress, quint16 value);
|
||||||
void transmitEnd();
|
void transmitEnd();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_selectiveRadio_clicked();
|
void on_selectiveRadio_clicked();
|
||||||
|
|
||||||
void on_fullRadio_clicked();
|
void on_fullRadio_clicked();
|
||||||
|
|
||||||
void on_checkButton_clicked();
|
void on_checkButton_clicked();
|
||||||
|
|
||||||
void on_adrSpin_valueChanged(int arg1);
|
void on_adrSpin_valueChanged(int arg1);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void sortScrollArea();
|
void sortScrollArea();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int adr;
|
int adr;
|
||||||
QTimer *updateTimer;
|
|
||||||
QVector<ParameterBox*>parameterBoxes;
|
QVector<ParameterBox*>parameterBoxes;
|
||||||
|
|
||||||
requestMode mode = fullRequest;
|
requestMode mode = fullRequest;
|
||||||
Ui::ParameterDevice *ui;
|
Ui::ParameterDevice *ui;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -6,39 +6,38 @@ ParameterWorkspace::ParameterWorkspace(QWidget *parent) :
|
|||||||
ui(new Ui::ParameterWorkspace)
|
ui(new Ui::ParameterWorkspace)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ParameterWorkspace::~ParameterWorkspace()
|
ParameterWorkspace::~ParameterWorkspace()
|
||||||
{
|
{
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
// QModbusRequest requestOfDeviceType(QModbusRequest::EncapsulatedInterfaceTransport, QByteArray::fromHex("0E0404"));
|
|
||||||
// auto *reply = modbusDevice->sendRawRequest(requestOfDeviceType, tmp_adr);
|
|
||||||
void ParameterWorkspace::setDeviceCount(int count)
|
void ParameterWorkspace::setDeviceCount(int count)
|
||||||
{
|
{
|
||||||
for(const auto& device : deviceList)
|
for(const auto& device : deviceList) {
|
||||||
{
|
|
||||||
device.tab->deleteLater();
|
device.tab->deleteLater();
|
||||||
device.device->deleteLater();
|
device.device->deleteLater();
|
||||||
}
|
}
|
||||||
deviceList.clear();
|
deviceList.clear();
|
||||||
for(int i = 0; i < ui->tabWidget->count(); i++)
|
for(int i = 0; i < ui->tabWidget->count(); i++)
|
||||||
ui->tabWidget->removeTab(i);
|
ui->tabWidget->removeTab(i);
|
||||||
for(int i = 0; i < count; i++)
|
for(int i = 0; i < count; i++) {
|
||||||
{
|
|
||||||
device* _device = new device();
|
device* _device = new device();
|
||||||
deviceList.append(*_device);
|
deviceList.append(*_device);
|
||||||
deviceList[i].device = new ParameterDevice();
|
deviceList[i].device = new ParameterDevice();
|
||||||
int newtab = ui->tabWidget->addTab(deviceList[i].device, tr("Device №%1").arg(i+1));
|
int newtab = ui->tabWidget->addTab(deviceList[i].device, tr("Device №%1").arg(i+1));
|
||||||
deviceList[i].tab = ui->tabWidget->widget(newtab);
|
deviceList[i].tab = ui->tabWidget->widget(newtab);
|
||||||
connect(deviceList[i].device, &ParameterDevice::read, this, [this, i](QModbusRequest request, quint16 objectID){
|
connect(deviceList[i].device, &ParameterDevice::read, this,
|
||||||
|
[this, i](QModbusRequest request, quint16 objectID){
|
||||||
readDeviceIdentification(deviceList[i].device, request, deviceList[i].adr, objectID);
|
readDeviceIdentification(deviceList[i].device, request, deviceList[i].adr, objectID);
|
||||||
});
|
});
|
||||||
connect(deviceList[i].device, &ParameterDevice::writeSingleCoil, this, [this, i](int coilAddress, bool value){
|
connect(deviceList[i].device, &ParameterDevice::writeSingleCoil, this,
|
||||||
|
[this, i](int coilAddress, bool value){
|
||||||
writeSingleCoil(deviceList[i].adr, coilAddress, value);
|
writeSingleCoil(deviceList[i].adr, coilAddress, value);
|
||||||
});
|
});
|
||||||
connect(deviceList[i].device, &ParameterDevice::writeSingleRegister, this, [this, i](int registerAddress, quint16 value){
|
connect(deviceList[i].device, &ParameterDevice::writeSingleRegister, this,
|
||||||
|
[this, i](int registerAddress, quint16 value){
|
||||||
writeSingleRegister(deviceList[i].adr, registerAddress, value);
|
writeSingleRegister(deviceList[i].adr, registerAddress, value);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -46,74 +45,62 @@ void ParameterWorkspace::setDeviceCount(int count)
|
|||||||
|
|
||||||
void ParameterWorkspace::writeSingleCoil(int adr, int coilAddress, bool value)
|
void ParameterWorkspace::writeSingleCoil(int adr, int coilAddress, bool value)
|
||||||
{
|
{
|
||||||
if (!modbusDevice && modbusDevice->state() == QModbusDevice::ConnectedState)
|
if(!modbusDevice && modbusDevice->state() == QModbusDevice::ConnectedState)
|
||||||
return;
|
return;
|
||||||
QModbusDataUnit unit(QModbusDataUnit::Coils, coilAddress, 1);
|
QModbusDataUnit unit(QModbusDataUnit::Coils, coilAddress, 1);
|
||||||
unit.setValue(0, value ? 1 : 0);
|
unit.setValue(0, value ? 1 : 0);
|
||||||
if (auto *reply = modbusDevice->sendWriteRequest(unit, adr)) {
|
if(auto *reply = modbusDevice->sendWriteRequest(unit, adr)) {
|
||||||
if (!reply->isFinished()) {
|
if(!reply->isFinished())
|
||||||
connect(reply, &QModbusReply::finished, this, [this, reply]() {
|
connect(reply, &QModbusReply::finished, this, [reply]() {
|
||||||
if (reply->error() != QModbusDevice::NoError) {
|
if(reply->error() != QModbusDevice::NoError)
|
||||||
//ERROR
|
{/*ERROR*/}
|
||||||
}
|
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
});
|
});
|
||||||
} else {
|
else
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParameterWorkspace::writeSingleRegister(int adr, int regAddress, quint16 value)
|
void ParameterWorkspace::writeSingleRegister(int adr, int regAddress, quint16 value)
|
||||||
{
|
{
|
||||||
if (!modbusDevice && modbusDevice->state() == QModbusDevice::ConnectedState)
|
if(!modbusDevice && modbusDevice->state() == QModbusDevice::ConnectedState)
|
||||||
return;
|
return;
|
||||||
QModbusDataUnit unit(QModbusDataUnit::HoldingRegisters, regAddress, 1);
|
QModbusDataUnit unit(QModbusDataUnit::HoldingRegisters, regAddress, 1);
|
||||||
unit.setValue(0, value);
|
unit.setValue(0, value);
|
||||||
if (auto *reply = modbusDevice->sendWriteRequest(unit, adr)) {
|
if(auto *reply = modbusDevice->sendWriteRequest(unit, adr)) {
|
||||||
if (!reply->isFinished()) {
|
if(!reply->isFinished())
|
||||||
connect(reply, &QModbusReply::finished, this, [this, reply]() {
|
connect(reply, &QModbusReply::finished, this, [reply]() {
|
||||||
if (reply->error() != QModbusDevice::NoError) {
|
if(reply->error() != QModbusDevice::NoError)
|
||||||
//ERROR
|
{/*ERROR*/}
|
||||||
}
|
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
});
|
});
|
||||||
} else {
|
else
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParameterWorkspace::readDeviceIdentification(ParameterDevice *device, QModbusRequest request, int adr, quint16 objectID)
|
void ParameterWorkspace::readDeviceIdentification(ParameterDevice *device, QModbusRequest request, int adr, quint16 objectID)
|
||||||
{
|
{
|
||||||
if (!modbusDevice && modbusDevice->state() == QModbusDevice::ConnectedState)
|
if(!modbusDevice && modbusDevice->state() == QModbusDevice::ConnectedState)
|
||||||
return;
|
return;
|
||||||
if(auto *reply = modbusDevice->sendRawRequest(request, adr))
|
if(auto *reply = modbusDevice->sendRawRequest(request, adr)) {
|
||||||
{
|
if(!reply->isFinished()) {
|
||||||
if (!reply->isFinished()) {
|
connect(reply, &QModbusReply::finished, this, [device, reply, objectID](){
|
||||||
connect(reply, &QModbusReply::finished, this, [this, device, reply, objectID](){
|
if(reply->error() == QModbusDevice::NoError) {
|
||||||
if(reply->error() == QModbusDevice::NoError)
|
|
||||||
{
|
|
||||||
QModbusResponse resp = reply->rawResult();
|
QModbusResponse resp = reply->rawResult();
|
||||||
if(resp.data().size() >= MODBUS_REQUEST_PROTOCOL_INFO_LENGTH)
|
if(resp.data().size() >= MODBUS_REQUEST_PROTOCOL_INFO_LENGTH) {
|
||||||
{
|
|
||||||
QString result = QString(resp.data().remove(0, MODBUS_REQUEST_PROTOCOL_INFO_LENGTH));
|
QString result = QString(resp.data().remove(0, MODBUS_REQUEST_PROTOCOL_INFO_LENGTH));
|
||||||
device->setAnswer(result, objectID);
|
device->setAnswer(result, objectID);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
device->setError(reply->errorString());
|
device->setError(reply->errorString());
|
||||||
qDebug()<<"Получен ответ:" + reply->errorString();
|
qDebug()<<"Получен ответ:" + reply->errorString();
|
||||||
}
|
}
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
{
|
|
||||||
device->setError("Unknow error");
|
device->setError("Unknow error");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParameterWorkspace::updateDevice(int ID, bool status, int adr)
|
void ParameterWorkspace::updateDevice(int ID, bool status, int adr)
|
||||||
|
|||||||
@ -24,7 +24,6 @@ class ParameterWorkspace;
|
|||||||
class ParameterWorkspace : public QWidget
|
class ParameterWorkspace : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ParameterWorkspace(QWidget *parent = nullptr);
|
explicit ParameterWorkspace(QWidget *parent = nullptr);
|
||||||
~ParameterWorkspace();
|
~ParameterWorkspace();
|
||||||
@ -32,12 +31,10 @@ public:
|
|||||||
void setModbusClient(QModbusClient *device){modbusDevice = device;}
|
void setModbusClient(QModbusClient *device){modbusDevice = device;}
|
||||||
void setDeviceCount(int count);
|
void setDeviceCount(int count);
|
||||||
void updateDevice(int deviceID, bool status, int adr);
|
void updateDevice(int deviceID, bool status, int adr);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void readDeviceIdentification(ParameterDevice *board, QModbusRequest request, int adr, quint16 objectID);
|
void readDeviceIdentification(ParameterDevice *board, QModbusRequest request, int adr, quint16 objectID);
|
||||||
void writeSingleCoil(int adr, int coilAddress, bool value);
|
void writeSingleCoil(int adr, int coilAddress, bool value);
|
||||||
void writeSingleRegister(int adr, int registerAddress, quint16 value);
|
void writeSingleRegister(int adr, int registerAddress, quint16 value);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct device{
|
struct device{
|
||||||
bool isActive = false;
|
bool isActive = false;
|
||||||
|
|||||||
@ -14,19 +14,15 @@ class ScanBoard : public QDialog
|
|||||||
public:
|
public:
|
||||||
explicit ScanBoard(QWidget *parent = nullptr);
|
explicit ScanBoard(QWidget *parent = nullptr);
|
||||||
~ScanBoard();
|
~ScanBoard();
|
||||||
|
|
||||||
Qt::CheckState getCheckState();
|
Qt::CheckState getCheckState();
|
||||||
void showMeTheTruth(QString resultOfScan);
|
void showMeTheTruth(QString resultOfScan);
|
||||||
quint16 getBaud();
|
quint16 getBaud();
|
||||||
private slots:
|
private slots:
|
||||||
void on_applyToAllBox_stateChanged(int arg1);
|
void on_applyToAllBox_stateChanged(int arg1);
|
||||||
|
|
||||||
void on_baudRateBox_currentTextChanged(const QString &arg1);
|
void on_baudRateBox_currentTextChanged(const QString &arg1);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Qt::CheckState checkState;
|
Qt::CheckState checkState;
|
||||||
quint16 baud;
|
quint16 baud;
|
||||||
|
|
||||||
Ui::ScanBoard *ui;
|
Ui::ScanBoard *ui;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -19,7 +19,7 @@ SettingsDialog::SettingsDialog(QWidget *parent) :
|
|||||||
#if QT_CONFIG(modbus_serialport)
|
#if QT_CONFIG(modbus_serialport)
|
||||||
m_settings.portName = ui->comBox->currentData().toString();
|
m_settings.portName = ui->comBox->currentData().toString();
|
||||||
m_settings.parity = ui->parityCombo->currentIndex();
|
m_settings.parity = ui->parityCombo->currentIndex();
|
||||||
if (m_settings.parity > 0)
|
if(m_settings.parity > 0)
|
||||||
m_settings.parity++;
|
m_settings.parity++;
|
||||||
m_settings.baud = ui->baudCombo->currentText().toInt();
|
m_settings.baud = ui->baudCombo->currentText().toInt();
|
||||||
m_settings.dataBits = ui->dataBitsCombo->currentText().toInt();
|
m_settings.dataBits = ui->dataBitsCombo->currentText().toInt();
|
||||||
@ -50,11 +50,10 @@ int SettingsDialog::UpdateBaud(int baud)
|
|||||||
int SettingsDialog::UpdateParity(int parity)
|
int SettingsDialog::UpdateParity(int parity)
|
||||||
{
|
{
|
||||||
ui->parityCombo->setCurrentIndex(parity);
|
ui->parityCombo->setCurrentIndex(parity);
|
||||||
if(parity>0) {
|
if(parity > 0)
|
||||||
return (m_settings.parity = ++parity);
|
return (m_settings.parity = ++parity);
|
||||||
} else {
|
else
|
||||||
return (m_settings.parity = parity);
|
return (m_settings.parity = parity);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int SettingsDialog::curBaud()
|
int SettingsDialog::curBaud()
|
||||||
@ -71,7 +70,6 @@ void SettingsDialog::on_updateComBox_clicked()
|
|||||||
{
|
{
|
||||||
ui->comBox->clear();
|
ui->comBox->clear();
|
||||||
const auto listPorts = QSerialPortInfo::availablePorts();
|
const auto listPorts = QSerialPortInfo::availablePorts();
|
||||||
for (const auto& port: listPorts) {
|
for(const auto& port: listPorts)
|
||||||
ui->comBox->addItem(QString(port.portName() + ": " + port.manufacturer()), QVariant(port.portName()));
|
ui->comBox->addItem(QString(port.portName() + ": " + port.manufacturer()), QVariant(port.portName()));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,20 +27,15 @@ public:
|
|||||||
int responseTime = 1000;
|
int responseTime = 1000;
|
||||||
int numberOfRetries = 0;
|
int numberOfRetries = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit SettingsDialog(QWidget *parent = nullptr);
|
explicit SettingsDialog(QWidget *parent = nullptr);
|
||||||
~SettingsDialog();
|
~SettingsDialog();
|
||||||
|
|
||||||
Settings settings() const;
|
Settings settings() const;
|
||||||
|
|
||||||
int UpdateBaud(int baud);
|
int UpdateBaud(int baud);
|
||||||
int UpdateParity(int parity);
|
int UpdateParity(int parity);
|
||||||
|
|
||||||
int curBaud();
|
int curBaud();
|
||||||
int curParity();
|
int curParity();
|
||||||
private slots:
|
private slots:
|
||||||
void on_updateComBox_clicked();
|
void on_updateComBox_clicked();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Settings m_settings;
|
Settings m_settings;
|
||||||
Ui::SettingsDialog *ui;
|
Ui::SettingsDialog *ui;
|
||||||
|
|||||||
@ -1,7 +1,5 @@
|
|||||||
#include "writeregistermodel.h"
|
#include "writeregistermodel.h"
|
||||||
|
|
||||||
#include "writeregistermodel.h"
|
|
||||||
|
|
||||||
enum { NumColumn = 0, NameColumn = 1, CoilsColumn = 2, HoldingColumn = 3, ColumnCount = 5, CurrentUColumn = 4};
|
enum { NumColumn = 0, NameColumn = 1, CoilsColumn = 2, HoldingColumn = 3, ColumnCount = 5, CurrentUColumn = 4};
|
||||||
|
|
||||||
WriteRegisterModel::WriteRegisterModel(QObject *parent, int _tmpRC, bool _isHR)
|
WriteRegisterModel::WriteRegisterModel(QObject *parent, int _tmpRC, bool _isHR)
|
||||||
@ -23,29 +21,29 @@ int WriteRegisterModel::columnCount(const QModelIndex &/*parent*/) const
|
|||||||
|
|
||||||
QVariant WriteRegisterModel::data(const QModelIndex &index, int role) const
|
QVariant WriteRegisterModel::data(const QModelIndex &index, int role) const
|
||||||
{
|
{
|
||||||
if (!index.isValid() || index.row() >= RowCount || index.column() >= ColumnCount)
|
if(!index.isValid() || index.row() >= RowCount || index.column() >= ColumnCount)
|
||||||
return QVariant();
|
return QVariant();
|
||||||
Q_ASSERT(m_coils.count() == RowCount);
|
Q_ASSERT(m_coils.count() == RowCount);
|
||||||
Q_ASSERT(m_holdingRegisters.count() == RowCount);
|
Q_ASSERT(m_holdingRegisters.count() == RowCount);
|
||||||
if (index.column() == NumColumn && role == Qt::DisplayRole)
|
if(index.column() == NumColumn && role == Qt::DisplayRole)
|
||||||
return QString::number(index.row());
|
return QString::number(index.row());
|
||||||
if (index.column() == NameColumn && role == Qt::DisplayRole)
|
if(index.column() == NameColumn && role == Qt::DisplayRole)
|
||||||
return QString("ТЭ%1").arg(index.row()%(RowCount/(1+isHR))+1);
|
return QString("ТЭ%1").arg(index.row()%(RowCount/(1+isHR))+1);
|
||||||
if (index.column() == CoilsColumn && role == Qt::CheckStateRole) // coils
|
if(index.column() == CoilsColumn && role == Qt::CheckStateRole) // coils
|
||||||
return m_coils.at(index.row()) ? Qt::Checked : Qt::Unchecked;
|
return m_coils.at(index.row()) ? Qt::Checked : Qt::Unchecked;
|
||||||
if (index.column() == HoldingColumn && role == Qt::DisplayRole) // holding registers
|
if(index.column() == HoldingColumn && role == Qt::DisplayRole) // holding registers
|
||||||
return QString("%1 В").arg(QString::number((double)((double)m_holdingRegisters.at(index.row())/(double)1000), 'f', 3));
|
return QString("%1 В").arg(QString::number((double)((double)m_holdingRegisters.at(index.row()) / (double)1000), 'f', 3));
|
||||||
if(index.column() == CurrentUColumn && role == Qt::DisplayRole)
|
if(index.column() == CurrentUColumn && role == Qt::DisplayRole)
|
||||||
return QString("%1 В").arg(QString::number((double)((double)m_currentU.at(index.row())/(double)1000), 'f', 3));
|
return QString("%1 В").arg(QString::number((double)((double)m_currentU.at(index.row()) / (double)1000), 'f', 3));
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant WriteRegisterModel::headerData(int section, Qt::Orientation orientation, int role) const
|
QVariant WriteRegisterModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||||
{
|
{
|
||||||
if (role != Qt::DisplayRole)
|
if(role != Qt::DisplayRole)
|
||||||
return QVariant();
|
return QVariant();
|
||||||
if (orientation == Qt::Horizontal) {
|
if(orientation == Qt::Horizontal) {
|
||||||
switch (section) {
|
switch(section) {
|
||||||
case NumColumn:
|
case NumColumn:
|
||||||
return QStringLiteral("#Reg");
|
return QStringLiteral("#Reg");
|
||||||
case NameColumn:
|
case NameColumn:
|
||||||
@ -65,20 +63,20 @@ QVariant WriteRegisterModel::headerData(int section, Qt::Orientation orientation
|
|||||||
|
|
||||||
bool WriteRegisterModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
bool WriteRegisterModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||||
{
|
{
|
||||||
if (!index.isValid() || index.row() >= RowCount || index.column() >= ColumnCount)
|
if(!index.isValid() || index.row() >= RowCount || index.column() >= ColumnCount)
|
||||||
return false;
|
return false;
|
||||||
Q_ASSERT(m_coils.count() == RowCount);
|
Q_ASSERT(m_coils.count() == RowCount);
|
||||||
Q_ASSERT(m_holdingRegisters.count() == RowCount);
|
Q_ASSERT(m_holdingRegisters.count() == RowCount);
|
||||||
if (index.column() == CoilsColumn && role == Qt::CheckStateRole) { // coils
|
if(index.column() == CoilsColumn && role == Qt::CheckStateRole) { // coils
|
||||||
auto s = static_cast<Qt::CheckState>(value.toUInt());
|
auto s = static_cast<Qt::CheckState>(value.toUInt());
|
||||||
s == Qt::Checked ? m_coils.setBit(index.row()) : m_coils.clearBit(index.row());
|
s == Qt::Checked ? m_coils.setBit(index.row()) : m_coils.clearBit(index.row());
|
||||||
emit dataChanged(index, index);
|
emit dataChanged(index, index);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (index.column() == HoldingColumn && role == Qt::EditRole) { // holding registers
|
if(index.column() == HoldingColumn && role == Qt::EditRole) { // holding registers
|
||||||
bool result = false;
|
bool result = false;
|
||||||
quint16 newValue = value.toString().toUShort(&result, 10);
|
quint16 newValue = value.toString().toUShort(&result, 10);
|
||||||
if (result)
|
if(result)
|
||||||
m_holdingRegisters[index.row()] = newValue;
|
m_holdingRegisters[index.row()] = newValue;
|
||||||
emit dataChanged(index, index);
|
emit dataChanged(index, index);
|
||||||
return result;
|
return result;
|
||||||
@ -88,14 +86,14 @@ bool WriteRegisterModel::setData(const QModelIndex &index, const QVariant &value
|
|||||||
|
|
||||||
Qt::ItemFlags WriteRegisterModel::flags(const QModelIndex &index) const
|
Qt::ItemFlags WriteRegisterModel::flags(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
if (!index.isValid() || index.row() >= RowCount || index.column() >= ColumnCount)
|
if(!index.isValid() || index.row() >= RowCount || index.column() >= ColumnCount)
|
||||||
return QAbstractTableModel::flags(index);
|
return QAbstractTableModel::flags(index);
|
||||||
Qt::ItemFlags flags = QAbstractTableModel::flags(index);
|
Qt::ItemFlags flags = QAbstractTableModel::flags(index);
|
||||||
if ((index.row() < m_address) || (index.row() >= (m_address + m_number)))
|
if((index.row() < m_address) || (index.row() >= (m_address + m_number)))
|
||||||
flags &= ~Qt::ItemIsEnabled;
|
flags &= ~Qt::ItemIsEnabled;
|
||||||
if (index.column() == CoilsColumn) // coils
|
if(index.column() == CoilsColumn) // coils
|
||||||
return flags | Qt::ItemIsUserCheckable;
|
return flags | Qt::ItemIsUserCheckable;
|
||||||
if (index.column() == HoldingColumn) // holding registers
|
if(index.column() == HoldingColumn) // holding registers
|
||||||
return flags | Qt::ItemIsEditable;
|
return flags | Qt::ItemIsEditable;
|
||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
@ -103,13 +101,11 @@ Qt::ItemFlags WriteRegisterModel::flags(const QModelIndex &index) const
|
|||||||
void WriteRegisterModel::setStartAddress(int address)
|
void WriteRegisterModel::setStartAddress(int address)
|
||||||
{
|
{
|
||||||
m_address = address;
|
m_address = address;
|
||||||
//emit updateViewport();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WriteRegisterModel::setNumberOfValues(const QString &number)
|
void WriteRegisterModel::setNumberOfValues(const QString &number)
|
||||||
{
|
{
|
||||||
m_number = number.toInt();
|
m_number = number.toInt();
|
||||||
//emit updateViewport();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WriteRegisterModel::get_coil(const QModelIndex &index)
|
bool WriteRegisterModel::get_coil(const QModelIndex &index)
|
||||||
|
|||||||
@ -14,25 +14,18 @@ public:
|
|||||||
WriteRegisterModel(QObject *parent = nullptr, int _tmpRC = 85, bool _isHR = false);
|
WriteRegisterModel(QObject *parent = nullptr, int _tmpRC = 85, bool _isHR = false);
|
||||||
bool get_coil(const QModelIndex &index);
|
bool get_coil(const QModelIndex &index);
|
||||||
uint get_holreg(const QModelIndex &index);
|
uint get_holreg(const QModelIndex &index);
|
||||||
|
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
|
|
||||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||||
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
|
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
|
||||||
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
|
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
|
||||||
|
|
||||||
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||||
|
|
||||||
bool set_currentU(unsigned _tmpU, unsigned index);
|
bool set_currentU(unsigned _tmpU, unsigned index);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setStartAddress(int address);
|
void setStartAddress(int address);
|
||||||
void setNumberOfValues(const QString &number);
|
void setNumberOfValues(const QString &number);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void updateViewport();
|
void updateViewport();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int m_number = 0;
|
int m_number = 0;
|
||||||
int m_address = 0;
|
int m_address = 0;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user