添加管控软件和相机的通讯
This commit is contained in:
@@ -2,11 +2,13 @@
|
||||
#define MODBUSTCPMANAGER_H
|
||||
|
||||
#include "modbusconfig.h"
|
||||
#include "../models/visionresult.h"
|
||||
|
||||
#include <QQueue>
|
||||
#include <QObject>
|
||||
#include <QModbusDevice>
|
||||
#include <QString>
|
||||
#include <QVector>
|
||||
#include <QtGlobal>
|
||||
#include <functional>
|
||||
|
||||
@@ -20,6 +22,7 @@ class ModbusTcpManager : public QObject
|
||||
|
||||
public:
|
||||
using Completion = std::function<void(bool, quint16, const QString &)>;
|
||||
using VisionWriteCallback = std::function<void(VisionWriteOutcome, const QString &)>;
|
||||
|
||||
explicit ModbusTcpManager(const ModbusConfig &config,
|
||||
QObject *parent = nullptr);
|
||||
@@ -29,6 +32,11 @@ public:
|
||||
|
||||
void readCoil(int address,
|
||||
const std::function<void(bool, bool, const QString &)> &callback);
|
||||
void readCoils(
|
||||
int startAddress, quint16 count,
|
||||
const std::function<void(
|
||||
bool, const QVector<bool> &, const QString &)> &callback,
|
||||
bool visionRequest = false);
|
||||
void readHoldingRegister(
|
||||
int address,
|
||||
const std::function<void(bool, quint16, const QString &)> &callback);
|
||||
@@ -37,24 +45,46 @@ public:
|
||||
void writeHoldingRegister(
|
||||
int address, quint16 value,
|
||||
const std::function<void(bool, const QString &)> &callback);
|
||||
bool readRReal(
|
||||
int rAddress,
|
||||
const std::function<void(bool, float, const QString &)> &callback);
|
||||
bool writeRReal(
|
||||
int rAddress, float value,
|
||||
const std::function<void(bool, const QString &)> &callback);
|
||||
bool readRReals(int rAddress, int count,
|
||||
const std::function<void(bool, const QVector<double> &, const QString &)> &callback,
|
||||
bool lowWordFirst = true);
|
||||
bool writeRReals(int rAddress, const QVector<double> &values,
|
||||
const VisionWriteCallback &callback, bool lowWordFirst = true,
|
||||
const std::function<bool()> &beforeSend = {});
|
||||
void readVisionCoil(int address,
|
||||
const std::function<void(bool, bool, const QString &)> &callback);
|
||||
void writeVisionCoil(int address, bool value, const VisionWriteCallback &callback,
|
||||
const std::function<bool()> &beforeSend = {});
|
||||
void cancelVisionRequests(const QString &reason);
|
||||
void abortAll(const QString &reason);
|
||||
bool isBusy() const;
|
||||
|
||||
private:
|
||||
using ValuesCompletion = std::function<void(
|
||||
bool, const QVector<quint16> &, const QString &)>;
|
||||
|
||||
struct Request
|
||||
{
|
||||
Request()
|
||||
: registerType(0)
|
||||
, address(-1)
|
||||
, value(0)
|
||||
, count(0)
|
||||
, write(false)
|
||||
{
|
||||
}
|
||||
Request(int type, int requestAddress, quint16 requestValue,
|
||||
bool requestWrite, const Completion &requestCallback)
|
||||
Request(int type, int requestAddress, quint16 requestCount,
|
||||
const QVector<quint16> &requestValues, bool requestWrite,
|
||||
const ValuesCompletion &requestCallback)
|
||||
: registerType(type)
|
||||
, address(requestAddress)
|
||||
, value(requestValue)
|
||||
, count(requestCount)
|
||||
, values(requestValues)
|
||||
, write(requestWrite)
|
||||
, callback(requestCallback)
|
||||
{
|
||||
@@ -62,16 +92,22 @@ private:
|
||||
|
||||
int registerType;
|
||||
int address;
|
||||
quint16 value;
|
||||
quint16 count;
|
||||
QVector<quint16> values;
|
||||
bool write;
|
||||
Completion callback;
|
||||
ValuesCompletion callback;
|
||||
bool vision = false;
|
||||
bool sent = false;
|
||||
VisionWriteCallback writeCallback;
|
||||
std::function<bool()> beforeSend;
|
||||
};
|
||||
|
||||
void enqueue(const Request &request);
|
||||
void startNext();
|
||||
void ensureConnected();
|
||||
void startCurrentRequest();
|
||||
void finishCurrent(bool success, quint16 value, const QString &error);
|
||||
void finishCurrent(bool success, const QVector<quint16> &values,
|
||||
const QString &error);
|
||||
void handleConnectionFailure(const QString &error);
|
||||
void ensureClient();
|
||||
void setError(const QString &text);
|
||||
@@ -92,6 +128,7 @@ private:
|
||||
bool m_hasCurrentRequest;
|
||||
bool m_connecting;
|
||||
bool m_aborting;
|
||||
bool m_cancelingVision = false;
|
||||
int m_connectAttempts;
|
||||
QString m_lastErrorText;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user