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