Qt继电器控制板代码

本文档展示了如何使用Qt编写代码来初始化、控制和获取继电器控制板的状态。通过设置串口参数,发送特定指令来打开或关闭继电器,并验证设备响应以确保命令正确执行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#ifndef ZIOMODULE_H
#define ZIOMODULE_H

#include <QObject>
#include <QDebug>
#include <QSerialPort>
#include <QSerialPortInfo>

#define ADDR_DEST   0x01
const uchar zresponse_failed[]={0xA3,0x0D,0x0A,};
const uchar zcmd_output1_open[]={0x3A,0x88,ADDR_DEST,0x01,0x00,0x0D,0x0A};
const uchar zcmd_output1_close[]={0x3A,0x88,ADDR_DEST,0x01,0xFF,0x0D,0x0A};
const uchar zcmd_output2_open[]={0x3A,0x88,ADDR_DEST,0x02,0x00,0x0D,0x0A};
const uchar zcmd_output2_close[]={0x3A,0x88,ADDR_DEST,0x02,0xFF,0x0D,0x0A};
const uchar zcmd_output3_open[]={0x3A,0x88,ADDR_DEST,0x03,0x00,0x0D,0x0A};
const uchar zcmd_output3_close[]={0x3A,0x88,ADDR_DEST,0x03,0xFF,0x0D,0x0A};
const uchar zcmd_output4_open[]={0x3A,0x88,ADDR_DEST,0x04,0x00,0x0D,0x0A};
const uchar zcmd_output4_close[]={0x3A,0x88,ADDR_DEST,0x04,0xFF,0x0D,0x0A};
const uchar zresponse_output_open_close[]={0xA3,ADDR_DEST,0x00,0xFF,0x0D,0x0A};

//get all relays status.
const uchar zcmd_get_all_relay_status[]={0x3A,0x99,ADDR_DEST,0x00,0x0D,0x0A};
const uchar zresponse_all_relay_status[]={0xA3,ADDR_DEST,0xFF,0xFF,0xFF,0xFF,0x0D,0x0A};
//get all input status.
const uchar zcmd_get_all_inputs_status[]={0x3A,0x98,ADDR_DEST,0x00,0x0D,0x0A};
const uchar zresponse_all_inputs_status[]={0xA5,ADDR_DEST,0xFF,0xFF,0xFF,0xFF,0x0D,0x0A};

class ZIOModule : public QObject
{
    Q_OBJECT
public:
    typedef enum
    {
        OutputPort1=1,
        OutputPort2=2,
        OutputPort3=3,
        OutputPort4=4,
    }ZOutputPort;
    //portName: ttyUSB0.
    //responseTimeout: the wait time for the device response.
    explicit ZIOModule(QString portName,qint32 responseTimeOut=2000,QObject *parent = 0);
    ~ZIOModule();

    //execute serial port initial operations.
    bool ZDoInit();

    //do some clean work here.
    void ZCleanUp();

    //set output status of specified port.
    bool ZSetOutputPort(ZOutputPort port,bool bOpen);

    //get all output port status.
    qint32 ZGetOutputPortsS
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值