#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
#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