《S7-200 OPC C++读写PC Access服务器》由会员分享,可在线阅读,更多相关《S7-200 OPC C++读写PC Access服务器(11页珍藏版)》请在金锄头文库上搜索。
1、S7-200 OPC C+读写PC Access服务器 操作系统:Windows 7旗舰版开发工具:VS2010开发语言:MFC描述:对S7-200的VD100-VD220的31个双字寄存器进行写;头文件:OPCComm.h#pragma once#include StdAfx.hconst LPWSTR g_szItemID31 = L2, VD100, real, L2, VD104, real, L2, VD108, real, L2, VD112, real, L2, VD116, real,L2, VD120, real, L2, VD124, real, L2, VD128, re
2、al, L2, VD132, real, L2, VD136, real,L2, VD140, real, L2, VD144, real, L2, VD148, real, L2, VD152, real, L2, VD156, real,L2, VD160, real, L2, VD164, real, L2, VD168, real, L2, VD172, real, L2, VD176, real,/VD164L2, VD180, real, L2, VD184, real, L2, VD188, real, L2, VD192, real, L2, VD196, real,L2, V
3、D200, real, L2, VD204, real, L2, VD208, real, L2, VD212, real, L2, VD216, real,L2, VD220, real;class COPCCommpublic:COPCComm(void);COPCComm(void);public:DWORDm_dwAdvise;OPCITEMDEFm_Items31;VARIANT m_ItemValues31; LPWSTR m_ItemID31;OPCITEMATTRIBUTES *m_pItAttr;IUnknown* m_pUnknown;IOPCServer* m_IOPCS
4、erver;IOPCItemMgt* m_IOPCItemMgt;IOPCSyncIO* m_pOPCSync;IOPCGroupStateMgt* m_IOPCGroupStateMgt;IOPCAsyncIO2* m_IOPCAsyncIO2;OPCITEMRESULT* m_ItemResult;HRESULT* m_pErrors;OPCHANDLE m_GrpSrvHandle;MULTI_QI m_arrMultiQI6;DWORD m_TransactionID;OPCITEMDEF* m_pItems;OPCITEMSTATE* bdg;public:bool ConnectS
5、rv(void);bool Disconnect(void);bool AddGroup(void);bool AddItem(DWORD NumItems);bool Write(DWORD NumItems);bool RemoveGroup(void);bool RemovItem(DWORD NumItems);float Read(DWORD NumItems);源文件:OPCComm.cpp#include StdAfx.h#include OPCComm.hCOPCComm:COPCComm(void)int i;m_pItAttr = new OPCITEMATTRIBUTES
6、31;for(i = 0; i RemoveGroup(m_GrpSrvHandle,true);m_IOPCItemMgt-Release();m_IOPCServer-Release();return false;bool COPCComm:AddGroup()/ TODO: Add your control notification handler code hereLONG TimBias;FLOAT PercDeadband;DWORD dwLCID;DWORD RevUpRate; /outHRESULT r1;TimBias = 0;PercDeadband = 0.0;dwLC
7、ID = 0x409;r1 = m_IOPCServer-AddGroup(Lgru1, TRUE, 500, 1, &TimBias, &PercDeadband, dwLCID, &m_GrpSrvHandle, &RevUpRate, IID_IOPCItemMgt, (LPUNKNOWN*)&m_IOPCItemMgt);if(!FAILED(r1) /AfxMessageBox(_T(Successfully added group to server!); return false;elseAfxMessageBox(_T(Cant add group to server!); m
8、_IOPCItemMgt = NULL;return true;return false;bool COPCComm:AddItem(DWORD NumItems)/ TODO: Add your control notification handler code hereOPCITEMDEF* pItems;OPCITEMRESULT* pItResult;HRESULT* pErrors; HRESULT r1;DWORD i;/DWORD NumItems;/NumItems = 31;pItems = new OPCITEMDEFNumItems;for(i = 0; i AddItems(NumItems, pItems, &pItResult, &pErrors); if(FAILED(r1) &(r1 != S_FALSE) AfxMessageBox(_T(AddItems- failed!);if(m_IOPCServer != NULL)m_IOPCServer-Release();delete pItems;return true; /exit(1);for (i = 0; i