当前位置:网站首页>QT compile IOT management platform 39 alarm linkage

QT compile IOT management platform 39 alarm linkage

2022-07-07 21:37:00 feiyangqingyun

One 、 Preface

This system supports alarm linkage , It's after a detector gives an alarm , And then issue orders , Notify the following relay alarm , Generally, it is sent through serial port , Because the existing serial port lines will be used on site, such as 485 Bus , So this system needs special treatment , It's public 485 Communication bus , In the alarm linkage table , If the added serial port number exists in the port information table , You don't need to new A serial port , Directly send the command to be processed to the port communication class , When polling, the port communication class finds whether there are commands that need to be executed first , In some cases, priority is given to these commands , Only after all these commands are processed , Then send the polling command .

A sub device alarms , Multiple relays can be linked , One to many relationship , Multiple devices can also be linked to the same relay , many-to-one , Taken together, this becomes a many to many relationship , In the relay linkage information table , You can customize which sub equipment tag number alarms , Corresponding to which serial port and which address set are linked . At present, the system supports alarm linkage in hardware , In the later stage, soft linkage processing can be customized according to user needs , For example, pop up the corresponding monitoring alarm image .

Two 、 Functional characteristics

2.1 Software modules

  1. Equipment monitoring module , Including data monitoring ( Show... In tabular form )、 Device panel ( Display in panel form )、 Map monitoring ( Display in map form )、 Curve monitoring ( Show in curve form ).
  2. Data query module , Including alarm records 、 Operation record 、 Operation record .
  3. System setup module , Including basic settings 、 Port Management 、 Controller management 、 Detector Management 、 Alarm linkage 、 Type setting, etc .
  4. Other setting modules , Including user management 、 Map Management 、 Position adjustment 、 Configuration design 、 Equipment commissioning, etc .

2.2 Basic function

  1. Device data acquisition , Support serial port 、 The Internet , Serial port can set serial port number 、 Baud rate , The network can be set IP Address 、 Communication port .
  2. Each port supports acquisition cycle time , Default 1 One device per second .
  3. Support to set communication timeout times , Default 3 Time .
  4. Support maximum reconnection time , For rereading offline devices .
  5. Controller information , Can add controller name , Select the controller address 、 Controller model , Set the number of detectors under the controller .
  6. Detector information , Can add tag number 、 Detector model 、 Gas type 、 Gas symbol 、 High reported value 、 Under reported value 、 Buffer value 、 Zero value 、 Is it enabled? 、 Alarm sound 、 Background map 、 Storage cycle 、 The number of decimal places for numerical conversion 、 Alarm delay time 、 Type of alarm (HH,LL,HL) etc. .
  7. Type management configurable controller model 、 Detector model 、 Gas type 、 Gas symbols, etc .
  8. Map supports importing and deleting , The positions of all detectors on the map can be dragged and saved freely .
  9. Port information 、 Controller information 、 Detector information 、 Type information 、 User information, etc , Both support import 、 export 、 Export to excel、 Print .
  10. Operation record 、 Alarm records 、 Operation record , Both support multi condition combined query , For example, time period 、 controller 、 Detector, etc , All records support export to excel/pdf And print .
  11. Operation record 、 Alarm records 、 All operation records can delete data within a specified time range .
  12. The system can select the maximum number of records saved in the corresponding table , Automatically clean up early data , Leave enough space for important data .
  13. Alarm SMS forwarding , Support multiple receiving mobile numbers , The sending interval can be set , Like instant delivery or 6 Send all alarm messages once an hour , The message is too long , Automatically split multiple messages .
  14. Alarm mail forwarding , Support multiple receiving mailboxes , The sending interval can be set , Like instant delivery or 6 Send all alarm messages once an hour , Support attachment sending .
  15. Set the Chinese title of the software 、 English title 、logo route 、 All rights reserved .
  16. The switch is set for startup and operation 、 Alarm sound 、 automatic logon 、 Remember the password, etc .
  17. Alarm sound can be set to play times , Interface style provides 18 Set skin file selection .
  18. User management , Including user permission configuration , Different users can have different module permissions .
  19. User login and user logout , Can remember password and auto login , More than three error prompts and close the program .
  20. Four monitoring modes , Equipment panel monitoring 、 Map monitoring 、 Form data monitoring 、 Curve data monitoring , Free to switch , The collected data is displayed in real time in all four modes , Alarm flashing, etc .
  21. Alarm relay linkage , A tag number can link multiple modules and relay numbers across serial ports , Support many to many .

2.3 Special function

  1. Communication protocol supports modbus_com、modbus_tcp_rtu, Later expansion mqtt Such agreement .
  2. The data source is in addition to the real hardware device collection , Optional database acquisition , In this way, users can arrange other programmers, such as java The programmer puts the data collected by the front end into the database , The system can collect data directly from the database . Database collection mode can be used as a general system , More suitable for multi person and multi system cooperation .
  3. Smart skip timeout device , Speed up the acquisition of online devices , Especially useful when there are a large number of devices .
  4. For smart skip timeout devices , Automatically collect once at the set reconnection time , In order to detect whether the equipment is online again .
  5. Each detector can be controlled whether it is enabled , If it is not enabled, it will not collect , It will not be displayed on the interface , It is equivalent to temporary shutdown in the operation phase .
  6. The detector can set the buffer value and alarm delay time , An alarm generated by fluctuations near this value , Not included in the alarm , Only when it is continuously at the alarm value and exceeds the alarm delay time can it be considered as a real alarm , This can avoid many false positives caused by fluctuations .
  7. The detector can set the storage cycle , Store an operation record according to the set time , The storage cycle can be shorter for those with high importance according to the degree of importance , The unimportant setting is bigger , This can save a lot of storage space , It also ensures the timely storage of important data .
  8. The detector can set the zero clearing value , When some high-precision and sensitive equipment may leave the factory, the default value may not be 0, The reset value needs to be set to represent the initial value .
  9. The detector can set the decimal point , It is used to control the display of decimal places for the calculated real data , Equivalent to divided by 10、 Divide 100、 Divide 1000, In this way, most of the detector data directly control the real converted value through the decimal point setting , If special conversion is required, it can be agreed in the communication protocol .
  10. The type of detector alarm supports multiple types , Some devices are higher than a certain value and report high , Under reporting below a certain value , And some equipment is in the range of minimum and maximum value, which is high alarm , Under reporting below the minimum value , Above maximum normal . In this way, it can be handled according to the situation , Covers various alarm types .
  11. Original data import 、 export 、 Printer system , Cross platform does not rely on any components , Export data instantaneously .
  12. Export to excel The records support all excel、wps Wait for the form file version , Do not rely on excel Such as software .
  13. High color 、 Low color 、 Normal color 、 Default values: color, etc , Can be set freely .
  14. Support cloud data synchronization , Synchronize the data collected locally to the cloud in real time .
  15. Support network forwarding and network receiving , When network reception is turned on , Software from udp Receive data for parsing . Network forwarding supports multiple targets IP, In this way, the local acquisition software is realized , Free to transfer data to client , Check the collected data at any time .
  16. Automatically remember the last user interface and other configuration information , Automatic application after restart .
  17. The alarm automatically switches to the corresponding map , The detector button flashes , The table data is displayed in the corresponding color .
  18. Double click the probe Icon , Pop up the corresponding detector details , The back control operation can be customized as required .
  19. The database supports a variety of , Include sqlite、mysql、sqlserver、postgresql、oracle、 People's Congress, Jincang, etc .
  20. The data collected by the local device is uploaded to the cloud in real time , So that cell phones APP perhaps web And so on .
  21. Built in device simulation tools , Support data simulation of multiple devices of different models , At the same time, it also has database data simulation , In order to test the data when there is no equipment .
  22. standard modbus agreement , Various controller types 、 Detector type 、 species 、 All custom symbols, etc , Very flexible and powerful , The communication protocol sample data is very complete , General various modbus Protocol system , It is applicable to various application scenarios .
  23. At the same time, it integrates serial communication 、 Network communication 、 Database communication 、 Data import / export printing 、 Communication protocol analysis 、 Interface UI、 Many components and knowledge points such as global skin change , Very suitable for beginners and advanced .
  24. Support xp、win7、win10、、win11、linux、mac、 All kinds of domestic systems (UOS、 Winning Qilin 、 Galaxy unicorn, etc )、 The embedded linux Such as system .
  25. Note complete , The project structure is clear , Super detailed complete use of the development manual , Accurate to the function description of each code file , Keep iterating over versions .

3、 ... and 、 Experience address

  1. Domestic site :https://gitee.com/feiyangqingyun
  2. International sites :https://github.com/feiyangqingyun
  3. Personal home page :https://blog.csdn.net/feiyangqingyun
  4. Zhihu Homepage :https://www.zhihu.com/people/feiyangqingyun
  5. The product page :https://blog.csdn.net/feiyangqingyun/article/details/97565652
  6. Online document :https://feiyangqingyun.gitee.io/qwidgetdemo/iotsystem/
  7. Experience address :https://pan.baidu.com/s/1ZxG-oyUKe286LPMPxOrO2A Extraction code :o05q file name :bin_iotsystem.zip.
  8. Article navigation :https://qtchina.blog.csdn.net/article/details/121330922

Four 、 design sketch

 Insert picture description here

5、 ... and 、 Related codes

void AlarmLink::checkAlarm(const QString &positionID, bool alarm)
{
    
    for (int i = 0; i < DbData::AlarmLink_Count; ++i) {
    
        if (positionID == DbData::AlarmLink_PositionID.at(i)) {
    
            QString comName = DbData::AlarmLink_ComName.at(i);
            quint8 modelAddr = DbData::AlarmLink_ModelAddr.at(i);
            QString linkAddr = DbData::AlarmLink_LinkAddr.at(i);

            // Generate data to be linked 
            QByteArray body;
            body.append(0x06);
            body.append(data_zero);
            body.append(data_zero);

            // Send all alarm relay linkage at one time , For example, it's set linkAddr by 1,2,3
            // Specifically, it is calculated in bits , Fill the corresponding placeholder , Two bytes in total 
            // Take the original one from the corresponding module address, replace it and update it 
            QString strBin = "0000000000000000";
            QString temp = QString("%1|%2").arg(comName).arg(modelAddr);
            int index = -1;
            for (int i = 0; i < alarmIDs.count(); ++i) {
    
                if (alarmIDs.at(i).startsWith(temp)) {
    
                    index = i;
                    break;
                }
            }

            // Update the alarm bit again , And keep the previous alarm bit 
            if (index >= 0) {
    
                strBin = alarmIDs.at(index).split("|").last();
                QStringList linkAddrs = linkAddr.split("|");
                foreach (QString addr, linkAddrs) {
    
                    if (!addr.isEmpty()) {
    
                        strBin[16 - addr.toInt()] = alarm ? '1' : '0';
                    }
                }

                alarmIDs[index] = QString("%1|%2|%3").arg(comName).arg(modelAddr).arg(strBin);
            }

            quint16 addr = QUIHelper::strBinToDecimal(strBin);
            body.append(QUIHelper::ushortToByte(addr));
            QString type = QString(" A serial port [%1] %2 Alarm linkage  %3").arg(comName).arg(alarm ? " start-up " : " stop it ").arg(linkAddr);
            writeData(comName, type, modelAddr, body);
        }
    }
}

void AlarmLink::append(const QString &positionID)
{
    
    // Limit the maximum alarm queue , Those that already exist do not need to continue to join 
    if (alarmPositionIDs.count() > 50 || alarmPositionIDs.contains(positionID)) {
    
        return;
    }

    QMutexLocker lock(&mutex);
    alarmPositionIDs << positionID;
}

void AlarmLink::remove(const QString &positionID)
{
    
    // Need to remember the previous alarm , Replace the new 
    // This remains to be discussed , Whether to mute the module completely or individually , Single problem , When both are sent to an alarm bit, they will be inconsistent 
    //2019-3-25  Change to no need to reset the alarm relay , The user triggers the reset of all relays by clicking the mute button 
    //checkAlarm(positionID, false);
}

void AlarmLink::reset()
{
    
    // Send reset data to the serial port corresponding to all tag numbers 
    QByteArray body;
    body.append(0x06);
    body.append(data_zero);
    body.append(data_zero);
    body.append(data_zero);
    body.append(data_zero);

    QStringList comNames;
    for (int i = 0; i < DbData::AlarmLink_Count; ++i) {
    
        QString comName = DbData::AlarmLink_ComName.at(i);
        // Filter those that have sent reset , Otherwise, a large number of repeated transmissions 
        if (!comNames.contains(comName)) {
    
            quint8 modelAddr = DbData::AlarmLink_ModelAddr.at(i);
            QString type = QString(" A serial port [%1] %2 Alarm linkage  %3").arg(comName).arg(" Reset ").arg(0);
            writeData(comName, type, modelAddr, body);
            comNames << comName;
            break;
        }
    }

    // Build an empty queue of alarmed bits 
    alarmIDs.clear();
    alarmPositionIDs.clear();
    for (int i = 0; i < DbData::AlarmLink_Count; ++i) {
    
        QString comName = DbData::AlarmLink_ComName.at(i);
        quint8 modelAddr = DbData::AlarmLink_ModelAddr.at(i);
        QString alarmID = QString("%1|%2|0000000000000000").arg(comName).arg(modelAddr);

        // If the serial port number already exists, the module does not need to continue 
        bool exist = false;
        QString temp = QString("%1|%2").arg(comName).arg(modelAddr);
        for (int i = 0; i < alarmIDs.count(); ++i) {
    
            if (alarmIDs.at(i).startsWith(temp)) {
    
                exist = true;
                break;
            }
        }

        if (!exist) {
    
            alarmIDs << alarmID;
        }
    }
}

void AlarmLink::writeData(int index, const QString &type, quint8 addr, const QByteArray &body)
{
    
    // First judge whether the serial port is working normally 
    QByteArray data;
    data.append(addr);
    data.append(body);
    data.append(QUIHelper::getCrcCode(data));

    // You need to judge the quantity, or it will cross the boundary 
    if (coms.count() > index) {
    
        coms.at(index)->write(data);
    }

    QString portName = " Alarm linkage ";
    emit sendData(portName, addr, data);
    emit receiveInfo(portName, addr, type);
}

void AlarmLink::writeData(const QString &comName, const QString &type, quint8 modelAddr, const QByteArray &body)
{
    
    // If the serial port is not an independent serial port, send data from the serial port used by the controller 
    int index = comNames.indexOf(comName);
    if (index >= 0) {
    
        writeData(index, type, modelAddr, body);
    } else {
    
        index = DbData::PortInfo_ComName.indexOf(comName);
        if (index >= 0) {
    
            QString portName = DbData::PortInfo_PortName.at(index);
            DeviceServer::Instance()->writeData(portName, type, modelAddr, body);
        }
    }
}
原网站

版权声明
本文为[feiyangqingyun]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207071843400926.html