Checkpoint to git test
This commit is contained in:
@@ -26,6 +26,7 @@ SOURCES += \
|
|||||||
main.cpp \
|
main.cpp \
|
||||||
m3kte.cpp \
|
m3kte.cpp \
|
||||||
multiplesettings.cpp \
|
multiplesettings.cpp \
|
||||||
|
scanboard.cpp \
|
||||||
settingsdialog.cpp \
|
settingsdialog.cpp \
|
||||||
writeregistermodel.cpp
|
writeregistermodel.cpp
|
||||||
|
|
||||||
@@ -33,6 +34,7 @@ HEADERS += \
|
|||||||
devicesettingsdialog.h \
|
devicesettingsdialog.h \
|
||||||
m3kte.h \
|
m3kte.h \
|
||||||
multiplesettings.h \
|
multiplesettings.h \
|
||||||
|
scanboard.h \
|
||||||
settingsdialog.h \
|
settingsdialog.h \
|
||||||
writeregistermodel.h
|
writeregistermodel.h
|
||||||
|
|
||||||
@@ -40,6 +42,7 @@ FORMS += \
|
|||||||
devicesettingsdialog.ui \
|
devicesettingsdialog.ui \
|
||||||
m3kte.ui \
|
m3kte.ui \
|
||||||
multiplesettings.ui \
|
multiplesettings.ui \
|
||||||
|
scanboard.ui \
|
||||||
settingsdialog.ui
|
settingsdialog.ui
|
||||||
|
|
||||||
# Default rules for deployment.
|
# Default rules for deployment.
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ M3KTE::M3KTE(QWidget *parent)
|
|||||||
, ui(new Ui::M3KTE)
|
, ui(new Ui::M3KTE)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
//Массив указателей на индикаторы напряжения топливных элементов
|
//Массив указателей на индикаторы напряжения топливных элементов
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@@ -342,14 +341,10 @@ M3KTE::M3KTE(QWidget *parent)
|
|||||||
m_ProgressBar[i++] = ui->FuelCellVoltageBar_319;
|
m_ProgressBar[i++] = ui->FuelCellVoltageBar_319;
|
||||||
m_ProgressBar[i++] = ui->FuelCellVoltageBar_320;
|
m_ProgressBar[i++] = ui->FuelCellVoltageBar_320;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
m_settingsDialog = new SettingsDialog(this);
|
m_settingsDialog = new SettingsDialog(this);
|
||||||
|
|
||||||
ui->writeTable->addItem(tr("Exceptions"), QModbusDataUnit::Coils);
|
ui->writeTable->addItem(tr("Exceptions"), QModbusDataUnit::Coils);
|
||||||
ui->writeTable->addItem(tr("Warnings"), QModbusDataUnit::HoldingRegisters);
|
ui->writeTable->addItem(tr("Warnings"), QModbusDataUnit::HoldingRegisters);
|
||||||
ui->writeTable->addItem(tr("Accidents"), QModbusDataUnit::HoldingRegisters);
|
ui->writeTable->addItem(tr("Accidents"), QModbusDataUnit::HoldingRegisters);
|
||||||
|
|
||||||
for(int i = 0; i < 4; i++)
|
for(int i = 0; i < 4; i++)
|
||||||
{
|
{
|
||||||
Boards[i].ModbusModelCoil = new WriteRegisterModel(this, 85 - (i/3*20), false);
|
Boards[i].ModbusModelCoil = new WriteRegisterModel(this, 85 - (i/3*20), false);
|
||||||
@@ -359,57 +354,72 @@ M3KTE::M3KTE(QWidget *parent)
|
|||||||
Boards[i].ModbusModelHoldingReg->setStartAddress(0);
|
Boards[i].ModbusModelHoldingReg->setStartAddress(0);
|
||||||
Boards[i].ModbusModelHoldingReg->setNumberOfValues(QString::number(85-(i/3*20)));
|
Boards[i].ModbusModelHoldingReg->setNumberOfValues(QString::number(85-(i/3*20)));
|
||||||
}
|
}
|
||||||
|
|
||||||
m_deviceSettingsDialog = new DeviceSettingsDialog(this);
|
m_deviceSettingsDialog = new DeviceSettingsDialog(this);
|
||||||
m_regMultipleSettings = new MultipleSettings(this);
|
m_regMultipleSettings = new MultipleSettings(this);
|
||||||
|
|
||||||
modbusDevice = new QModbusRtuSerialMaster(this);
|
modbusDevice = new QModbusRtuSerialMaster(this);
|
||||||
//ui->M3kteRegSettings->setEnabled(false);
|
|
||||||
|
|
||||||
Boards[0].boardScanners = new QTimer();
|
Boards[0].boardScanners = new QTimer();
|
||||||
Boards[1].boardScanners = new QTimer();
|
Boards[1].boardScanners = new QTimer();
|
||||||
Boards[2].boardScanners = new QTimer();
|
Boards[2].boardScanners = new QTimer();
|
||||||
Boards[3].boardScanners = new QTimer();
|
Boards[3].boardScanners = new QTimer();
|
||||||
|
|
||||||
Boards[0].boardScanners->setSingleShot(true);
|
Boards[0].boardScanners->setSingleShot(true);
|
||||||
Boards[1].boardScanners->setSingleShot(true);
|
Boards[1].boardScanners->setSingleShot(true);
|
||||||
Boards[2].boardScanners->setSingleShot(true);
|
Boards[2].boardScanners->setSingleShot(true);
|
||||||
Boards[3].boardScanners->setSingleShot(true);
|
Boards[3].boardScanners->setSingleShot(true);
|
||||||
|
connect(Boards[0].boardScanners, &QTimer::timeout, this, [this]()
|
||||||
connect(Boards[0].boardScanners, &QTimer::timeout, this, &M3KTE::firstBoardScan);
|
{
|
||||||
connect(Boards[1].boardScanners, &QTimer::timeout, this, &M3KTE::secondBoardScan);
|
boardScan(0);
|
||||||
connect(Boards[2].boardScanners, &QTimer::timeout, this, &M3KTE::thirdBoardScan);
|
});
|
||||||
connect(Boards[3].boardScanners, &QTimer::timeout, this, &M3KTE::fourthBoardScan);
|
connect(Boards[1].boardScanners, &QTimer::timeout, this, [this]()
|
||||||
|
{
|
||||||
|
boardScan(1);
|
||||||
|
});
|
||||||
|
connect(Boards[2].boardScanners, &QTimer::timeout, this, [this]()
|
||||||
|
{
|
||||||
|
boardScan(2);
|
||||||
|
});
|
||||||
|
connect(Boards[3].boardScanners, &QTimer::timeout, this, [this]()
|
||||||
|
{
|
||||||
|
boardScan(3);
|
||||||
|
});
|
||||||
Boards[0].adr = 1;
|
Boards[0].adr = 1;
|
||||||
Boards[1].adr = 2;
|
Boards[1].adr = 2;
|
||||||
Boards[2].adr = 3;
|
Boards[2].adr = 3;
|
||||||
Boards[3].adr = 4;
|
Boards[3].adr = 4;
|
||||||
|
ui->M3kteMenuSettings->setEnabled(false);
|
||||||
|
ui->M3kteRegSettings->setEnabled(false);
|
||||||
ui->BSM_Warning->setEnabled(false);
|
ui->BSM_Warning->setEnabled(false);
|
||||||
ui->BSM_Accident->setEnabled(false);
|
ui->BSM_Accident->setEnabled(false);
|
||||||
ui->BSM_WorkInProgress->setEnabled(false);
|
ui->BSM_WorkInProgress->setEnabled(false);
|
||||||
|
|
||||||
initActions();
|
initActions();
|
||||||
|
|
||||||
ui->BST_Off->setChecked(true);
|
ui->BST_Off->setChecked(true);
|
||||||
|
|
||||||
ui->boardSelectBox->setCurrentIndex(0);
|
ui->boardSelectBox->setCurrentIndex(0);
|
||||||
ui->writeTable->setCurrentIndex(0);
|
ui->writeTable->setCurrentIndex(0);
|
||||||
changeTable(0, 0);
|
changeTable(0, 0);
|
||||||
|
Boards_Fields[0] = ui->FCBoardBox;
|
||||||
|
Boards_Fields[1] = ui->FCBoardBox_2;
|
||||||
|
Boards_Fields[2] = ui->FCBoardBox_3;
|
||||||
|
Boards_Fields[3] = ui->FCBoardBox_4;
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
statusM3KTE.Warnings[i] = false;
|
statusM3KTE.Warnings[i] = false;
|
||||||
statusM3KTE.Accidents[i] = false;
|
statusM3KTE.Accidents[i] = false;
|
||||||
|
Boards_Fields[i]->setEnabled(false);
|
||||||
|
}
|
||||||
|
for (int i = 0; i < 5; i++)
|
||||||
|
{
|
||||||
|
ui->writeValueTable->resizeColumnToContents(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
QBrush tb(Qt::transparent); // Transparent brush, solid pattern
|
QBrush tb(Qt::transparent); // Transparent brush, solid pattern
|
||||||
for(int i = 0; i<320; i++)
|
for(int i = 0; i<320; i++)
|
||||||
{
|
{
|
||||||
|
m_ProgressBar[i]->setTextVisible(true);
|
||||||
|
m_ProgressBar[i]->setMinimumSize(25, 25);
|
||||||
|
m_ProgressBar[i]->setMaximumSize(25, 25);
|
||||||
|
m_ProgressBar[i]->resize(25, 25);
|
||||||
|
m_ProgressBar[i]->setAlignment(Qt::AlignCenter);
|
||||||
|
m_ProgressBar[i]->setFormat(QString("%1").arg((i%85+1)));
|
||||||
m_ProgressBar[i]->setValue(3);
|
m_ProgressBar[i]->setValue(3);
|
||||||
QString style_fc_off = "QProgressBar {border: 2px solid black; font: bold 10px} QProgressBar::chunk {background: hsva(" + QString::number(30) + ", 30, 30, 30%);} ";
|
QString style_fc_off = "QProgressBar {border: 2px solid black; font: bold 10px} QProgressBar::chunk {background: hsva(" + QString::number(30) + ", 30, 30, 30%);} ";
|
||||||
m_ProgressBar[i]->setStyleSheet(style_fc_off);
|
m_ProgressBar[i]->setStyleSheet(style_fc_off);
|
||||||
|
|
||||||
ThePhantomMenace[i] = new QPushButton(m_ProgressBar[i]);
|
ThePhantomMenace[i] = new QPushButton(m_ProgressBar[i]);
|
||||||
ThePhantomMenace[i]->setFlat(true);
|
ThePhantomMenace[i]->setFlat(true);
|
||||||
ThePhantomMenace[i]->setPalette(QPalette(tb, tb, tb, tb, tb, tb, tb, tb, tb));
|
ThePhantomMenace[i]->setPalette(QPalette(tb, tb, tb, tb, tb, tb, tb, tb, tb));
|
||||||
@@ -417,16 +427,8 @@ M3KTE::M3KTE(QWidget *parent)
|
|||||||
selectPositionOnTree(i);
|
selectPositionOnTree(i);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
debug();
|
|
||||||
|
|
||||||
connect(m_deviceSettingsDialog, &DeviceSettingsDialog::parityChanged, this, &M3KTE::onParityUpdate);
|
connect(m_deviceSettingsDialog, &DeviceSettingsDialog::parityChanged, this, &M3KTE::onParityUpdate);
|
||||||
connect(m_deviceSettingsDialog, &DeviceSettingsDialog::speedChanged, this, &M3KTE::onSpeedUpdate);
|
connect(m_deviceSettingsDialog, &DeviceSettingsDialog::speedChanged, this, &M3KTE::onSpeedUpdate);
|
||||||
|
|
||||||
|
|
||||||
//Вызов окна настройки подключения
|
|
||||||
|
|
||||||
//Вызов окна настройки устройства
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
M3KTE::~M3KTE()
|
M3KTE::~M3KTE()
|
||||||
@@ -438,56 +440,11 @@ M3KTE::~M3KTE()
|
|||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
void M3KTE::debug()
|
|
||||||
{
|
|
||||||
srand(time(0));
|
|
||||||
for(int i = 0; i < 320; i++)
|
|
||||||
{
|
|
||||||
m_ProgressBar[i]->setTextVisible(true);
|
|
||||||
m_ProgressBar[i]->setMinimumSize(25, 25);
|
|
||||||
m_ProgressBar[i]->setMaximumSize(25, 25);
|
|
||||||
m_ProgressBar[i]->resize(25, 25);
|
|
||||||
m_ProgressBar[i]->setAlignment(Qt::AlignCenter);
|
|
||||||
m_ProgressBar[i]->setFormat(QString("%1").arg((i%85+1)));
|
|
||||||
// int j = rand()%4;
|
|
||||||
// if(j!=3) j=rand()%4;
|
|
||||||
// m_ProgressBar[i]->setValue(j);
|
|
||||||
// QString style_fc = "QProgressBar {border: 2px solid black; font: bold 10px} QProgressBar::chunk {background: hsva(" + QString::number(j*50-50) + ", 255, 255, 100%);} ";
|
|
||||||
// QString style_fc_off = "QProgressBar {border: 2px solid black; font: bold 10px} QProgressBar::chunk {background: hsva(" + QString::number(30) + ", 30, 30, 30%);} ";
|
|
||||||
// m_ProgressBar[i]->setStyleSheet(style_fc);
|
|
||||||
|
|
||||||
// switch (j) {
|
|
||||||
// case 1:
|
|
||||||
// {
|
|
||||||
// m_ProgressBar[i]->setStatusTip(QString("П%1 ТЭ%2: Аварийный уровень напряжения.").arg(QString::number(i/85+1), QString::number(i%85)));
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// case 2:
|
|
||||||
// {
|
|
||||||
// m_ProgressBar[i]->setStatusTip(QString("П%1 ТЭ%2: Предупредительный уровень напряжения.").arg(QString::number(i/85+1), QString::number(i%85)));
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// case 3:
|
|
||||||
// {
|
|
||||||
// m_ProgressBar[i]->setStatusTip(QString("П%1 ТЭ%2: Уровень напряжения в норме.").arg(QString::number(i/85+1), QString::number(i%85)));
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// case 0:
|
|
||||||
// m_ProgressBar[i]->setStatusTip(QString("П%1 ТЭ%2: Топливный Элемент не учитывается.").arg(QString::number(i/85+1), QString::number(i%85)));
|
|
||||||
// m_ProgressBar[i]->setStyleSheet(style_fc_off);
|
|
||||||
// m_ProgressBar[i]->setValue(3);
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void M3KTE::initActions()
|
void M3KTE::initActions()
|
||||||
{
|
{
|
||||||
ui->ConnectionMenuConnect->setEnabled(true);
|
ui->ConnectionMenuConnect->setEnabled(true);
|
||||||
ui->ConnectionMenuDisconnect->setEnabled(false);
|
ui->ConnectionMenuDisconnect->setEnabled(false);
|
||||||
ui->ConnectionMenuSettings->setEnabled(true);
|
ui->ConnectionMenuSettings->setEnabled(true);
|
||||||
|
|
||||||
connect(ui->ConnectionMenuConnect, &QAction::triggered,
|
connect(ui->ConnectionMenuConnect, &QAction::triggered,
|
||||||
this, &M3KTE::onConnectClicked);
|
this, &M3KTE::onConnectClicked);
|
||||||
connect(ui->ConnectionMenuDisconnect, &QAction::triggered,
|
connect(ui->ConnectionMenuDisconnect, &QAction::triggered,
|
||||||
@@ -500,11 +457,9 @@ void M3KTE::initActions()
|
|||||||
this, &M3KTE::onSelectedBoardChanged);
|
this, &M3KTE::onSelectedBoardChanged);
|
||||||
connect(ui->writeTable, QOverload<int>::of(&QComboBox::currentIndexChanged),
|
connect(ui->writeTable, QOverload<int>::of(&QComboBox::currentIndexChanged),
|
||||||
this, &M3KTE::onWriteTableChanged);
|
this, &M3KTE::onWriteTableChanged);
|
||||||
|
|
||||||
connect(ui->M3kteRegSettings, &QAction::triggered, m_regMultipleSettings, &QDialog::show);
|
connect(ui->M3kteRegSettings, &QAction::triggered, m_regMultipleSettings, &QDialog::show);
|
||||||
connect(m_regMultipleSettings, &MultipleSettings::write, this, &M3KTE::slotmultipleRegWrite);
|
connect(m_regMultipleSettings, &MultipleSettings::write, this, &M3KTE::slotmultipleRegWrite);
|
||||||
connect(m_regMultipleSettings, &MultipleSettings::writeAndSend, this, &M3KTE::slotmultipleRegWriteAndSend);
|
connect(m_regMultipleSettings, &MultipleSettings::writeAndSend, this, &M3KTE::slotmultipleRegWriteAndSend);
|
||||||
|
|
||||||
connect(ui->ConnectionMenuSettings, &QAction::triggered, m_settingsDialog, &QDialog::show);
|
connect(ui->ConnectionMenuSettings, &QAction::triggered, m_settingsDialog, &QDialog::show);
|
||||||
connect(ui->M3kteMenuSettings, &QAction::triggered, m_deviceSettingsDialog, &QDialog::show);
|
connect(ui->M3kteMenuSettings, &QAction::triggered, m_deviceSettingsDialog, &QDialog::show);
|
||||||
}
|
}
|
||||||
@@ -513,7 +468,6 @@ void M3KTE::onConnectClicked()
|
|||||||
{
|
{
|
||||||
if (!modbusDevice)
|
if (!modbusDevice)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
statusBar()->clearMessage();
|
statusBar()->clearMessage();
|
||||||
if (modbusDevice->state() != QModbusDevice::ConnectedState) {
|
if (modbusDevice->state() != QModbusDevice::ConnectedState) {
|
||||||
modbusDevice->setConnectionParameter(QModbusDevice::SerialPortNameParameter,
|
modbusDevice->setConnectionParameter(QModbusDevice::SerialPortNameParameter,
|
||||||
@@ -535,37 +489,42 @@ void M3KTE::onConnectClicked()
|
|||||||
} else {
|
} else {
|
||||||
ui->ConnectionMenuConnect->setEnabled(false);
|
ui->ConnectionMenuConnect->setEnabled(false);
|
||||||
ui->ConnectionMenuDisconnect->setEnabled(true);
|
ui->ConnectionMenuDisconnect->setEnabled(true);
|
||||||
|
if(pingNetworkDevices()) //Опрос устройств
|
||||||
if(pingNetworkDevices())
|
|
||||||
{
|
{
|
||||||
unsigned tmp_adr[4];
|
unsigned tmp_adr[4];
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
tmp_adr[i] = Boards[i].adr;
|
tmp_adr[i] = Boards[i].adr;
|
||||||
}
|
}
|
||||||
|
|
||||||
ui->M3kteRegSettings->setEnabled(true);
|
ui->M3kteRegSettings->setEnabled(true);
|
||||||
|
|
||||||
m_deviceSettingsDialog->updateSettingsAfterConnection(m_settingsDialog->settings().baud, m_settingsDialog->settings().parity, tmp_adr, CurrentConnectedDevice);
|
m_deviceSettingsDialog->updateSettingsAfterConnection(m_settingsDialog->settings().baud, m_settingsDialog->settings().parity, tmp_adr, CurrentConnectedDevice);
|
||||||
|
|
||||||
ui->boardSelectBox->setCurrentIndex(0);
|
ui->boardSelectBox->setCurrentIndex(0);
|
||||||
ui->writeTable->setCurrentIndex(0);
|
ui->writeTable->setCurrentIndex(0);
|
||||||
changeTable(0, 0);
|
changeTable(0, 0);
|
||||||
|
ui->M3kteMenuSettings->setEnabled(true);
|
||||||
|
ui->M3kteRegSettings->setEnabled(true);
|
||||||
ui->BST_Off->setChecked(false);
|
ui->BST_Off->setChecked(false);
|
||||||
ui->BST_On->setChecked(true);
|
ui->BST_On->setChecked(true);
|
||||||
|
|
||||||
ui->BSM_Warning->setEnabled(true);
|
ui->BSM_Warning->setEnabled(true);
|
||||||
ui->BSM_Accident->setEnabled(true);
|
ui->BSM_Accident->setEnabled(true);
|
||||||
ui->BSM_WorkInProgress->setEnabled(true);
|
ui->BSM_WorkInProgress->setEnabled(true);
|
||||||
ui->BSM_WorkInProgress->setChecked(true);
|
ui->BSM_WorkInProgress->setChecked(true);
|
||||||
}
|
}
|
||||||
//Опрос устройств
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
QString style_fc_off = "QProgressBar {border: 2px solid black; font: bold 10px} QProgressBar::chunk {background: hsva(" + QString::number(30) + ", 30, 30, 30%);} ";
|
QString style_fc_off = "QProgressBar {border: 2px solid black; font: bold 10px} QProgressBar::chunk {background: hsva(" + QString::number(30) + ", 30, 30, 30%);} ";
|
||||||
for(int i = 0; i < 4; i++)
|
for(int i = 0; i < 4; i++)
|
||||||
{
|
{
|
||||||
Boards[i].boardScanners->stop();
|
Boards[i].boardScanners->stop();
|
||||||
|
Boards_Fields[i]->setEnabled(false);
|
||||||
|
Boards[i].isActive=false;
|
||||||
|
for(int j = 0; j < (85 - (i/3*20)); j++)
|
||||||
|
{
|
||||||
|
Boards[i].coil[j] = false;
|
||||||
|
Boards[i].ModbusModelCoil->m_coils[j]=0;
|
||||||
|
Boards[i].ModbusModelHoldingReg->m_currentU[j]=0;
|
||||||
|
Boards[i].ModbusModelHoldingReg->m_holdingRegisters[j] = 0;
|
||||||
|
Boards[i].ModbusModelHoldingReg->m_holdingRegisters[j + (85 - (i/3*20))] = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for(int i = 0; i < 320; i++)
|
for(int i = 0; i < 320; i++)
|
||||||
{
|
{
|
||||||
@@ -574,21 +533,19 @@ void M3KTE::onConnectClicked()
|
|||||||
m_ProgressBar[i]->setValue(3);
|
m_ProgressBar[i]->setValue(3);
|
||||||
m_ProgressBar[i]->setStyleSheet(style_fc_off);
|
m_ProgressBar[i]->setStyleSheet(style_fc_off);
|
||||||
}
|
}
|
||||||
|
|
||||||
modbusDevice->disconnectDevice();
|
modbusDevice->disconnectDevice();
|
||||||
|
ui->M3kteMenuSettings->setEnabled(false);
|
||||||
|
ui->M3kteRegSettings->setEnabled(false);
|
||||||
ui->ConnectionMenuConnect->setEnabled(true);
|
ui->ConnectionMenuConnect->setEnabled(true);
|
||||||
ui->ConnectionMenuDisconnect->setEnabled(false);
|
ui->ConnectionMenuDisconnect->setEnabled(false);
|
||||||
ui->BST_Off->setChecked(true);
|
ui->BST_Off->setChecked(true);
|
||||||
ui->BST_On->setChecked(false);
|
ui->BST_On->setChecked(false);
|
||||||
|
|
||||||
ui->BSM_Warning->setChecked(false);
|
ui->BSM_Warning->setChecked(false);
|
||||||
ui->BSM_Accident->setChecked(false);
|
ui->BSM_Accident->setChecked(false);
|
||||||
ui->BSM_WorkInProgress->setChecked(false);
|
ui->BSM_WorkInProgress->setChecked(false);
|
||||||
|
|
||||||
ui->BSM_Warning->setEnabled(false);
|
ui->BSM_Warning->setEnabled(false);
|
||||||
ui->BSM_Accident->setEnabled(false);
|
ui->BSM_Accident->setEnabled(false);
|
||||||
ui->BSM_WorkInProgress->setEnabled(false);
|
ui->BSM_WorkInProgress->setEnabled(false);
|
||||||
|
|
||||||
ui->M3kteRegSettings->setEnabled(false);
|
ui->M3kteRegSettings->setEnabled(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -597,10 +554,7 @@ void M3KTE::onReadButtonClicked()
|
|||||||
{
|
{
|
||||||
if (!modbusDevice)
|
if (!modbusDevice)
|
||||||
return;
|
return;
|
||||||
//ui->readValue->clear();
|
|
||||||
statusBar()->clearMessage();
|
statusBar()->clearMessage();
|
||||||
|
|
||||||
|
|
||||||
if (auto *reply = modbusDevice->sendReadRequest(readRequest(), Boards[ui->boardSelectBox->currentIndex()].adr)) {
|
if (auto *reply = modbusDevice->sendReadRequest(readRequest(), Boards[ui->boardSelectBox->currentIndex()].adr)) {
|
||||||
if (!reply->isFinished())
|
if (!reply->isFinished())
|
||||||
connect(reply, &QModbusReply::finished, this, &M3KTE::onReadReady);
|
connect(reply, &QModbusReply::finished, this, &M3KTE::onReadReady);
|
||||||
@@ -609,22 +563,6 @@ void M3KTE::onReadButtonClicked()
|
|||||||
} else {
|
} else {
|
||||||
statusBar()->showMessage(tr("Read error: ") + modbusDevice->errorString(), 5000);
|
statusBar()->showMessage(tr("Read error: ") + modbusDevice->errorString(), 5000);
|
||||||
}
|
}
|
||||||
// if (auto *reply = modbusDevice->sendReadRequest(readRequest(), ui->serverEdit->value())) {
|
|
||||||
// if (!reply->isFinished())
|
|
||||||
// connect(reply, &QModbusReply::finished, this, &M3KTE::onReadReady);
|
|
||||||
// else
|
|
||||||
// delete reply; // broadcast replies return immediately
|
|
||||||
// } else {
|
|
||||||
// statusBar()->showMessage(tr("Read error: ") + modbusDevice->errorString(), 5000);
|
|
||||||
// }
|
|
||||||
// if (auto *reply = modbusDevice->sendReadRequest(readRequest(), ui->serverEdit->value())) {
|
|
||||||
// if (!reply->isFinished())
|
|
||||||
// connect(reply, &QModbusReply::finished, this, &M3KTE::onReadReady);
|
|
||||||
// else
|
|
||||||
// delete reply; // broadcast replies return immediately
|
|
||||||
// } else {
|
|
||||||
// statusBar()->showMessage(tr("Read error: ") + modbusDevice->errorString(), 5000);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void M3KTE::onReadReady()
|
void M3KTE::onReadReady()
|
||||||
@@ -632,7 +570,6 @@ void M3KTE::onReadReady()
|
|||||||
auto reply = qobject_cast<QModbusReply *>(sender());
|
auto reply = qobject_cast<QModbusReply *>(sender());
|
||||||
if (!reply)
|
if (!reply)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (reply->error() == QModbusDevice::NoError) {
|
if (reply->error() == QModbusDevice::NoError) {
|
||||||
const QModbusDataUnit unit = reply->result();
|
const QModbusDataUnit unit = reply->result();
|
||||||
int Adr = 255;
|
int Adr = 255;
|
||||||
@@ -645,10 +582,8 @@ void M3KTE::onReadReady()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int i = 0, total = int(unit.valueCount()); i < total; ++i) {
|
for (int i = 0, total = int(unit.valueCount()); i < total; ++i) {
|
||||||
//ui->readValue->addItem(entry);
|
|
||||||
if(unit.registerType() == QModbusDataUnit::Coils)
|
if(unit.registerType() == QModbusDataUnit::Coils)
|
||||||
{
|
{
|
||||||
//QStandardItem *item = ui->writeValueTable->model()->item
|
|
||||||
Boards[Adr].coil[i + unit.startAddress()] = unit.value(i);
|
Boards[Adr].coil[i + unit.startAddress()] = unit.value(i);
|
||||||
if(unit.value(i)==1)
|
if(unit.value(i)==1)
|
||||||
Boards[Adr].ModbusModelCoil->setData(ui->writeValueTable->model()->index(i + unit.startAddress(), 2), Qt::Checked, Qt::CheckStateRole);
|
Boards[Adr].ModbusModelCoil->setData(ui->writeValueTable->model()->index(i + unit.startAddress(), 2), Qt::Checked, Qt::CheckStateRole);
|
||||||
@@ -670,7 +605,6 @@ void M3KTE::onReadReady()
|
|||||||
arg(reply->errorString()).
|
arg(reply->errorString()).
|
||||||
arg(reply->error(), -1, 16), 5000);
|
arg(reply->error(), -1, 16), 5000);
|
||||||
}
|
}
|
||||||
|
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -679,7 +613,6 @@ void M3KTE::onWriteButtonClicked()
|
|||||||
if (!modbusDevice)
|
if (!modbusDevice)
|
||||||
return;
|
return;
|
||||||
statusBar()->clearMessage();
|
statusBar()->clearMessage();
|
||||||
|
|
||||||
QModbusDataUnit writeUnit = writeRequest();
|
QModbusDataUnit writeUnit = writeRequest();
|
||||||
QModbusDataUnit::RegisterType table = writeUnit.registerType();
|
QModbusDataUnit::RegisterType table = writeUnit.registerType();
|
||||||
for (int i = 0, total = int(writeUnit.valueCount()); i < total; ++i) {
|
for (int i = 0, total = int(writeUnit.valueCount()); i < total; ++i) {
|
||||||
@@ -694,7 +627,6 @@ void M3KTE::onWriteButtonClicked()
|
|||||||
writeUnit.setValue(i, Boards[ui->boardSelectBox->currentIndex()].ModbusModelHoldingReg->m_holdingRegisters[i + writeUnit.startAddress()]);
|
writeUnit.setValue(i, Boards[ui->boardSelectBox->currentIndex()].ModbusModelHoldingReg->m_holdingRegisters[i + writeUnit.startAddress()]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (auto *reply = modbusDevice->sendWriteRequest(writeUnit, Boards[ui->boardSelectBox->currentIndex()].adr)) {
|
if (auto *reply = modbusDevice->sendWriteRequest(writeUnit, Boards[ui->boardSelectBox->currentIndex()].adr)) {
|
||||||
if (!reply->isFinished()) {
|
if (!reply->isFinished()) {
|
||||||
connect(reply, &QModbusReply::finished, this, [this, reply]() {
|
connect(reply, &QModbusReply::finished, this, [this, reply]() {
|
||||||
@@ -729,7 +661,6 @@ void M3KTE::onWriteTableChanged(int index)
|
|||||||
|
|
||||||
void M3KTE::changeTable(int board, int tabletype)
|
void M3KTE::changeTable(int board, int tabletype)
|
||||||
{
|
{
|
||||||
|
|
||||||
if(tabletype==0)
|
if(tabletype==0)
|
||||||
{
|
{
|
||||||
ui->writeValueTable->setModel(Boards[board].ModbusModelCoil);
|
ui->writeValueTable->setModel(Boards[board].ModbusModelCoil);
|
||||||
@@ -771,17 +702,18 @@ void M3KTE::changeTable(int board, int tabletype)
|
|||||||
ui->writeValueTable->hideColumn(2);
|
ui->writeValueTable->hideColumn(2);
|
||||||
ui->writeValueTable->showColumn(3);
|
ui->writeValueTable->showColumn(3);
|
||||||
}
|
}
|
||||||
|
for (int i = 0; i < 5; i++)
|
||||||
|
{
|
||||||
|
ui->writeValueTable->resizeColumnToContents(i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QModbusDataUnit M3KTE::readRequest() const
|
QModbusDataUnit M3KTE::readRequest() const
|
||||||
{
|
{
|
||||||
const auto table =
|
const auto table =
|
||||||
static_cast<QModbusDataUnit::RegisterType>(ui->writeTable->currentData().toInt());
|
static_cast<QModbusDataUnit::RegisterType>(ui->writeTable->currentData().toInt());
|
||||||
|
|
||||||
int startAddress = 85 * (ui->writeTable->currentIndex()/2);
|
int startAddress = 85 * (ui->writeTable->currentIndex()/2);
|
||||||
Q_ASSERT(startAddress >= 0 && startAddress < 340);
|
Q_ASSERT(startAddress >= 0 && startAddress < 340);
|
||||||
|
|
||||||
// do not go beyond 10 entries
|
|
||||||
quint16 numberOfEntries = qMin((ushort)(85 - (ui->boardSelectBox->currentIndex()/3*20)), quint16(340 - startAddress));
|
quint16 numberOfEntries = qMin((ushort)(85 - (ui->boardSelectBox->currentIndex()/3*20)), quint16(340 - startAddress));
|
||||||
return QModbusDataUnit(table, startAddress, numberOfEntries);
|
return QModbusDataUnit(table, startAddress, numberOfEntries);
|
||||||
}
|
}
|
||||||
@@ -790,11 +722,8 @@ QModbusDataUnit M3KTE::writeRequest() const
|
|||||||
{
|
{
|
||||||
const auto table =
|
const auto table =
|
||||||
static_cast<QModbusDataUnit::RegisterType>(ui->writeTable->currentData().toInt());
|
static_cast<QModbusDataUnit::RegisterType>(ui->writeTable->currentData().toInt());
|
||||||
|
|
||||||
int startAddress = 85 * (ui->writeTable->currentIndex()/2);
|
int startAddress = 85 * (ui->writeTable->currentIndex()/2);
|
||||||
Q_ASSERT(startAddress >= 0 && startAddress < 340);
|
Q_ASSERT(startAddress >= 0 && startAddress < 340);
|
||||||
|
|
||||||
// do not go beyond 10 entries
|
|
||||||
quint16 numberOfEntries = qMin((ushort)(85 - (ui->boardSelectBox->currentIndex()/3*20)), quint16(340 - startAddress));
|
quint16 numberOfEntries = qMin((ushort)(85 - (ui->boardSelectBox->currentIndex()/3*20)), quint16(340 - startAddress));
|
||||||
return QModbusDataUnit(table, startAddress, numberOfEntries);
|
return QModbusDataUnit(table, startAddress, numberOfEntries);
|
||||||
}
|
}
|
||||||
@@ -806,6 +735,7 @@ bool M3KTE::event(QEvent *event)
|
|||||||
BoardIdHasBeenChanged* _event = static_cast<BoardIdHasBeenChanged*>(event);
|
BoardIdHasBeenChanged* _event = static_cast<BoardIdHasBeenChanged*>(event);
|
||||||
QModbusDataUnit* _unit = new QModbusDataUnit(QModbusDataUnit::HoldingRegisters, 172, 1);
|
QModbusDataUnit* _unit = new QModbusDataUnit(QModbusDataUnit::HoldingRegisters, 172, 1);
|
||||||
_unit->setValue(0, _event->BoardNewID());
|
_unit->setValue(0, _event->BoardNewID());
|
||||||
|
Boards[_event->BoardNum()]._tmp_adr = _event->BoardNewID();
|
||||||
if (auto *reply = modbusDevice->sendWriteRequest(*_unit, Boards[_event->BoardNum()].adr))
|
if (auto *reply = modbusDevice->sendWriteRequest(*_unit, Boards[_event->BoardNum()].adr))
|
||||||
{
|
{
|
||||||
if(!reply->isFinished())
|
if(!reply->isFinished())
|
||||||
@@ -816,7 +746,10 @@ bool M3KTE::event(QEvent *event)
|
|||||||
if (auto *subreply = modbusDevice->sendReadRequest(*_unit, Boards[_event->BoardNum()]._tmp_adr))
|
if (auto *subreply = modbusDevice->sendReadRequest(*_unit, Boards[_event->BoardNum()]._tmp_adr))
|
||||||
{
|
{
|
||||||
if (!subreply->isFinished())
|
if (!subreply->isFinished())
|
||||||
connect(subreply, &QModbusReply::finished, this, &M3KTE::checkAdrChange);
|
connect(subreply, &QModbusReply::finished, this, [subreply, this, _event]()
|
||||||
|
{
|
||||||
|
checkAdrChange(subreply, _event->BoardNum());
|
||||||
|
});
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
errorAdrChange();
|
errorAdrChange();
|
||||||
@@ -833,6 +766,7 @@ bool M3KTE::event(QEvent *event)
|
|||||||
});
|
});
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
errorAdrChange();
|
||||||
delete reply;
|
delete reply;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -840,43 +774,34 @@ bool M3KTE::event(QEvent *event)
|
|||||||
{
|
{
|
||||||
errorAdrChange();
|
errorAdrChange();
|
||||||
}
|
}
|
||||||
// if (auto *reply = modbusDevice->sendReadRequest(*_unit, Boards[_event->BoardNum()]._tmp_adr))
|
|
||||||
// {
|
|
||||||
// if (!reply->isFinished())
|
|
||||||
// connect(reply, &QModbusReply::finished, this, &M3KTE::checkAdrChange);
|
|
||||||
// else
|
|
||||||
// delete reply; // broadcast replies return immediately
|
|
||||||
// } else {
|
|
||||||
// errorAdrChange();
|
|
||||||
// }
|
|
||||||
m_deviceSettingsDialog->show();
|
m_deviceSettingsDialog->show();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return QWidget::event(event);
|
return QWidget::event(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void M3KTE::checkAdrChange()
|
void M3KTE::checkAdrChange(QModbusReply *reply, unsigned boardNum)
|
||||||
{
|
{
|
||||||
auto reply = qobject_cast<QModbusReply *>(sender());
|
|
||||||
if (!reply)
|
if (!reply)
|
||||||
{
|
{
|
||||||
errorAdrChange();
|
errorAdrChange();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (reply->error() == QModbusDevice::NoError) {
|
if (reply->error() == QModbusDevice::NoError) {
|
||||||
for (int i = 0; i < CurrentConnectedDevice; i++) {
|
if(Boards[boardNum]._tmp_adr == reply->serverAddress())
|
||||||
if(Boards[i]._tmp_adr == reply->serverAddress())
|
{
|
||||||
{
|
//OK
|
||||||
//OK
|
Boards[boardNum].adr = Boards[boardNum]._tmp_adr;
|
||||||
Boards[i].adr = Boards[i]._tmp_adr;
|
reply->deleteLater();
|
||||||
reply->deleteLater();
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
//ERROR
|
//ERROR
|
||||||
errorAdrChange();
|
else{
|
||||||
|
Boards[boardNum]._tmp_adr = Boards[boardNum].adr;
|
||||||
|
errorAdrChange();
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
errorAdrChange();
|
errorAdrChange();
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
@@ -894,7 +819,6 @@ void M3KTE::errorAdrChange()
|
|||||||
void M3KTE::onSpeedUpdate()
|
void M3KTE::onSpeedUpdate()
|
||||||
{
|
{
|
||||||
//Отсутствие контроля записи регистра на плате.
|
//Отсутствие контроля записи регистра на плате.
|
||||||
|
|
||||||
QModbusDataUnit* _unit = new QModbusDataUnit(QModbusDataUnit::HoldingRegisters, 173, 1);
|
QModbusDataUnit* _unit = new QModbusDataUnit(QModbusDataUnit::HoldingRegisters, 173, 1);
|
||||||
_unit->setValue(0, m_deviceSettingsDialog->currentSpeed());
|
_unit->setValue(0, m_deviceSettingsDialog->currentSpeed());
|
||||||
for (int i = 0; i < CurrentConnectedDevice; i++) {
|
for (int i = 0; i < CurrentConnectedDevice; i++) {
|
||||||
@@ -938,21 +862,17 @@ void M3KTE::onSpeedUpdate()
|
|||||||
msgBox.setDefaultButton(QMessageBox::Ok);
|
msgBox.setDefaultButton(QMessageBox::Ok);
|
||||||
int ret = msgBox.exec();
|
int ret = msgBox.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
else
|
else
|
||||||
delete reply; // broadcast replies return immediately
|
delete reply; // broadcast replies return immediately
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void M3KTE::onParityUpdate()
|
void M3KTE::onParityUpdate()
|
||||||
{
|
{
|
||||||
//Отсутствие контроля записи регистра на плате.
|
//Отсутствие контроля записи регистра на плате.
|
||||||
|
|
||||||
QModbusDataUnit* _unit = new QModbusDataUnit(QModbusDataUnit::HoldingRegisters, 174, 1);
|
QModbusDataUnit* _unit = new QModbusDataUnit(QModbusDataUnit::HoldingRegisters, 174, 1);
|
||||||
switch (m_deviceSettingsDialog->currentParity())
|
switch (m_deviceSettingsDialog->currentParity())
|
||||||
{
|
{
|
||||||
@@ -1023,13 +943,9 @@ void M3KTE::onParityUpdate()
|
|||||||
|
|
||||||
bool M3KTE::pingNetworkDevices()
|
bool M3KTE::pingNetworkDevices()
|
||||||
{
|
{
|
||||||
int i=0;
|
CurrentConnectedDevice = 0;
|
||||||
QTimer *timer = new QTimer(this);
|
|
||||||
connect(timer, &QTimer::timeout, this, &M3KTE::timeForPingIsGone);
|
|
||||||
timer->setSingleShot(true);
|
|
||||||
QModbusDataUnit* _unit = new QModbusDataUnit(QModbusDataUnit::InputRegisters, 85, 1);
|
QModbusDataUnit* _unit = new QModbusDataUnit(QModbusDataUnit::InputRegisters, 85, 1);
|
||||||
int tmp_adr = 1;
|
int tmp_adr = 1;
|
||||||
|
|
||||||
bool isRun = false;
|
bool isRun = false;
|
||||||
bool *tmp_isRun = &isRun;
|
bool *tmp_isRun = &isRun;
|
||||||
auto bar = new QProgressDialog(this);
|
auto bar = new QProgressDialog(this);
|
||||||
@@ -1037,34 +953,36 @@ bool M3KTE::pingNetworkDevices()
|
|||||||
{
|
{
|
||||||
*tmp_isRun = true;
|
*tmp_isRun = true;
|
||||||
});
|
});
|
||||||
bar->setLabelText(tr("Поиск плат..."));
|
bar->setLabelText(tr("Поиск плат... Текущий адрес: %1").arg(tmp_adr));
|
||||||
bar->setCancelButton(nullptr);
|
bar->setCancelButton(nullptr);
|
||||||
bar->setRange(0, 4);
|
bar->setRange(0, 4);
|
||||||
bar->setMinimumDuration(100);
|
bar->setMinimumDuration(100);
|
||||||
bar->setValue(i);
|
bar->setValue(CurrentConnectedDevice);
|
||||||
|
modbusDevice->setNumberOfRetries(0);
|
||||||
|
|
||||||
CurrentConnectedDevice = 0;
|
QModbusRequest requestOfDeviceType(QModbusRequest::EncapsulatedInterfaceTransport, QByteArray::fromHex("0E0404"));
|
||||||
|
QModbusRequest requestOfBoardID(QModbusRequest::EncapsulatedInterfaceTransport, QByteArray::fromHex("0E0401"));
|
||||||
|
|
||||||
for(i=0; i<4;)
|
modbusDevice->setTimeout(50);
|
||||||
|
for(CurrentConnectedDevice=0; CurrentConnectedDevice<4;)
|
||||||
{
|
{
|
||||||
|
auto *reply = modbusDevice->sendRawRequest(requestOfDeviceType, tmp_adr);
|
||||||
if(isRun && CurrentConnectedDevice < 1)
|
//auto *reply = modbusDevice->sendReadRequest(*_unit, tmp_adr);
|
||||||
|
//Запрос типа устройства.
|
||||||
|
if(reply == nullptr)
|
||||||
{
|
{
|
||||||
onConnectClicked();
|
onConnectClicked();
|
||||||
|
bar->close();
|
||||||
|
bar->deleteLater();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else if(isRun)
|
while(!reply->isFinished())
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
timerForPingSignal = false;
|
|
||||||
timer->start(m_settingsDialog->settings().responseTime);
|
|
||||||
auto *reply = modbusDevice->sendReadRequest(*_unit, tmp_adr);
|
|
||||||
while(!reply->isFinished() && !timerForPingSignal)
|
|
||||||
{
|
{
|
||||||
if(isRun && CurrentConnectedDevice < 1)
|
if(isRun && CurrentConnectedDevice < 1)
|
||||||
{
|
{
|
||||||
onConnectClicked();
|
onConnectClicked();
|
||||||
|
bar->close();
|
||||||
|
bar->deleteLater();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else if(isRun)
|
else if(isRun)
|
||||||
@@ -1073,20 +991,73 @@ bool M3KTE::pingNetworkDevices()
|
|||||||
}
|
}
|
||||||
QCoreApplication::processEvents();
|
QCoreApplication::processEvents();
|
||||||
}
|
}
|
||||||
if(timerForPingSignal)
|
if(isRun && CurrentConnectedDevice < 1)
|
||||||
{
|
{
|
||||||
|
onConnectClicked();
|
||||||
|
bar->close();
|
||||||
|
bar->deleteLater();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else if(isRun)
|
||||||
{
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (!isRun)
|
||||||
|
{
|
||||||
|
//Нужна проверка типа устройства
|
||||||
if(reply->error()==QModbusDevice::NoError)
|
if(reply->error()==QModbusDevice::NoError)
|
||||||
{
|
{
|
||||||
timer->stop();
|
QModbusResponse resp = reply->rawResult();
|
||||||
CurrentConnectedDevice++;
|
QString result = QString(resp.data().remove(0, MODBUS_REQUEST_PROTOCOL_INFO_LENGTH));
|
||||||
Boards[i].adr = Boards[i]._tmp_adr = tmp_adr;
|
//result.remove(0, MODBUS_REQUEST_PROTOCOL_INFO_LENGTH);
|
||||||
statusBar()->showMessage(tr("Плата %1 найдена по адресу %2.").arg(i).arg(tmp_adr), m_settingsDialog->settings().responseTime);
|
if(result == QString("KTE"))
|
||||||
i++;
|
{
|
||||||
bar->setValue(i);
|
auto *subreply = modbusDevice->sendRawRequest(requestOfBoardID, tmp_adr);
|
||||||
|
while(!subreply->isFinished())
|
||||||
|
{
|
||||||
|
if(isRun && CurrentConnectedDevice < 1)
|
||||||
|
{
|
||||||
|
onConnectClicked();
|
||||||
|
bar->close();
|
||||||
|
bar->deleteLater();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else if(isRun)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
QCoreApplication::processEvents();
|
||||||
|
}
|
||||||
|
if(isRun && CurrentConnectedDevice < 1)
|
||||||
|
{
|
||||||
|
onConnectClicked();
|
||||||
|
bar->close();
|
||||||
|
bar->deleteLater();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else if(isRun)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//QString boardID(subreply->rawResult().data());
|
||||||
|
//boardID.remove(0, MODBUS_REQUEST_PROTOCOL_INFO_LENGTH);
|
||||||
|
if(Boards[(int)(subreply->rawResult().data().at(MODBUS_REQUEST_PROTOCOL_INFO_LENGTH))-1].isActive)
|
||||||
|
{
|
||||||
|
QMessageBox::warning(this, "Ошибка при сканировании сети.", QString("Платы по адресам %1 и %2 имеют одинаковый ID %3").arg(Boards[(int)subreply->rawResult().data().at(MODBUS_REQUEST_PROTOCOL_INFO_LENGTH)].adr).arg(tmp_adr).arg((int)subreply->rawResult().data().at(MODBUS_REQUEST_PROTOCOL_INFO_LENGTH)));
|
||||||
|
onConnectClicked();
|
||||||
|
bar->close();
|
||||||
|
bar->deleteLater();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
CurrentConnectedDevice++;
|
||||||
|
Boards[(int)(subreply->rawResult().data().at(MODBUS_REQUEST_PROTOCOL_INFO_LENGTH))-1].adr = Boards[(int)(subreply->rawResult().data().at(MODBUS_REQUEST_PROTOCOL_INFO_LENGTH))-1]._tmp_adr = tmp_adr;
|
||||||
|
statusBar()->showMessage(tr("Плата %1 найдена по адресу %2.").arg((int)(subreply->rawResult().data().at(MODBUS_REQUEST_PROTOCOL_INFO_LENGTH))-1).arg(tmp_adr), m_settingsDialog->settings().responseTime);
|
||||||
|
Boards[(int)(subreply->rawResult().data().at(MODBUS_REQUEST_PROTOCOL_INFO_LENGTH))-1].isActive = true;
|
||||||
|
bar->setValue(CurrentConnectedDevice);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tmp_adr++;
|
tmp_adr++;
|
||||||
@@ -1095,8 +1066,9 @@ bool M3KTE::pingNetworkDevices()
|
|||||||
{
|
{
|
||||||
//ERROR
|
//ERROR
|
||||||
//OUT OF RANGE
|
//OUT OF RANGE
|
||||||
QMessageBox::warning(this, "Ошибка при сканировании сети.", QString("Выход за пределы допустимых адресов. Найдено %1 плат.").arg(i));
|
QMessageBox::warning(this, "Ошибка при сканировании сети.", QString("Выход за пределы допустимых адресов. Найдено %1 плат.").arg(CurrentConnectedDevice));
|
||||||
bar->setValue(4);
|
bar->setValue(4);
|
||||||
|
bar->close();
|
||||||
bar->deleteLater();
|
bar->deleteLater();
|
||||||
onConnectClicked();
|
onConnectClicked();
|
||||||
return false;
|
return false;
|
||||||
@@ -1107,207 +1079,116 @@ bool M3KTE::pingNetworkDevices()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
isRun=false;
|
isRun=false;
|
||||||
QMessageBox::warning(this, "Сканирование сети завершено.", tr("Найдено плат: %1 из 4.").arg(i));
|
QMessageBox::warning(this, "Сканирование сети завершено.", tr("Найдено плат: %1 из 4.").arg(CurrentConnectedDevice));
|
||||||
if(isRun)
|
if(isRun)
|
||||||
{
|
{
|
||||||
|
QMessageBox::warning(this, "Ошибка при получении текущих настроек.", QString("Прерывание по запросу пользователя."));
|
||||||
onConnectClicked();
|
onConnectClicked();
|
||||||
|
bar->close();
|
||||||
|
bar->deleteLater();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
modbusDevice->setTimeout(m_settingsDialog->settings().responseTime);
|
||||||
bar->setLabelText(tr("Считывание текущих настроек..."));
|
bar->setLabelText(tr("Считывание текущих настроек..."));
|
||||||
|
|
||||||
bar->setRange(0, CurrentConnectedDevice*3);
|
bar->setRange(0, CurrentConnectedDevice*3);
|
||||||
QModbusDataUnit* _unit_settings[3];
|
QModbusDataUnit* _unit_settings[3];
|
||||||
_unit_settings[0] = new QModbusDataUnit(QModbusDataUnit::Coils, 0, 85);
|
_unit_settings[0] = new QModbusDataUnit(QModbusDataUnit::Coils, 0, 85);
|
||||||
_unit_settings[1] = new QModbusDataUnit(QModbusDataUnit::HoldingRegisters, 0, 85);
|
_unit_settings[1] = new QModbusDataUnit(QModbusDataUnit::HoldingRegisters, 0, 85);
|
||||||
_unit_settings[2] = new QModbusDataUnit(QModbusDataUnit::HoldingRegisters, 85, 85);
|
_unit_settings[2] = new QModbusDataUnit(QModbusDataUnit::HoldingRegisters, 85, 85);
|
||||||
|
for(int i=0; i<4; i++)
|
||||||
for(i=0; i<CurrentConnectedDevice; i++)
|
|
||||||
{
|
{
|
||||||
for (int j = 0; j<3; j++)
|
if(Boards[i].isActive)
|
||||||
{
|
{
|
||||||
bar->setValue(i*3+j);
|
Boards_Fields[i]->setEnabled(true);
|
||||||
if(isRun)
|
for (int j = 0; j<3; j++)
|
||||||
{
|
|
||||||
onConnectClicked();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
timerForPingSignal = false;
|
|
||||||
timer->start(m_settingsDialog->settings().responseTime);
|
|
||||||
auto *reply = modbusDevice->sendReadRequest(*_unit_settings[j], Boards[i].adr);
|
|
||||||
while(!reply->isFinished() && !timerForPingSignal)
|
|
||||||
{
|
{
|
||||||
|
bar->setValue(i*3+j);
|
||||||
if(isRun)
|
if(isRun)
|
||||||
{
|
{
|
||||||
onConnectClicked();
|
onConnectClicked();
|
||||||
|
bar->close();
|
||||||
|
bar->deleteLater();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
QCoreApplication::processEvents();
|
auto *reply = modbusDevice->sendReadRequest(*_unit_settings[j], Boards[i].adr);
|
||||||
}
|
if(!reply)
|
||||||
if(timerForPingSignal)
|
{
|
||||||
{
|
onConnectClicked();
|
||||||
QMessageBox::warning(this, "Ошибка при получении текущих настроек.", QString("Таймаут при опросе устройства %1 по адресу %2").arg(i).arg(Boards[i].adr));
|
bar->close();
|
||||||
onConnectClicked();
|
bar->deleteLater();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
while(!reply->isFinished())
|
||||||
{
|
{
|
||||||
|
if(isRun)
|
||||||
|
{
|
||||||
|
QMessageBox::warning(this, "Ошибка при получении текущих настроек.", QString("Прерывание по запросу пользователя."));
|
||||||
|
onConnectClicked();
|
||||||
|
bar->close();
|
||||||
|
bar->deleteLater();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
QCoreApplication::processEvents();
|
||||||
|
}
|
||||||
if(reply->error()==QModbusDevice::NoError)
|
if(reply->error()==QModbusDevice::NoError)
|
||||||
{
|
{
|
||||||
timer->stop();
|
applySettingsFromScan(reply);
|
||||||
stepForScanCurrentSettings(reply);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
QMessageBox::warning(this, "Ошибка при получении текущих настроек.", QString("Таймаут при опросе устройства %1 по адресу %2").arg(i).arg(Boards[i].adr));
|
QMessageBox::warning(this, "Ошибка при получении текущих настроек.", QString("Таймаут при опросе устройства %1 по адресу %2").arg(i+1).arg(Boards[i].adr));
|
||||||
bar->setValue(CurrentConnectedDevice*3);
|
bar->setValue(CurrentConnectedDevice*3);
|
||||||
|
bar->close();
|
||||||
|
bar->deleteLater();
|
||||||
onConnectClicked();
|
onConnectClicked();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
modbusDevice->setNumberOfRetries(m_settingsDialog->settings().numberOfRetries);
|
||||||
beginScanBoards();
|
beginScanBoards();
|
||||||
bar->deleteLater();
|
bar->deleteLater();
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void M3KTE::timeForPingIsGone()
|
|
||||||
{
|
|
||||||
timerForPingSignal=true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void M3KTE::beginScanBoards()
|
void M3KTE::beginScanBoards()
|
||||||
{
|
{
|
||||||
if(CurrentConnectedDevice>=1)
|
for (int i = 0; i < 4; i++) {
|
||||||
firstBoardScan();
|
if(Boards[i].isActive)
|
||||||
if(CurrentConnectedDevice>=2)
|
boardScan(i);
|
||||||
secondBoardScan();
|
}
|
||||||
if(CurrentConnectedDevice>=3)
|
|
||||||
thirdBoardScan();
|
|
||||||
if(CurrentConnectedDevice>=4)
|
|
||||||
fourthBoardScan();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void M3KTE::firstBoardScan()
|
void M3KTE::boardScan(unsigned boardID)
|
||||||
{
|
{
|
||||||
if (!modbusDevice)
|
if (!modbusDevice)
|
||||||
return;
|
return;
|
||||||
|
QModbusDataUnit* _unit = new QModbusDataUnit(QModbusDataUnit::InputRegisters, 0, 85);
|
||||||
QModbusDataUnit* _unit = new QModbusDataUnit(QModbusDataUnit::InputRegisters, 0, 85);
|
statusBar()->clearMessage();
|
||||||
statusBar()->clearMessage();
|
if (auto *reply = modbusDevice->sendReadRequest(*_unit, Boards[boardID].adr)) {
|
||||||
|
if (!reply->isFinished())
|
||||||
if (auto *reply = modbusDevice->sendReadRequest(*_unit, Boards[0].adr)) {
|
connect(reply, &QModbusReply::finished, this, [this, boardID]()
|
||||||
if (!reply->isFinished())
|
{
|
||||||
connect(reply, &QModbusReply::finished, this, &M3KTE::firstBoardReady);
|
auto subreply = qobject_cast<QModbusReply *>(sender());
|
||||||
else
|
displayResultOfScan(subreply, boardID);
|
||||||
delete reply; // broadcast replies return immediately
|
subreply->deleteLater();
|
||||||
} else {
|
Boards[boardID].boardScanners->start(m_deviceSettingsDialog->currentBoardTimer(boardID));
|
||||||
QMessageBox::warning(this, QString("Ошибка при опросе платы #%1").arg(1), QString(tr("Read error: ") + modbusDevice->errorString()));
|
});
|
||||||
statusBar()->showMessage(tr("Read error: ") + modbusDevice->errorString(), 5000);
|
else
|
||||||
}
|
delete reply; // broadcast replies return immediately
|
||||||
}
|
} else {
|
||||||
|
QMessageBox::warning(this, QString("Ошибка при опросе платы #%1").arg(boardID+1), QString(tr("Read error: ") + modbusDevice->errorString()));
|
||||||
void M3KTE::secondBoardScan()
|
statusBar()->showMessage(tr("Read error: ") + modbusDevice->errorString(), 5000);
|
||||||
{
|
}
|
||||||
if (!modbusDevice)
|
|
||||||
return;
|
|
||||||
|
|
||||||
QModbusDataUnit* _unit = new QModbusDataUnit(QModbusDataUnit::InputRegisters, 0, 85);
|
|
||||||
statusBar()->clearMessage();
|
|
||||||
|
|
||||||
if (auto *reply = modbusDevice->sendReadRequest(*_unit, Boards[1].adr)) {
|
|
||||||
if (!reply->isFinished())
|
|
||||||
connect(reply, &QModbusReply::finished, this, &M3KTE::secondBoardReady);
|
|
||||||
else
|
|
||||||
delete reply; // broadcast replies return immediately
|
|
||||||
} else {
|
|
||||||
QMessageBox::warning(this, QString("Ошибка при опросе платы #%1").arg(2), QString(tr("Read error: ") + modbusDevice->errorString()));
|
|
||||||
statusBar()->showMessage(tr("Read error: ") + modbusDevice->errorString(), 5000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void M3KTE::thirdBoardScan()
|
|
||||||
{
|
|
||||||
if (!modbusDevice)
|
|
||||||
return;
|
|
||||||
|
|
||||||
QModbusDataUnit* _unit = new QModbusDataUnit(QModbusDataUnit::InputRegisters, 0, 85);
|
|
||||||
statusBar()->clearMessage();
|
|
||||||
|
|
||||||
if (auto *reply = modbusDevice->sendReadRequest(*_unit, Boards[2].adr)) {
|
|
||||||
if (!reply->isFinished())
|
|
||||||
connect(reply, &QModbusReply::finished, this, &M3KTE::thirdBoardReady);
|
|
||||||
else
|
|
||||||
delete reply; // broadcast replies return immediately
|
|
||||||
} else {
|
|
||||||
QMessageBox::warning(this, QString("Ошибка при опросе платы #%1").arg(3), QString(tr("Read error: ") + modbusDevice->errorString()));
|
|
||||||
statusBar()->showMessage(tr("Read error: ") + modbusDevice->errorString(), 5000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void M3KTE::fourthBoardScan()
|
|
||||||
{
|
|
||||||
if (!modbusDevice)
|
|
||||||
return;
|
|
||||||
|
|
||||||
QModbusDataUnit* _unit = new QModbusDataUnit(QModbusDataUnit::InputRegisters, 0, 85);
|
|
||||||
statusBar()->clearMessage();
|
|
||||||
|
|
||||||
if (auto *reply = modbusDevice->sendReadRequest(*_unit, Boards[3].adr)) {
|
|
||||||
if (!reply->isFinished())
|
|
||||||
connect(reply, &QModbusReply::finished, this, &M3KTE::fourthBoardReady);
|
|
||||||
else
|
|
||||||
delete reply; // broadcast replies return immediately
|
|
||||||
} else {
|
|
||||||
QMessageBox::warning(this, QString("Ошибка при опросе платы #%1").arg(4), QString(tr("Read error: ") + modbusDevice->errorString()));
|
|
||||||
statusBar()->showMessage(tr("Read error: ") + modbusDevice->errorString(), 5000);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void M3KTE::firstBoardReady()
|
|
||||||
{
|
|
||||||
auto reply = qobject_cast<QModbusReply *>(sender());
|
|
||||||
displayResultOfScan(reply, 0);
|
|
||||||
reply->deleteLater();
|
|
||||||
Boards[0].boardScanners->start(m_deviceSettingsDialog->currentBoardTimer(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
void M3KTE::secondBoardReady()
|
|
||||||
{
|
|
||||||
auto reply = qobject_cast<QModbusReply *>(sender());
|
|
||||||
displayResultOfScan(reply, 1);
|
|
||||||
reply->deleteLater();
|
|
||||||
Boards[1].boardScanners->start(m_deviceSettingsDialog->currentBoardTimer(1));
|
|
||||||
}
|
|
||||||
|
|
||||||
void M3KTE::thirdBoardReady()
|
|
||||||
{
|
|
||||||
auto reply = qobject_cast<QModbusReply *>(sender());
|
|
||||||
displayResultOfScan(reply, 2);
|
|
||||||
reply->deleteLater();
|
|
||||||
Boards[2].boardScanners->start(m_deviceSettingsDialog->currentBoardTimer(2));
|
|
||||||
}
|
|
||||||
|
|
||||||
void M3KTE::fourthBoardReady()
|
|
||||||
{
|
|
||||||
auto reply = qobject_cast<QModbusReply *>(sender());
|
|
||||||
displayResultOfScan(reply, 3);
|
|
||||||
reply->deleteLater();
|
|
||||||
Boards[3].boardScanners->start(m_deviceSettingsDialog->currentBoardTimer(3));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void M3KTE::displayResultOfScan(QModbusReply *reply, int boardID)
|
void M3KTE::displayResultOfScan(QModbusReply *reply, int boardID)
|
||||||
{
|
{
|
||||||
if (!reply)
|
if (!reply)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (reply->error() == QModbusDevice::NoError) {
|
if (reply->error() == QModbusDevice::NoError) {
|
||||||
|
|
||||||
const QModbusDataUnit unit = reply->result();
|
const QModbusDataUnit unit = reply->result();
|
||||||
bool W_Flag = false;
|
bool W_Flag = false;
|
||||||
bool A_Flag = false;
|
bool A_Flag = false;
|
||||||
@@ -1318,16 +1199,11 @@ void M3KTE::displayResultOfScan(QModbusReply *reply, int boardID)
|
|||||||
QMessageBox::warning(this, QString("Ошибка при опросе платы #%1").arg(boardID), QString("Принятый ответ: Стартовый адрес %1, Количество элементов %2").arg(unit.startAddress()).arg(unit.valueCount()));
|
QMessageBox::warning(this, QString("Ошибка при опросе платы #%1").arg(boardID), QString("Принятый ответ: Стартовый адрес %1, Количество элементов %2").arg(unit.startAddress()).arg(unit.valueCount()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i = unit.startAddress(), total = int(unit.valueCount()); i < total; ++i)
|
for(int i = unit.startAddress(), total = int(unit.valueCount()); i < total; ++i)
|
||||||
{
|
{
|
||||||
//QErrorMessage::showMessage()
|
|
||||||
//if(Boards[boardID].ModbusModelCoil->data(Boards[boardID].ModbusModelCoil->index(i, 2), Qt::CheckStateRole).Bool != 0)
|
|
||||||
//if(Boards[boardID].ModbusModelCoil->get_coil(Boards[boardID].ModbusModelCoil->index(i, 2))==true)
|
|
||||||
if(Boards[boardID].coil[i]==true)
|
if(Boards[boardID].coil[i]==true)
|
||||||
{
|
{
|
||||||
int j = 0;
|
int j = 0;
|
||||||
//if(Boards[boardID].ModbusModelHoldingReg->get_holreg(Boards[boardID].ModbusModelHoldingReg->index(85+i, 3)) > unit.value(i))
|
|
||||||
if(Boards[boardID].HR[i + 85] > unit.value(i))
|
if(Boards[boardID].HR[i + 85] > unit.value(i))
|
||||||
{
|
{
|
||||||
j = 1;
|
j = 1;
|
||||||
@@ -1335,7 +1211,6 @@ void M3KTE::displayResultOfScan(QModbusReply *reply, int boardID)
|
|||||||
m_ProgressBar[i+boardID*85]->setWhatsThis(QString("П%1 ТЭ%2: Аварийный уровень напряжения.").arg(QString::number(boardID+1), QString::number(i%85)));
|
m_ProgressBar[i+boardID*85]->setWhatsThis(QString("П%1 ТЭ%2: Аварийный уровень напряжения.").arg(QString::number(boardID+1), QString::number(i%85)));
|
||||||
A_Flag = true;
|
A_Flag = true;
|
||||||
}
|
}
|
||||||
//else if(Boards[boardID].ModbusModelHoldingReg->get_holreg(Boards[boardID].ModbusModelHoldingReg->index(i, 3)) > unit.value(i))
|
|
||||||
else if(Boards[boardID].HR[i] > unit.value(i))
|
else if(Boards[boardID].HR[i] > unit.value(i))
|
||||||
{
|
{
|
||||||
j = 2;
|
j = 2;
|
||||||
@@ -1372,7 +1247,6 @@ void M3KTE::displayResultOfScan(QModbusReply *reply, int boardID)
|
|||||||
statusM3KTE.Warnings[boardID] = true;
|
statusM3KTE.Warnings[boardID] = true;
|
||||||
else
|
else
|
||||||
statusM3KTE.Warnings[boardID] = false;
|
statusM3KTE.Warnings[boardID] = false;
|
||||||
|
|
||||||
ui->BSM_Warning->setChecked(false);
|
ui->BSM_Warning->setChecked(false);
|
||||||
ui->BSM_Accident->setChecked(false);
|
ui->BSM_Accident->setChecked(false);
|
||||||
ui->BSM_WorkInProgress->setChecked(true);
|
ui->BSM_WorkInProgress->setChecked(true);
|
||||||
@@ -1404,52 +1278,48 @@ void M3KTE::displayResultOfScan(QModbusReply *reply, int boardID)
|
|||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
void M3KTE::stepForScanCurrentSettings(QModbusReply *reply)
|
void M3KTE::applySettingsFromScan(QModbusReply *reply)
|
||||||
{
|
{
|
||||||
if (reply->error() == QModbusDevice::NoError) {
|
if (reply->error() == QModbusDevice::NoError) {
|
||||||
const QModbusDataUnit unit = reply->result();
|
const QModbusDataUnit unit = reply->result();
|
||||||
int Adr = 255;
|
int Adr = 255;
|
||||||
for(int i = 0; i < 4; i++)
|
for(int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
if(Boards[i].adr==reply->serverAddress() &&Boards[i].isActive)
|
||||||
{
|
{
|
||||||
if(Boards[i].adr==reply->serverAddress())
|
Adr = i;
|
||||||
{
|
break;
|
||||||
Adr = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for (int i = 0, total = int(unit.valueCount()); i < (total); ++i) {
|
|
||||||
//ui->readValue->addItem(entry);
|
|
||||||
if(unit.registerType() == QModbusDataUnit::Coils)
|
|
||||||
{
|
|
||||||
Boards[Adr].coil[i + unit.startAddress()] = unit.value(i);
|
|
||||||
//QStandardItem *item = ui->writeValueTable->model()->item
|
|
||||||
if(unit.value(i)==1)
|
|
||||||
{
|
|
||||||
Boards[Adr].ModbusModelCoil->setData(ui->writeValueTable->model()->index(i + unit.startAddress(), 2), Qt::Checked, Qt::CheckStateRole);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Boards[Adr].ModbusModelCoil->setData(ui->writeValueTable->model()->index(i + unit.startAddress(), 2), Qt::Unchecked, Qt::CheckStateRole);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else if(unit.registerType() == QModbusDataUnit::HoldingRegisters)
|
|
||||||
{
|
|
||||||
Boards[Adr].HR[i + unit.startAddress()] = unit.value(i);
|
|
||||||
Boards[Adr].ModbusModelHoldingReg->setData(Boards[Adr].ModbusModelHoldingReg->index(i + unit.startAddress(), 3), QString::number(unit.value(i), 16), Qt::EditRole);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (reply->error() == QModbusDevice::ProtocolError) {
|
|
||||||
statusBar()->showMessage(tr("Read response error: %1 (Mobus exception: 0x%2)").
|
|
||||||
arg(reply->errorString()).
|
|
||||||
arg(reply->rawResult().exceptionCode(), -1, 16), 5000);
|
|
||||||
} else {
|
|
||||||
statusBar()->showMessage(tr("Read response error: %1 (code: 0x%2)").
|
|
||||||
arg(reply->errorString()).
|
|
||||||
arg(reply->error(), -1, 16), 5000);
|
|
||||||
}
|
}
|
||||||
|
for (int i = 0, total = int(unit.valueCount()); i < (total); ++i) {
|
||||||
reply->deleteLater();
|
if(unit.registerType() == QModbusDataUnit::Coils)
|
||||||
|
{
|
||||||
|
Boards[Adr].coil[i + unit.startAddress()] = unit.value(i);
|
||||||
|
if(unit.value(i)==1)
|
||||||
|
{
|
||||||
|
Boards[Adr].ModbusModelCoil->setData(ui->writeValueTable->model()->index(i + unit.startAddress(), 2), Qt::Checked, Qt::CheckStateRole);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Boards[Adr].ModbusModelCoil->setData(ui->writeValueTable->model()->index(i + unit.startAddress(), 2), Qt::Unchecked, Qt::CheckStateRole);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(unit.registerType() == QModbusDataUnit::HoldingRegisters)
|
||||||
|
{
|
||||||
|
Boards[Adr].HR[i + unit.startAddress()] = unit.value(i);
|
||||||
|
Boards[Adr].ModbusModelHoldingReg->setData(Boards[Adr].ModbusModelHoldingReg->index(i + unit.startAddress(), 3), QString::number(unit.value(i), 16), Qt::EditRole);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (reply->error() == QModbusDevice::ProtocolError) {
|
||||||
|
statusBar()->showMessage(tr("Read response error: %1 (Mobus exception: 0x%2)").
|
||||||
|
arg(reply->errorString()).
|
||||||
|
arg(reply->rawResult().exceptionCode(), -1, 16), 5000);
|
||||||
|
} else {
|
||||||
|
statusBar()->showMessage(tr("Read response error: %1 (code: 0x%2)").
|
||||||
|
arg(reply->errorString()).
|
||||||
|
arg(reply->error(), -1, 16), 5000);
|
||||||
|
}
|
||||||
|
reply->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
void M3KTE::slotmultipleRegWrite()
|
void M3KTE::slotmultipleRegWrite()
|
||||||
@@ -1489,7 +1359,6 @@ void M3KTE::multipleRegSend()
|
|||||||
Boards[m_regMultipleSettings->getBoardId()].coil[i+m_regMultipleSettings->getStartAdr()] = m_regMultipleSettings->getNewValue();
|
Boards[m_regMultipleSettings->getBoardId()].coil[i+m_regMultipleSettings->getStartAdr()] = m_regMultipleSettings->getNewValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (auto *reply = modbusDevice->sendWriteRequest(*unit_tx, Boards[m_regMultipleSettings->getBoardId()].adr)) {
|
if (auto *reply = modbusDevice->sendWriteRequest(*unit_tx, Boards[m_regMultipleSettings->getBoardId()].adr)) {
|
||||||
if (!reply->isFinished()) {
|
if (!reply->isFinished()) {
|
||||||
connect(reply, &QModbusReply::finished, this, [this, reply]() {
|
connect(reply, &QModbusReply::finished, this, [this, reply]() {
|
||||||
@@ -1517,12 +1386,10 @@ void M3KTE::multipleRegWrite()
|
|||||||
for (unsigned i = 0; i < m_regMultipleSettings->getCountReg(); i++) {
|
for (unsigned i = 0; i < m_regMultipleSettings->getCountReg(); i++) {
|
||||||
if(m_regMultipleSettings->getTypeReg())
|
if(m_regMultipleSettings->getTypeReg())
|
||||||
{
|
{
|
||||||
//Boards[m_regMultipleSettings->getBoardId()].HR[i] = m_regMultipleSettings->getNewValue();
|
|
||||||
Boards[m_regMultipleSettings->getBoardId()].ModbusModelHoldingReg->m_holdingRegisters[i+m_regMultipleSettings->getStartAdr()] = m_regMultipleSettings->getNewValue();
|
Boards[m_regMultipleSettings->getBoardId()].ModbusModelHoldingReg->m_holdingRegisters[i+m_regMultipleSettings->getStartAdr()] = m_regMultipleSettings->getNewValue();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//Boards[m_regMultipleSettings->getBoardId()].coil[i] = m_regMultipleSettings->getNewValue();
|
|
||||||
Boards[m_regMultipleSettings->getBoardId()].ModbusModelCoil->m_coils[i+m_regMultipleSettings->getStartAdr()] = (bool)m_regMultipleSettings->getNewValue();
|
Boards[m_regMultipleSettings->getBoardId()].ModbusModelCoil->m_coils[i+m_regMultipleSettings->getStartAdr()] = (bool)m_regMultipleSettings->getNewValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1534,5 +1401,110 @@ void M3KTE::selectPositionOnTree(unsigned int index)
|
|||||||
QModelIndex selected = ui->writeValueTable->model()->index(index%85, 0);
|
QModelIndex selected = ui->writeValueTable->model()->index(index%85, 0);
|
||||||
ui->writeValueTable->selectionModel()->select(selected, QItemSelectionModel::ClearAndSelect |QItemSelectionModel::Rows);
|
ui->writeValueTable->selectionModel()->select(selected, QItemSelectionModel::ClearAndSelect |QItemSelectionModel::Rows);
|
||||||
ui->writeValueTable->scrollTo(selected);
|
ui->writeValueTable->scrollTo(selected);
|
||||||
//selection
|
}
|
||||||
|
|
||||||
|
bool M3KTE::autoBaudRateScan()
|
||||||
|
{
|
||||||
|
unsigned countOfDeviceOnLine = 0;
|
||||||
|
QString resultOfScan;
|
||||||
|
|
||||||
|
modbusDevice->setConnectionParameter(QModbusDevice::SerialPortNameParameter,
|
||||||
|
m_settingsDialog->settings().portName);
|
||||||
|
#if QT_CONFIG(modbus_serialport)
|
||||||
|
modbusDevice->setConnectionParameter(QModbusDevice::SerialParityParameter,
|
||||||
|
m_settingsDialog->settings().parity);
|
||||||
|
modbusDevice->setConnectionParameter(QModbusDevice::SerialDataBitsParameter,
|
||||||
|
m_settingsDialog->settings().dataBits);
|
||||||
|
modbusDevice->setConnectionParameter(QModbusDevice::SerialStopBitsParameter,
|
||||||
|
m_settingsDialog->settings().stopBits);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
modbusDevice->setTimeout(50);
|
||||||
|
modbusDevice->setNumberOfRetries(0);
|
||||||
|
uint m_baud[] = {9600, 14400, 19200, 31250, 38400, 56000, 57600, 115200};
|
||||||
|
|
||||||
|
bool isRun = false;
|
||||||
|
bool *tmp_isRun = &isRun;
|
||||||
|
auto bar = new QProgressDialog(this);
|
||||||
|
connect(bar, &QProgressDialog::canceled, this, [this, tmp_isRun]()
|
||||||
|
{
|
||||||
|
*tmp_isRun = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
bar->setCancelButton(nullptr);
|
||||||
|
bar->setRange(0, 8);
|
||||||
|
bar->setMinimumDuration(100);
|
||||||
|
bar->setValue(0);
|
||||||
|
|
||||||
|
QModbusRequest requestOfDeviceType(QModbusRequest::EncapsulatedInterfaceTransport, QByteArray::fromHex("0E0404"));
|
||||||
|
|
||||||
|
for(int i = 0; i < 8; i++)
|
||||||
|
{
|
||||||
|
bar->setValue(i);
|
||||||
|
modbusDevice->setConnectionParameter(QModbusDevice::SerialBaudRateParameter,
|
||||||
|
m_baud[i]);
|
||||||
|
if (!modbusDevice->connectDevice()) {
|
||||||
|
statusBar()->showMessage(tr("Connect failed: ") + modbusDevice->errorString(), 5000);
|
||||||
|
}
|
||||||
|
for(int tmp_adr = 1; tmp_adr < 248; tmp_adr++)
|
||||||
|
{
|
||||||
|
bar->setLabelText(tr("Поиск плат... Текущий адрес: %1").arg(tmp_adr));
|
||||||
|
|
||||||
|
auto *reply = modbusDevice->sendRawRequest(requestOfDeviceType, tmp_adr);
|
||||||
|
//auto *reply = modbusDevice->sendReadRequest(*_unit, tmp_adr);
|
||||||
|
//Запрос типа устройства.
|
||||||
|
if(reply == nullptr)
|
||||||
|
{
|
||||||
|
onConnectClicked();
|
||||||
|
bar->close();
|
||||||
|
bar->deleteLater();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
while(!reply->isFinished())
|
||||||
|
{
|
||||||
|
if(isRun)
|
||||||
|
{
|
||||||
|
onConnectClicked();
|
||||||
|
bar->close();
|
||||||
|
bar->deleteLater();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
QCoreApplication::processEvents();
|
||||||
|
}
|
||||||
|
if(isRun)
|
||||||
|
{
|
||||||
|
onConnectClicked();
|
||||||
|
bar->close();
|
||||||
|
bar->deleteLater();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else if (!isRun)
|
||||||
|
{
|
||||||
|
//Нужна проверка типа устройства
|
||||||
|
if(reply->error()==QModbusDevice::NoError)
|
||||||
|
{
|
||||||
|
QModbusResponse resp = reply->rawResult();
|
||||||
|
QString result = QString(resp.data().remove(0, MODBUS_REQUEST_PROTOCOL_INFO_LENGTH));
|
||||||
|
//result.remove(0, MODBUS_REQUEST_PROTOCOL_INFO_LENGTH);
|
||||||
|
if(result == QString("KTE"))
|
||||||
|
{
|
||||||
|
countOfDeviceOnLine++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(countOfDeviceOnLine>0)
|
||||||
|
resultOfScan += QString("%1 плат M3KTE работают на скорости %2.\n").arg(countOfDeviceOnLine).arg(m_baud[i]);
|
||||||
|
countOfDeviceOnLine = 0;
|
||||||
|
}
|
||||||
|
if(m_scanBoard->exec()==QDialog::Accepted)
|
||||||
|
{
|
||||||
|
if(m_scanBoard->getCheckState()==Qt::Checked)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#include "writeregistermodel.h"
|
#include "writeregistermodel.h"
|
||||||
#include "devicesettingsdialog.h"
|
#include "devicesettingsdialog.h"
|
||||||
#include "multiplesettings.h"
|
#include "multiplesettings.h"
|
||||||
|
#include "scanboard.h"
|
||||||
|
|
||||||
#include <QModbusTcpClient>
|
#include <QModbusTcpClient>
|
||||||
#include <QModbusRtuSerialMaster>
|
#include <QModbusRtuSerialMaster>
|
||||||
@@ -18,6 +19,7 @@
|
|||||||
#include <QProgressDialog>
|
#include <QProgressDialog>
|
||||||
#include <QErrorMessage>
|
#include <QErrorMessage>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
|
#include <QGroupBox>
|
||||||
|
|
||||||
#include <QtSerialBus/qtserialbusglobal.h>
|
#include <QtSerialBus/qtserialbusglobal.h>
|
||||||
|
|
||||||
@@ -25,6 +27,8 @@
|
|||||||
#include <QSerialPort>
|
#include <QSerialPort>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define MODBUS_REQUEST_PROTOCOL_INFO_LENGTH 8
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
namespace Ui { class M3KTE; class SettingsDialog;}
|
namespace Ui { class M3KTE; class SettingsDialog;}
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
@@ -40,17 +44,18 @@ private:
|
|||||||
QModbusDataUnit readRequest() const;
|
QModbusDataUnit readRequest() const;
|
||||||
QModbusDataUnit writeRequest() const;
|
QModbusDataUnit writeRequest() const;
|
||||||
void changeTable(int board, int tabletype);
|
void changeTable(int board, int tabletype);
|
||||||
void debug();
|
|
||||||
void errorAdrChange();
|
void errorAdrChange();
|
||||||
bool event(QEvent* event);
|
bool event(QEvent* event);
|
||||||
bool pingNetworkDevices();
|
bool pingNetworkDevices();
|
||||||
void beginScanBoards();
|
void beginScanBoards();
|
||||||
void displayResultOfScan(QModbusReply *reply, int boardID);
|
void displayResultOfScan(QModbusReply *reply, int boardID);
|
||||||
void stepForScanCurrentSettings(QModbusReply *reply);
|
void applySettingsFromScan(QModbusReply *reply);
|
||||||
|
|
||||||
void multipleRegWrite();
|
void multipleRegWrite();
|
||||||
void multipleRegSend();
|
void multipleRegSend();
|
||||||
|
|
||||||
|
bool autoBaudRateScan();
|
||||||
|
|
||||||
void selectPositionOnTree(unsigned index);
|
void selectPositionOnTree(unsigned index);
|
||||||
private slots:
|
private slots:
|
||||||
|
|
||||||
@@ -62,9 +67,7 @@ private slots:
|
|||||||
void onReadButtonClicked();
|
void onReadButtonClicked();
|
||||||
void onReadReady();
|
void onReadReady();
|
||||||
|
|
||||||
void timeForPingIsGone();
|
void checkAdrChange(QModbusReply *reply, unsigned boardNum);
|
||||||
|
|
||||||
void checkAdrChange();
|
|
||||||
|
|
||||||
void onWriteButtonClicked();
|
void onWriteButtonClicked();
|
||||||
void onSelectedBoardChanged(int index);
|
void onSelectedBoardChanged(int index);
|
||||||
@@ -73,22 +76,14 @@ private slots:
|
|||||||
void onSpeedUpdate();
|
void onSpeedUpdate();
|
||||||
void onParityUpdate();
|
void onParityUpdate();
|
||||||
|
|
||||||
void firstBoardScan();
|
void boardScan(unsigned boardID);
|
||||||
void secondBoardScan();
|
|
||||||
void thirdBoardScan();
|
|
||||||
void fourthBoardScan();
|
|
||||||
|
|
||||||
void firstBoardReady();
|
|
||||||
void secondBoardReady();
|
|
||||||
void thirdBoardReady();
|
|
||||||
void fourthBoardReady();
|
|
||||||
public:
|
public:
|
||||||
M3KTE(QWidget *parent = nullptr);
|
M3KTE(QWidget *parent = nullptr);
|
||||||
~M3KTE();
|
~M3KTE();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::M3KTE *ui;
|
Ui::M3KTE *ui;
|
||||||
bool timerForPingSignal = false;
|
|
||||||
int CurrentConnectedDevice = 0;
|
int CurrentConnectedDevice = 0;
|
||||||
//int DeviceOnNetwork[4];
|
//int DeviceOnNetwork[4];
|
||||||
QProgressBar *m_ProgressBar[320];
|
QProgressBar *m_ProgressBar[320];
|
||||||
@@ -98,6 +93,8 @@ private:
|
|||||||
DeviceSettingsDialog *m_deviceSettingsDialog = nullptr;
|
DeviceSettingsDialog *m_deviceSettingsDialog = nullptr;
|
||||||
SettingsDialog *m_settingsDialog = nullptr;
|
SettingsDialog *m_settingsDialog = nullptr;
|
||||||
MultipleSettings *m_regMultipleSettings = nullptr;
|
MultipleSettings *m_regMultipleSettings = nullptr;
|
||||||
|
ScanBoard *m_scanBoard = nullptr;
|
||||||
|
QGroupBox *Boards_Fields[4];
|
||||||
//WriteRegisterModel *writeModel = nullptr;
|
//WriteRegisterModel *writeModel = nullptr;
|
||||||
|
|
||||||
struct StatusM3KTE{
|
struct StatusM3KTE{
|
||||||
@@ -107,6 +104,8 @@ private:
|
|||||||
|
|
||||||
struct BoardModbusRegisters
|
struct BoardModbusRegisters
|
||||||
{
|
{
|
||||||
|
bool isActive = false;
|
||||||
|
|
||||||
int adr;
|
int adr;
|
||||||
int _tmp_adr;
|
int _tmp_adr;
|
||||||
|
|
||||||
|
|||||||
@@ -3914,7 +3914,7 @@
|
|||||||
</item>
|
</item>
|
||||||
<item row="2" column="4" rowspan="2" colspan="2">
|
<item row="2" column="4" rowspan="2" colspan="2">
|
||||||
<layout class="QGridLayout" name="TxRxLayout">
|
<layout class="QGridLayout" name="TxRxLayout">
|
||||||
<item row="4" column="0">
|
<item row="5" column="0">
|
||||||
<widget class="QPushButton" name="writeButton">
|
<widget class="QPushButton" name="writeButton">
|
||||||
<property name="minimumSize">
|
<property name="minimumSize">
|
||||||
<size>
|
<size>
|
||||||
@@ -3927,6 +3927,9 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="3" column="0">
|
||||||
|
<widget class="QTreeView" name="writeValueTable"/>
|
||||||
|
</item>
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<widget class="QComboBox" name="boardSelectBox">
|
<widget class="QComboBox" name="boardSelectBox">
|
||||||
<item>
|
<item>
|
||||||
@@ -3954,7 +3957,7 @@
|
|||||||
<item row="1" column="0">
|
<item row="1" column="0">
|
||||||
<widget class="QComboBox" name="writeTable"/>
|
<widget class="QComboBox" name="writeTable"/>
|
||||||
</item>
|
</item>
|
||||||
<item row="3" column="0">
|
<item row="4" column="0">
|
||||||
<widget class="QPushButton" name="readButton">
|
<widget class="QPushButton" name="readButton">
|
||||||
<property name="minimumSize">
|
<property name="minimumSize">
|
||||||
<size>
|
<size>
|
||||||
@@ -3967,9 +3970,6 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="0">
|
|
||||||
<widget class="QTreeView" name="writeValueTable"/>
|
|
||||||
</item>
|
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="3" rowspan="3">
|
<item row="1" column="3" rowspan="3">
|
||||||
|
|||||||
29
M3KTE_TERM/scanboard.cpp
Normal file
29
M3KTE_TERM/scanboard.cpp
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
#include "scanboard.h"
|
||||||
|
#include "ui_scanboard.h"
|
||||||
|
|
||||||
|
ScanBoard::ScanBoard(QWidget *parent) :
|
||||||
|
QDialog(parent),
|
||||||
|
ui(new Ui::ScanBoard)
|
||||||
|
{
|
||||||
|
ui->setupUi(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
ScanBoard::~ScanBoard()
|
||||||
|
{
|
||||||
|
delete ui;
|
||||||
|
}
|
||||||
|
|
||||||
|
Qt::CheckState ScanBoard::getCheckState()
|
||||||
|
{
|
||||||
|
return checkState;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScanBoard::on_applyToAllBox_stateChanged(int arg1)
|
||||||
|
{
|
||||||
|
checkState = (Qt::CheckState)arg1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScanBoard::showMeTheTruth(QString resultOfScan)
|
||||||
|
{
|
||||||
|
ui->logger->append(resultOfScan);
|
||||||
|
}
|
||||||
29
M3KTE_TERM/scanboard.h
Normal file
29
M3KTE_TERM/scanboard.h
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
#ifndef SCANBOARD_H
|
||||||
|
#define SCANBOARD_H
|
||||||
|
|
||||||
|
#include <QDialog>
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
class ScanBoard;
|
||||||
|
}
|
||||||
|
|
||||||
|
class ScanBoard : public QDialog
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit ScanBoard(QWidget *parent = nullptr);
|
||||||
|
~ScanBoard();
|
||||||
|
|
||||||
|
Qt::CheckState getCheckState();
|
||||||
|
void showMeTheTruth(QString resultOfScan);
|
||||||
|
private slots:
|
||||||
|
void on_applyToAllBox_stateChanged(int arg1);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Qt::CheckState checkState;
|
||||||
|
|
||||||
|
Ui::ScanBoard *ui;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // SCANBOARD_H
|
||||||
81
M3KTE_TERM/scanboard.ui
Normal file
81
M3KTE_TERM/scanboard.ui
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>ScanBoard</class>
|
||||||
|
<widget class="QDialog" name="ScanBoard">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>337</width>
|
||||||
|
<height>145</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Dialog</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QGridLayout" name="gridLayout_2">
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QTextEdit" name="logger"/>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QComboBox" name="baudRateBox"/>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="1">
|
||||||
|
<widget class="QCheckBox" name="applyToAllBox">
|
||||||
|
<property name="text">
|
||||||
|
<string>Применить ко всем обнаруженным платам</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="0">
|
||||||
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="standardButtons">
|
||||||
|
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>accepted()</signal>
|
||||||
|
<receiver>ScanBoard</receiver>
|
||||||
|
<slot>accept()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>248</x>
|
||||||
|
<y>254</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>157</x>
|
||||||
|
<y>274</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>rejected()</signal>
|
||||||
|
<receiver>ScanBoard</receiver>
|
||||||
|
<slot>reject()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>316</x>
|
||||||
|
<y>260</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>286</x>
|
||||||
|
<y>274</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
</connections>
|
||||||
|
</ui>
|
||||||
@@ -23,7 +23,7 @@ public:
|
|||||||
int baud = 115200;
|
int baud = 115200;
|
||||||
int dataBits = QSerialPort::Data8;
|
int dataBits = QSerialPort::Data8;
|
||||||
int stopBits = QSerialPort::OneStop;
|
int stopBits = QSerialPort::OneStop;
|
||||||
int responseTime = 500;
|
int responseTime = 50;
|
||||||
int numberOfRetries = 0;
|
int numberOfRetries = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -20,13 +20,13 @@
|
|||||||
<string> мс</string>
|
<string> мс</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="minimum">
|
<property name="minimum">
|
||||||
<number>-1</number>
|
<number>10</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="maximum">
|
<property name="maximum">
|
||||||
<number>5000</number>
|
<number>5000</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="singleStep">
|
<property name="singleStep">
|
||||||
<number>20</number>
|
<number>1</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="value">
|
<property name="value">
|
||||||
<number>200</number>
|
<number>200</number>
|
||||||
@@ -36,7 +36,7 @@
|
|||||||
<item row="2" column="1" rowspan="2" colspan="2">
|
<item row="2" column="1" rowspan="2" colspan="2">
|
||||||
<widget class="QSpinBox" name="retriesSpinner">
|
<widget class="QSpinBox" name="retriesSpinner">
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
<bool>false</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
<property name="value">
|
<property name="value">
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
|
|||||||
@@ -25,10 +25,8 @@ 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());
|
||||||
|
|
||||||
@@ -42,17 +40,14 @@ QVariant WriteRegisterModel::data(const QModelIndex &index, int role) const
|
|||||||
return QString("0x%1").arg(QString::number(m_holdingRegisters.at(index.row()), 16));
|
return QString("0x%1").arg(QString::number(m_holdingRegisters.at(index.row()), 16));
|
||||||
|
|
||||||
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)));
|
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:
|
||||||
@@ -76,7 +71,6 @@ bool WriteRegisterModel::setData(const QModelIndex &index, const QVariant &value
|
|||||||
{
|
{
|
||||||
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);
|
||||||
|
|
||||||
@@ -86,7 +80,6 @@ bool WriteRegisterModel::setData(const QModelIndex &index, const QVariant &value
|
|||||||
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, 16);
|
quint16 newValue = value.toString().toUShort(&result, 16);
|
||||||
@@ -96,7 +89,6 @@ bool WriteRegisterModel::setData(const QModelIndex &index, const QVariant &value
|
|||||||
emit dataChanged(index, index);
|
emit dataChanged(index, index);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user