From 3970068b82a21617443fd99a152723e54289ecf2 Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期三, 08 一月 2025 16:14:49 +0800
Subject: [PATCH] 1.继续移入相关文件,警告功能等;
---
SourceCode/Bond/BoounionPLC/PLC.h | 77 ++++++++++++++++++++++++++++++++++++++
1 files changed, 77 insertions(+), 0 deletions(-)
diff --git a/SourceCode/Bond/BoounionPLC/PLC.h b/SourceCode/Bond/BoounionPLC/PLC.h
index 7922f2f..40bf436 100644
--- a/SourceCode/Bond/BoounionPLC/PLC.h
+++ b/SourceCode/Bond/BoounionPLC/PLC.h
@@ -1,5 +1,38 @@
#pragma once
#include <string>
+#include "AlarmMonitor.h"
+#include "MMSystem.h"
+#pragma comment(lib,"winmm")
+
+
+typedef std::function<void(void* pFrom, int)> ONPLCSTATECHANGED;
+typedef std::function<void(void* pFrom, int)> ONPLCMONITORDATA;
+typedef std::function<void(void* pFrom, CAlarm*, int)> ONALARM;
+typedef struct _PLCListener
+{
+ ONPLCSTATECHANGED onStateChanged;
+ ONPLCMONITORDATA onMonitorData;
+ ONALARM onAlarm;
+} PLCListener;
+
+typedef struct _MONITOR
+{
+ int id;
+ int beginAddr;
+ int readLen;
+ MC::SOFT_COMPONENT softComponent;
+ char* szRecvBuffer;
+ HANDLE hEvent;
+ ULONGLONG readCount;
+} MONITOR;
+
+enum class PLCSTATE
+{
+ READY = 0,
+ CONNECTING,
+ CONNECTED,
+ DISCONNECTED
+};
class CPLC
{
@@ -9,13 +42,57 @@
~CPLC();
public:
+ void setWorkDir(const char* pszDir);
+ void init();
+ void term();
+ void sendBroadcast(CComponent* pSender, CIntent* pIntent);
+ void onRecvBroadcast(CComponent* pSender, CIntent* pIntent);
+ bool isConnected();
+ void setActionInterval(unsigned int nInterval);
std::string& getName();
std::string& getIp();
unsigned int getPort();
+ bool isMute();
+ void addComponent(CComponent* pComponent);
+ CComponent* getComponent(const char* pszName);
+ CAlarmMonitor* getAlarmMonitor();
+ unsigned onMonitor();
+ void OnTimer(UINT nTimerid);
+ int addMonitor(int id, int beginAddr, int endAddr, MC::SOFT_COMPONENT softComponent, char* pszRecvBuffer);
+ int readWord(MC::SOFT_COMPONENT softComponent, unsigned int addr, ONREAD funOnRead);
+ int readData(MC::SOFT_COMPONENT softComponent, unsigned int addr, unsigned int nReadLen, ONREADDATA funOnReadData);
+ int writeWord(MC::SOFT_COMPONENT softComponent, unsigned int addr, int value, ONWRITE funOnWrite);
+ int writeDWord(MC::SOFT_COMPONENT softComponent, unsigned int addr, int value, ONWRITE funOnWrite);
+ int writeBit(MC::SOFT_COMPONENT softComponent, unsigned int addr, BOOL bValue, ONWRITE funOnWrite);
+ int writeData(MC::SOFT_COMPONENT softComponent, unsigned int addr, const char* pszData, unsigned int length, ONWRITE funOnWrite);
+
+
+public:
+ HANDLE m_hTimeEvent;
private:
+ void setState(PLCSTATE state);
+ void monitorReadData(MONITOR& monitor);
+ CString& dataToHexString(const char* pData, const int size, CString& strOut);
+
+private:
+ std::string m_strWorkDir;
std::string m_strName;
std::string m_strIp;
unsigned int m_nPort;
+ IMcChannel* m_pChannel;
+ PLCSTATE m_state;
+ PLCListener m_listener;
+ unsigned int m_nActionInterval;
+ unsigned int m_nUnHeartBeat;
+ std::vector<CComponent*> m_components;
+
+private:
+ std::vector<MONITOR> m_monitors;
+ HANDLE m_hMcMonitorStop;
+ HANDLE m_hMcMonitorThreadHandle;
+ unsigned m_mcMonitorThrdaddr;
+ MMRESULT m_nTimerId;
+ bool m_bMute;
};
--
Gitblit v1.9.3