added button on/off
This commit is contained in:
@@ -216,10 +216,7 @@ void Mainwindows::onReadReady() {
|
||||
auto reply = qobject_cast<QModbusReply *>(sender());
|
||||
if (!reply) return;
|
||||
|
||||
// Увеличиваем счетчик ответов при успешном чтении
|
||||
if (reply->error() == QModbusDevice::NoError) {
|
||||
m_responseCounter++;
|
||||
updateStatusBar();
|
||||
const QModbusDataUnit unit = reply->result();
|
||||
int address = unit.startAddress();
|
||||
int value = unit.value(0);
|
||||
@@ -243,8 +240,17 @@ void Mainwindows::onReadReady() {
|
||||
if (address == m_buttonRegisters[i]) {
|
||||
m_buttonValues[i] = value;
|
||||
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