SEI Modbus Dev Contd
This commit is contained in:
parent
26877b7941
commit
32ca136904
Binary file not shown.
@ -62,7 +62,8 @@
|
|||||||
#define EXT_ANALOG_INPUT_ACQUISITION_PERIOD 200000 //nanoseconds
|
#define EXT_ANALOG_INPUT_ACQUISITION_PERIOD 200000 //nanoseconds
|
||||||
#define FILESYSTEM_FORCED_SYNC_TIMEOUT (qint64)2400000 //2.4 million milliseconds = 40 minutes
|
#define FILESYSTEM_FORCED_SYNC_TIMEOUT (qint64)2400000 //2.4 million milliseconds = 40 minutes
|
||||||
#define MAX_ENGINEERING_LOG_FILESIZE (qint32)1000000 //~1Mb
|
#define MAX_ENGINEERING_LOG_FILESIZE (qint32)1000000 //~1Mb
|
||||||
//#define OUTPUT_EXTIO_SAMPLE_RATE
|
#define SEI_CLIENT_RECONNECT_TIMEOUT 200 //ms
|
||||||
|
#define SEI_CLIENT_CONNECTION_TIMEOUT 500 //ms
|
||||||
|
|
||||||
#define USE_DAQNAVI_LIB
|
#define USE_DAQNAVI_LIB
|
||||||
|
|
||||||
|
|||||||
@ -115,7 +115,7 @@ CSEISettingsPage::CSEISettingsPage(QGraphicsWidget *Parent)
|
|||||||
mSEIModbusLinkLED->setPos(IpSettingsPosx,IpSettingsPosy+5);
|
mSEIModbusLinkLED->setPos(IpSettingsPosx,IpSettingsPosy+5);
|
||||||
|
|
||||||
IpSettingsPosy += 30;
|
IpSettingsPosy += 30;
|
||||||
mModbusSEIConnectionState = new QGraphicsTextItem("Connection HPC: DÉCONNECTÉE",this);
|
mModbusSEIConnectionState = new QGraphicsTextItem("Connection NetTrac: DÉCONNECTÉE",this);
|
||||||
mModbusSEIConnectionState->setFont(font);
|
mModbusSEIConnectionState->setFont(font);
|
||||||
mModbusSEIConnectionState->setPos(IpSettingsPosx+30,IpSettingsPosy);
|
mModbusSEIConnectionState->setPos(IpSettingsPosx+30,IpSettingsPosy);
|
||||||
mSEIConnectionLED = new QGraphicsPixmapItem(QPixmap("./Images/red-led-on-md.png").scaled(25,25),this);
|
mSEIConnectionLED = new QGraphicsPixmapItem(QPixmap("./Images/red-led-on-md.png").scaled(25,25),this);
|
||||||
@ -157,7 +157,7 @@ void CSEISettingsPage::ButtonClicked(CTextButtonWidget *BtnPtr)
|
|||||||
QString LogEntry = QString("Changement des paramètres Modbus SEI -> Adresse IP %1").arg(IPAddress.toString().toAscii().data());
|
QString LogEntry = QString("Changement des paramètres Modbus SEI -> Adresse IP %1").arg(IPAddress.toString().toAscii().data());
|
||||||
CZTLog::instance()->AddLogString(LogEntry,true);
|
CZTLog::instance()->AddLogString(LogEntry,true);
|
||||||
|
|
||||||
mProgramHandle->ApplySEISettings();//TODO
|
mProgramHandle->ApplySEISettings(IPAddress);//TODO
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,19 +1,27 @@
|
|||||||
#include "ModbusSEIMgr.h"
|
#include "ModbusSEIMgr.h"
|
||||||
#include <QTcpSocket>
|
#include <QTcpSocket>
|
||||||
#include "ModbusCCDefs.h"
|
#include "ModbusCCDefs.h"
|
||||||
|
#include "GlobalDefine.h"
|
||||||
|
|
||||||
CModbusSEIMgr::CModbusSEIMgr(CModbusRepository *Repo, int ModbusPort, int DevID):
|
CModbusSEIMgr::CModbusSEIMgr(CModbusRepository *Repo, QHostAddress ServerIP, int ModbusPort, int DevID):
|
||||||
CModbusBackend(Repo)
|
CModbusBackend(Repo)
|
||||||
{
|
{
|
||||||
// connect(mModbusTCPSocketHandle,SIGNAL(readyRead()),this,SLOT(ModbusDataReady()));
|
// connect(mModbusTCPSocketHandle,SIGNAL(readyRead()),this,SLOT(ModbusDataReady()));
|
||||||
mModbusMode = MODBUS_MASTER_MODE;
|
mModbusMode = MODBUS_MASTER_MODE;
|
||||||
mModbusPort = ModbusPort;
|
mModbusPort = ModbusPort;
|
||||||
mDeviceID = DevID;
|
mDeviceID = DevID;
|
||||||
|
mSEIIPAddress = ServerIP;
|
||||||
|
|
||||||
|
mConnectionTimer = new QTimer();
|
||||||
|
mConnectionTimer->setInterval(SEI_CLIENT_RECONNECT_TIMEOUT);
|
||||||
|
mConnectionTimer->setSingleShot(false);
|
||||||
|
mConnectionTimer->stop();
|
||||||
|
|
||||||
mModbusTCPSocketHandle = new QTcpSocket();
|
mModbusTCPSocketHandle = new QTcpSocket();
|
||||||
connect(mModbusTCPSocketHandle,SIGNAL(readyRead()),this,SLOT(ModbusDataReady()));
|
connect(mModbusTCPSocketHandle,SIGNAL(readyRead()),this,SLOT(ModbusDataReady()));
|
||||||
connect(mModbusTCPSocketHandle,SIGNAL(disconnected()),this,SLOT(SocketDisconnected()));
|
connect(mModbusTCPSocketHandle,SIGNAL(disconnected()),this,SLOT(SocketDisconnected()));
|
||||||
connect(mModbusTCPSocketHandle,SIGNAL(connected()),this,SLOT(SocketConnected()));
|
connect(mModbusTCPSocketHandle,SIGNAL(connected()),this,SLOT(SocketConnected()));
|
||||||
|
connect(mConnectionTimer,SIGNAL(timeout()),this,SLOT(ConnectionTimerExpired()));
|
||||||
}
|
}
|
||||||
|
|
||||||
CModbusSEIMgr::~CModbusSEIMgr()
|
CModbusSEIMgr::~CModbusSEIMgr()
|
||||||
@ -24,9 +32,20 @@ CModbusSEIMgr::~CModbusSEIMgr()
|
|||||||
mModbusTCPSocketHandle->waitForDisconnected(1000);
|
mModbusTCPSocketHandle->waitForDisconnected(1000);
|
||||||
}
|
}
|
||||||
delete mModbusTCPSocketHandle;
|
delete mModbusTCPSocketHandle;
|
||||||
|
|
||||||
|
if(mConnectionTimer)
|
||||||
|
delete mConnectionTimer;
|
||||||
|
if(mSEIWatchdogTimer)
|
||||||
|
delete mSEIWatchdogTimer;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CModbusSEIMgr::ConnectToSlave(QString SlaveIP, int SlavePort)
|
int CModbusSEIMgr::StartSEICommunication()
|
||||||
|
{
|
||||||
|
mConnectionTimer->start();
|
||||||
|
return RET_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
int CModbusSEIMgr::ConnectToSlave(QHostAddress SlaveIP, int SlavePort)
|
||||||
{
|
{
|
||||||
if(mModbusTCPSocketHandle->state() != QAbstractSocket::UnconnectedState)
|
if(mModbusTCPSocketHandle->state() != QAbstractSocket::UnconnectedState)
|
||||||
{
|
{
|
||||||
@ -42,12 +61,12 @@ int CModbusSEIMgr::DisconnectFromSlave()
|
|||||||
{
|
{
|
||||||
if(mModbusTCPSocketHandle->state() != QAbstractSocket::ConnectedState)
|
if(mModbusTCPSocketHandle->state() != QAbstractSocket::ConnectedState)
|
||||||
{
|
{
|
||||||
qDebug("Trying to disconnect a non connected socket");
|
|
||||||
mModbusTCPSocketHandle->disconnectFromHost();
|
mModbusTCPSocketHandle->disconnectFromHost();
|
||||||
|
mConnectionTimer->start();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug("Requesting Disconnection...");
|
qDebug("Requesting Disconnection from NetTrac...");
|
||||||
mModbusTCPSocketHandle->disconnectFromHost();
|
mModbusTCPSocketHandle->disconnectFromHost();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -55,13 +74,16 @@ int CModbusSEIMgr::DisconnectFromSlave()
|
|||||||
void CModbusSEIMgr::SocketConnected()
|
void CModbusSEIMgr::SocketConnected()
|
||||||
{
|
{
|
||||||
emit ModbusMasterConnected(this);
|
emit ModbusMasterConnected(this);
|
||||||
qDebug("Master: Connection established with slave");
|
qDebug("Master: Connection established with NetTrac");
|
||||||
|
mConnectionTimer->stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CModbusSEIMgr::SocketDisconnected()
|
void CModbusSEIMgr::SocketDisconnected()
|
||||||
{
|
{
|
||||||
ModbusLinkDisconnected();
|
ModbusLinkDisconnected();
|
||||||
emit ModbusMasterDisconnected(this);
|
emit ModbusMasterDisconnected(this);
|
||||||
|
mConnectionTimer->start();
|
||||||
|
qDebug("Disconnected from NetTrac");
|
||||||
}
|
}
|
||||||
|
|
||||||
int CModbusSEIMgr::ReadModbusRegisters()
|
int CModbusSEIMgr::ReadModbusRegisters()
|
||||||
@ -70,6 +92,44 @@ int CModbusSEIMgr::ReadModbusRegisters()
|
|||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CModbusSEIMgr::ConnectionTimerExpired()
|
||||||
|
{
|
||||||
|
//Establish connection only if not connected
|
||||||
|
if(mModbusTCPSocketHandle->state() == QAbstractSocket::UnconnectedState)
|
||||||
|
{
|
||||||
|
ConnectToSlave(mSEIIPAddress,mModbusPort);
|
||||||
|
mConnectionTimeout.restart();
|
||||||
|
}
|
||||||
|
else if(mModbusTCPSocketHandle->state() == QAbstractSocket::ConnectingState)
|
||||||
|
{
|
||||||
|
//Default connection timeout is 1s for sockets. We want this to be shorter.
|
||||||
|
//if connection timeout is reached, disconnect and retry.
|
||||||
|
if(mConnectionTimeout.hasExpired(SEI_CLIENT_CONNECTION_TIMEOUT))
|
||||||
|
{
|
||||||
|
mModbusTCPSocketHandle->disconnectFromHost();
|
||||||
|
qDebug("Connection timeout expired... disconnecting");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int CModbusSEIMgr::SEISettingsChanged(QHostAddress ServerIP, int ModbusPort, int DevID)
|
||||||
|
{
|
||||||
|
if(DevID > 255)
|
||||||
|
{
|
||||||
|
return RET_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
mSEIIPAddress = ServerIP;
|
||||||
|
mModbusPort = ModbusPort;
|
||||||
|
mDeviceID = DevID;
|
||||||
|
|
||||||
|
//Make shure we are disconnected. Connection timer will do the reconnection.
|
||||||
|
DisconnectFromSlave();
|
||||||
|
|
||||||
|
return RET_OK;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void CModbusSEIMgr::RegistersDatabaseUpdated(quint16 StartAddress, quint16 Length)
|
void CModbusSEIMgr::RegistersDatabaseUpdated(quint16 StartAddress, quint16 Length)
|
||||||
{
|
{
|
||||||
@ -77,24 +137,9 @@ void CModbusSEIMgr::RegistersDatabaseUpdated(quint16 StartAddress, quint16 Lengt
|
|||||||
Q_UNUSED(Length)
|
Q_UNUSED(Length)
|
||||||
|
|
||||||
emit ModbusMasterRepositoryUpdated();
|
emit ModbusMasterRepositoryUpdated();
|
||||||
qDebug("Database updated with ZT data...");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CModbusSEIMgr::ModbusResponseException(quint8 ExceptionCode, quint8 FctCode)
|
void CModbusSEIMgr::ModbusResponseException(quint8 ExceptionCode, quint8 FctCode)
|
||||||
{
|
{
|
||||||
qDebug("Modbus MASTER exception: code:%d Fct:%d",ExceptionCode,FctCode);
|
qDebug("Modbus MASTER exception: code:%d Fct:%d",ExceptionCode,FctCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
int CModbusSEIMgr::SendAN1ToZT()
|
|
||||||
{
|
|
||||||
//return SendWriteHoldingRegistersRequest(CC_AN1_REGISTER_ADDRESS,1);
|
|
||||||
//return SendWriteSingleRegisterRequest(CC_AN1_REGISTER_ADDRESS);
|
|
||||||
return RET_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
int CModbusSEIMgr::SendAN2ToZT()
|
|
||||||
{
|
|
||||||
//return SendWriteHoldingRegistersRequest(CC_AN2_REGISTER_ADDRESS,1);
|
|
||||||
//return SendWriteSingleRegisterRequest(CC_AN2_REGISTER_ADDRESS);
|
|
||||||
return RET_OK;
|
|
||||||
}
|
|
||||||
|
|||||||
@ -1,8 +1,12 @@
|
|||||||
#ifndef CMODBUSSEIMGR_H
|
#ifndef CMODBUSSEIMGR_H
|
||||||
#define CMODBUSSEIMGR_H
|
#define CMODBUSSEIMGR_H
|
||||||
|
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include "ModbusBackend.h"
|
#include "ModbusBackend.h"
|
||||||
|
#include <QTimer>
|
||||||
|
#include <QElapsedTimer>
|
||||||
|
#include <QHostAddress>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -11,20 +15,26 @@ class CModbusSEIMgr : public CModbusBackend
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit CModbusSEIMgr(CModbusRepository *Repo, int ModbusPort, int DevID);
|
explicit CModbusSEIMgr(CModbusRepository *Repo, QHostAddress ServerIP, int ModbusPort, int DevID);
|
||||||
~CModbusSEIMgr();
|
~CModbusSEIMgr();
|
||||||
|
|
||||||
int ConnectToSlave(QString SlaveIP, int SlavePort);
|
int ConnectToSlave(QHostAddress SlaveIP, int SlavePort);
|
||||||
int DisconnectFromSlave();
|
int DisconnectFromSlave();
|
||||||
int ReadModbusRegisters();
|
int ReadModbusRegisters();
|
||||||
int SendAN1ToZT();
|
int StartSEICommunication();
|
||||||
int SendAN2ToZT();
|
int SEISettingsChanged(QHostAddress ServerIP, int ModbusPort, int DevID);
|
||||||
|
|
||||||
|
|
||||||
virtual void RegistersDatabaseUpdated(quint16 StartAddress, quint16 Length);
|
virtual void RegistersDatabaseUpdated(quint16 StartAddress, quint16 Length);
|
||||||
virtual void ModbusResponseException(quint8 ExceptionCode, quint8 FctCode);
|
virtual void ModbusResponseException(quint8 ExceptionCode, quint8 FctCode);
|
||||||
|
|
||||||
|
QTimer *mConnectionTimer;
|
||||||
|
QTimer *mSEIWatchdogTimer;
|
||||||
|
QElapsedTimer mConnectionTimeout;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int mModbusPort;
|
int mModbusPort;
|
||||||
|
QHostAddress mSEIIPAddress;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void ModbusMasterConnected(CModbusSEIMgr *);
|
void ModbusMasterConnected(CModbusSEIMgr *);
|
||||||
@ -34,6 +44,7 @@ signals:
|
|||||||
public slots:
|
public slots:
|
||||||
void SocketConnected();
|
void SocketConnected();
|
||||||
void SocketDisconnected();
|
void SocketDisconnected();
|
||||||
|
void ConnectionTimerExpired();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CMODBUSSEIMGR_H
|
#endif // CMODBUSSEIMGR_H
|
||||||
|
|||||||
@ -246,7 +246,10 @@ void CZTSettingsFileMgr::LogSettings(CZTSettingsData *SettingsData, bool LogStat
|
|||||||
stream << QString().fromUtf8(" Utilisation communication Modbus CC = ") << SettingsData->mUseModbusCC;
|
stream << QString().fromUtf8(" Utilisation communication Modbus CC = ") << SettingsData->mUseModbusCC;
|
||||||
CZTLog::instance()->AddLogString(temp,true);
|
CZTLog::instance()->AddLogString(temp,true);
|
||||||
temp.clear();
|
temp.clear();
|
||||||
stream << QString().fromUtf8(" Adresse IP réseau TLT = ") << SettingsData->mModbusCCHostAddress.toString();
|
stream << QString().fromUtf8(" Adresse IP CC = ") << SettingsData->mModbusCCHostAddress.toString();
|
||||||
|
CZTLog::instance()->AddLogString(temp,true);
|
||||||
|
temp.clear();
|
||||||
|
stream << QString().fromUtf8(" Adresse IP SEI = ") << SettingsData->mSEIModbusHostAddress.toString();
|
||||||
CZTLog::instance()->AddLogString(temp,true);
|
CZTLog::instance()->AddLogString(temp,true);
|
||||||
temp.clear();
|
temp.clear();
|
||||||
|
|
||||||
|
|||||||
@ -599,7 +599,6 @@ unsigned int CZoneTest::InitZT()
|
|||||||
connect(mModbusCCMgr,SIGNAL(RepoHasChanged()),TransportInterface,SLOT(ModbusCCUpdated()));
|
connect(mModbusCCMgr,SIGNAL(RepoHasChanged()),TransportInterface,SLOT(ModbusCCUpdated()));
|
||||||
|
|
||||||
mZTStateMachine->BindModbusCCMgrPtr(mModbusCCMgr);
|
mZTStateMachine->BindModbusCCMgrPtr(mModbusCCMgr);
|
||||||
// connect(mModbusCCMgr,SIGNAL(RepoHasChanged()),mZTStateMachine,SLOT(ModbusCCANUpdate()));
|
|
||||||
connect(mModbusCCMgr,SIGNAL(ModbusCCLinkRecovered()),panel.mZTMainPage,SLOT(ModbusCCConnected()));
|
connect(mModbusCCMgr,SIGNAL(ModbusCCLinkRecovered()),panel.mZTMainPage,SLOT(ModbusCCConnected()));
|
||||||
connect(mModbusCCMgr,SIGNAL(ModbusCCLinkLost()),panel.mZTMainPage,SLOT(ModbusCCDisconnected()));
|
connect(mModbusCCMgr,SIGNAL(ModbusCCLinkLost()),panel.mZTMainPage,SLOT(ModbusCCDisconnected()));
|
||||||
connect(mModbusCCMgr,SIGNAL(ModbusDateTimeReceived(QDateTime*)),this,SLOT(ModbusDateTimeUpdate(QDateTime*)));
|
connect(mModbusCCMgr,SIGNAL(ModbusDateTimeReceived(QDateTime*)),this,SLOT(ModbusDateTimeUpdate(QDateTime*)));
|
||||||
@ -617,8 +616,9 @@ unsigned int CZoneTest::InitZT()
|
|||||||
mSEIModbusRepository->AddHRDataMap(SEI_MODBUS_SEI_DATA_BASE_REG,SEI_MODBUS_SEI_TABLE_DATA_SIZE); //Add the SEI data map
|
mSEIModbusRepository->AddHRDataMap(SEI_MODBUS_SEI_DATA_BASE_REG,SEI_MODBUS_SEI_TABLE_DATA_SIZE); //Add the SEI data map
|
||||||
if(mModbusSEIMgr == 0)
|
if(mModbusSEIMgr == 0)
|
||||||
{
|
{
|
||||||
mModbusSEIMgr = new CModbusSEIMgr(mSEIModbusRepository,ModbusSEIPort,SEIDevID);
|
mModbusSEIMgr = new CModbusSEIMgr(mSEIModbusRepository,mZTSettings->mSEIModbusHostAddress,ModbusSEIPort,SEIDevID);
|
||||||
}
|
}
|
||||||
|
mModbusSEIMgr->StartSEICommunication();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1195,6 +1195,7 @@ void CZoneTest::ModbusSettingsChangedReboot(bool UseModbus, QHostAddress CCHostA
|
|||||||
//Messages from SEI settings page
|
//Messages from SEI settings page
|
||||||
void CZoneTest::OpenSEISettingsPage()
|
void CZoneTest::OpenSEISettingsPage()
|
||||||
{
|
{
|
||||||
|
panel.mSEISettingsPage->SetActualSettings(mZTSettings->mSEIModbusHostAddress);
|
||||||
panel.mSEISettingsPage->show();
|
panel.mSEISettingsPage->show();
|
||||||
panel.mOptionsPage->hide();
|
panel.mOptionsPage->hide();
|
||||||
}
|
}
|
||||||
@ -1204,9 +1205,12 @@ void CZoneTest::CloseSEISettingsPage()
|
|||||||
panel.mSEISettingsPage->hide();
|
panel.mSEISettingsPage->hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CZoneTest::ApplySEISettings()
|
void CZoneTest::ApplySEISettings(QHostAddress SEIHostAdd)
|
||||||
{
|
{
|
||||||
|
mZTSettings->mSEIModbusHostAddress = SEIHostAdd;
|
||||||
|
mZTSettingsFileMgr.SaveSettings(mZTSettings);
|
||||||
|
|
||||||
|
//TODO: apply changes and reconnect.
|
||||||
}
|
}
|
||||||
|
|
||||||
///Messages from ZTLog viewer page
|
///Messages from ZTLog viewer page
|
||||||
|
|||||||
@ -132,7 +132,7 @@ public:
|
|||||||
|
|
||||||
void OpenSEISettingsPage();
|
void OpenSEISettingsPage();
|
||||||
void CloseSEISettingsPage();
|
void CloseSEISettingsPage();
|
||||||
void ApplySEISettings();
|
void ApplySEISettings(QHostAddress SEIHostAdd);
|
||||||
|
|
||||||
void ShowZTLogViewerPage();
|
void ShowZTLogViewerPage();
|
||||||
void HideZTLogViewerPage();
|
void HideZTLogViewerPage();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user