added button on/off
This commit is contained in:
@@ -216,10 +216,7 @@ void Mainwindows::onReadReady() {
|
|||||||
auto reply = qobject_cast<QModbusReply *>(sender());
|
auto reply = qobject_cast<QModbusReply *>(sender());
|
||||||
if (!reply) return;
|
if (!reply) return;
|
||||||
|
|
||||||
// Увеличиваем счетчик ответов при успешном чтении
|
|
||||||
if (reply->error() == QModbusDevice::NoError) {
|
if (reply->error() == QModbusDevice::NoError) {
|
||||||
m_responseCounter++;
|
|
||||||
updateStatusBar();
|
|
||||||
const QModbusDataUnit unit = reply->result();
|
const QModbusDataUnit unit = reply->result();
|
||||||
int address = unit.startAddress();
|
int address = unit.startAddress();
|
||||||
int value = unit.value(0);
|
int value = unit.value(0);
|
||||||
@@ -243,8 +240,17 @@ void Mainwindows::onReadReady() {
|
|||||||
if (address == m_buttonRegisters[i]) {
|
if (address == m_buttonRegisters[i]) {
|
||||||
m_buttonValues[i] = value;
|
m_buttonValues[i] = value;
|
||||||
bool bitState = (value >> m_buttonBits[i]) & 1;
|
bool bitState = (value >> m_buttonBits[i]) & 1;
|
||||||
m_buttons[i]->setText(QString("%1")
|
// Проверяем, есть ли индикатор для этой кнопки
|
||||||
.arg(bitState ? "Закрыть" : "Открыть"));
|
bool hasIndicator = false;
|
||||||
|
for (int j = 0; j < m_indicatorRegisters.size(); ++j) {
|
||||||
|
if (m_indicatorLabels[j].contains(m_buttonLabels[i], Qt::CaseInsensitive)) {
|
||||||
|
hasIndicator = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_buttons[i]->setText(hasIndicator ?
|
||||||
|
QString("%1").arg(bitState ? "Выкл" : "Вкл") :
|
||||||
|
QString("%1").arg(bitState ? "Закрыть" : "Открыть"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user