84 lines
1.5 KiB
C++
84 lines
1.5 KiB
C++
#include "Hd_PLC_Adaptor.h"
|
|||
|
|
|
||
|
|
#include <QDebug>
|
||
|
|
|
||
|
|
Hd_PLC_Adaptor* create(int type)
|
||
|
|
{
|
||
|
|
qDebug() << "Hd_PLC_Adaptor create success!";
|
||
|
|
return new Hd_PLC_Adaptor(type, nullptr);
|
||
|
|
}
|
||
|
|
|
||
|
|
void destory(Hd_PLC_Adaptor* ptr)
|
||
|
|
{
|
||
|
|
if (ptr != nullptr)
|
||
|
|
{
|
||
|
|
delete ptr;
|
||
|
|
ptr = nullptr;
|
||
|
|
}
|
||
|
|
qDebug() << "Hd_PLC_Adaptor destory success!";
|
||
|
|
}
|
||
|
|
|
||
|
|
Hd_PLC_Adaptor::Hd_PLC_Adaptor(int type, QObject* parent) : PbGlobalObject(type, parent)
|
||
|
|
{
|
||
|
|
famliy = PGOFAMLIY::PLC;
|
||
|
|
m_plc = new Hd_SocketModule_PLC(type, parent);
|
||
|
|
}
|
||
|
|
|
||
|
|
Hd_PLC_Adaptor::~Hd_PLC_Adaptor()
|
||
|
|
{
|
||
|
|
if (m_plc)
|
||
|
|
{
|
||
|
|
m_plc->deleteLater();
|
||
|
|
m_plc = nullptr;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
bool Hd_PLC_Adaptor::setParameter(const QMap<QString, QString>& param)
|
||
|
|
{
|
||
|
|
if (m_plc == nullptr)
|
||
|
|
return false;
|
||
|
|
|
||
|
|
return m_plc->setParameter(param);
|
||
|
|
}
|
||
|
|
|
||
|
|
QMap<QString, QString> Hd_PLC_Adaptor::parameters()
|
||
|
|
{
|
||
|
|
if (m_plc == nullptr)
|
||
|
|
return QMap<QString, QString>();
|
||
|
|
|
||
|
|
return m_plc->parameters();
|
||
|
|
}
|
||
|
|
|
||
|
|
bool Hd_PLC_Adaptor::init()
|
||
|
|
{
|
||
|
|
if (m_plc == nullptr)
|
||
|
|
return false;
|
||
|
|
|
||
|
|
return m_plc->init();
|
||
|
|
}
|
||
|
|
|
||
|
|
bool Hd_PLC_Adaptor::setData(const vector<cv::Mat>& mat, const QStringList& data)
|
||
|
|
{
|
||
|
|
UNREFERENCED_PARAMETER(mat);
|
||
|
|
if (m_plc == nullptr)
|
||
|
|
return false;
|
||
|
|
|
||
|
|
if (data.isEmpty() || data.size() != 1)//每次只处理一条命令
|
||
|
|
return false;
|
||
|
|
|
||
|
|
return m_plc->setData(data[0].toLocal8Bit());
|
||
|
|
}
|
||
|
|
|
||
|
|
bool Hd_PLC_Adaptor::data(std::vector<cv::Mat>& mat, QStringList& data)
|
||
|
|
{
|
||
|
|
UNREFERENCED_PARAMETER(mat);
|
||
|
|
if (m_plc == nullptr)
|
||
|
|
return false;
|
||
|
|
|
||
|
|
QByteArray bytes;
|
||
|
|
bool res = m_plc->data(bytes);
|
||
|
|
if (res)
|
||
|
|
data.append(bytes.toHex());
|
||
|
|
return res;
|
||
|
|
}
|