Ich umgehe mit Purebasic die Automation Schnittstelle und verwende direkt die Costumer Interface direkt auf den OPC-Server.
Ist zwar zuerst eine Menge arbeit, läuft aber erheblich stabiler.
Eine gesamte veröffendlichung meiner Arbeit möchte ich nicht da ich diese Beruflich verwende.
Aber die Declaration kann ich Dir geben.
Code: Alles auswählen
;- TOP
; Komment : OPC Define
; Version : v2.101
; Erstellt : 02.12.2004
; Geändert : 13.06.2007
; Author : Michael Kastner (mk-soft)
; Compiler : Unicode
; *********************************************************************************************************
;- Konstanten CLSCTX
#CLSCTX_INPROC_SERVER = $1
#CLSCTX_INPROC_HANDLER = $2
#CLSCTX_LOCAL_SERVER = $4
#CLSCTX_REMOTE_SERVER = $10
#CLSCTX_ALL = $17 ;#CLSCTX_INPROC_SERVER|#CLSCTX_INPROC_HANDLER|#CLSCTX_LOCAL_SERVER|#CLSCTX_REMOTE_SERVER
;- Konstanten OPC
#OPC_DS_CACHE = 1
#OPC_DS_DEVICE = 2
#OPC_READABLE = 1
#OPC_WRITEABLE = 2
#OPC_E_INVALIDHANDLE = ($C0040001)
#OPC_E_BADTYPE = ($C0040004)
#OPC_E_PUBLIC = ($C0040005)
#OPC_E_BADRIGHTS = ($C0040006)
#OPC_E_UNKNOWNITEMID = ($C0040007)
#OPC_E_INVALIDITEMID = ($C0040008)
#OPC_E_INVALIDFILTER = ($C0040009)
#OPC_E_UNKNOWNPATH = ($C004000A)
#OPC_E_RANGE = ($C004000B)
#OPC_E_DUPLICATENAME = ($C004000C)
#OPC_S_UNSUPPORTEDRATE = ($0004000D)
#OPC_S_CLAMP = ($0004000E)
#OPC_S_INUSE = ($0004000F)
#OPC_E_INVALIDCONFIGFILE = ($C0040010)
#OPC_E_NOTFOUND = ($C0040011)
#OPC_E_INVALID_PID = ($C0040203)
#OPC_QUALITY_MASK = $C0
#OPC_STATUS_MASK = $FC
#OPC_LIMIT_MASK = $03
#OPC_QUALITY_BAD = $00
#OPC_QUALITY_UNCERTAIN = $40
#OPC_QUALITY_GOOD = $C0
#OPC_QUALITY_CONFIG_ERROR = $04
#OPC_QUALITY_NOT_CONNECTED = $08
#OPC_QUALITY_DEVICE_FAILURE = $0c
#OPC_QUALITY_SENSOR_FAILURE = $10
#OPC_QUALITY_LAST_KNOWN = $14
#OPC_QUALITY_COMM_FAILURE = $18
#OPC_QUALITY_OUT_OF_SERVICE = $1C
#OPC_QUALITY_LAST_USABLE = $44
#OPC_QUALITY_SENSOR_CAL = $50
#OPC_QUALITY_EGU_EXCEEDED = $54
#OPC_QUALITY_SUB_NORMAL = $58
#OPC_QUALITY_LOCAL_OVERRIDE = $D8
#OPC_LIMIT_OK = $00
#OPC_LIMIT_LOW = $01
#OPC_LIMIT_HIGH = $02
#OPC_LIMIT_CONST = $03
; *********************************************************************************************************
;------------------------------------------------
; *********************************************************************************************************
;- Structure MULTI_QI
Structure MULTI_QI
*pIID.IID;
*pItf.l;
hr.l;
EndStructure
;- Structure COSERVERINFO
Structure COSERVERINFO
dwReserved1.l;
*pwszName;
*pAuthInfo;
dwReserved2.l;
EndStructure
;- Structure SAFEARRAYBOUND
Structure SAFEARRAYBOUND
cElements.l
lLbound.l
EndStructure
;- Structure SAFEARRAY
Structure pData
StructureUnion
bVal.b[0]; AS BYTE ' VT_UI1
iVal.w[0]; AS INTEGER ' VT_I2
lVal.l[0]; AS LONG ' VT_I4
fltVal.f[0]; AS SINGLE ' VT_R4
dblVal.d[0]; AS DOUBLE ' VT_R8
boolVal.w[0]; AS INTEGER ' VT_BOOL
scode.l[0]; AS LONG ' VT_ERROR
cyVal.l[0]; AS LONG ' VT_CY
date.d[0]; AS DOUBLE ' VT_DATE
bstrVal.l[0]; AS LONG ' VT_BSTR
punkVal.l[0]; AS DWORD ' VT_UNKNOWN
pdispVal.l[0]; AS DWORD ' VT_DISPATCH
parray.l[0]; AS DWORD ' VT_ARRAY|*
EndStructureUnion
EndStructure
Structure SAFEARRAY
cDims.w
fFeatures.w
cbElements.l
cLocks.l
*pvData.pData
rgsabound.SAFEARRAYBOUND[1]
EndStructure
; *********************************************************************************************************
;------------------------------------------------
; *********************************************************************************************************
;- Structure OPC
;- Structure OPCGROUPHEADER
Structure OPCGROUPHEADER
dwSize.l
dwItemCount.l
hClientGroup.l
dwTransactionID.l
hrStatus.l
EndStructure
;- Structure OPCITEMHEADER1
Structure OPCITEMHEADER1
hClient.l
dwValueOffset.l
wQuality.w
wReserved.w
ftTimeStampItem.FILETIME
EndStructure
;- Structure OPCITEMHEADER2
Structure OPCITEMHEADER2
hClient.l
dwValueOffset.l
wQuality.w
wReserved.w
EndStructure
;- Structure OPCGROUPHEADERWRITE
Structure OPCGROUPHEADERWRITE
dwItemCount.l
hClientGroup.l
dwTransactionID.l
hrStatus.l
EndStructure
;- Structure OPCITEMHEADERWRITE
Structure OPCITEMHEADERWRITE
hClient.l
dwError.l
EndStructure
;- Structure OPCITEMSTATE
Structure OPCITEMSTATE
hClient.l
ftTimeStamp.FILETIME
wQuality.w
wReserved.w
vDataValue.VARIANT
EndStructure
;- Structure OPCSERVERSTATUS
Structure OPCSERVERSTATUS
ftStartTime.FILETIME
ftCurrentTime.FILETIME
ftLastUpdateTime.FILETIME
dwServerState.l ;OPCSERVERSTATE
dwGroupCount.l
dwBandWidth.l
wMajorVersion.w
wMinorVersion.w
wBuildNumber.w
wReserved.w
EndStructure
;- Structure OPCITEMDEF
Structure OPCITEMDEF
szAccessPath.s;
szItemID.s;
bActive.l;
hClient.l;
dwBlobSize.l;
*pBlob.l;
vtRequestedDataType.w;
wReserved.w;
EndStructure
;- Structure OPCITEMATTRIBUTES
Structure OPCITEMATTRIBUTES
szAccessPath.s;
szItemID.s;
bActive.l
hClient.l
hServer.l
dwAccessRights.l
dwBlobSize.l
*pBlob.l;
vtRequestedDataType.l
vtCanonicalDataType.l
dwEUType.l ;OPCEUTYPE
vEUInfo.VARIANT
EndStructure
;- Structure OPCITEMRESULT
Structure OPCITEMRESULT
hServer.l
vtCanonicalDataType.w
wReserved.w
dwAccessRights.l
dwBlobSize.l
*pBlob.l;
EndStructure
; *********************************************************************************************************
;------------------------------------------------
; *********************************************************************************************************
;- OPC-Server Interfaces
;-
;- IOPCServer interface definition
Interface IOPCServer
QueryInterface(a, b)
AddRef()
Release()
AddGroup(a, b, c, d, e, f, g, h, i, j, k)
GetErrorString(a, b, c)
GetGroupByName(a, b, c)
GetStatus(a)
RemoveGroup(a, b)
CreateGroupEnumerator(a, b, c)
EndInterface
;- IOPCServerPublicGroups interface definition
;
Interface IOPCServerPublicGroups
QueryInterface(a, b)
AddRef()
Release()
GetPublicGroupByName(a, b, c)
RemovePublicGroup(a, b)
EndInterface
;- IOPCBrowseServerAddressSpace interface definition
;
Interface IOPCBrowseServerAddressSpace
QueryInterface(a, b)
AddRef()
Release()
QueryOrganization(a)
ChangeBrowsePosition(a, b)
BrowseOPCItemIDs(a, b, c, d, e)
GetItemID(a, b)
BrowseAccessPaths(a, b)
EndInterface
;- IOPCGroupStateMgt interface definition
;
Interface IOPCGroupStateMgt
QueryInterface(a, b)
AddRef()
Release()
GetState(a, b, c, d, e, f, g, h)
SetState(a, b, c, d, e, f, g)
SetName(a)
CloneGroup(a, b, c)
EndInterface
;- IOPCPublicGroupStateMgt interface definition
;
Interface IOPCPublicGroupStateMgt
QueryInterface(a, b)
AddRef()
Release()
GetState(a)
MoveToPublic()
EndInterface
;- IOPCSyncIO interface definition
;
Interface IOPCSyncIO
QueryInterface(a, b)
AddRef()
Release()
Read(a, b, c, d, e)
Write(a, b, c, d)
EndInterface
;- IOPCAsyncIO interface definition
;
Interface IOPCAsyncIO
QueryInterface(a, b)
AddRef()
Release()
Read(a, b, c, d, e, f)
Write(a, b, c, d, e, f)
Refresh(a, b, c)
Cancel(a)
EndInterface
;- IOPCItemMgt interface definition
;
Interface IOPCItemMgt
QueryInterface(a, b)
AddRef()
Release()
AddItems(a, b, c, d)
ValidateItems(a, b, c, d, e)
RemoveItems(a, b, c)
SetActiveState(a, b, c, d)
SetClientHandles(a, b, c, d)
SetDatatypes(a, b, c, d)
CreateEnumerator(a, b)
EndInterface
;- IEnumOPCItemAttributes interface definition
;
Interface IEnumOPCItemAttributes
QueryInterface(a, b)
AddRef()
Release()
Next(a, b, c)
Skip(a)
Reset()
Clone(a)
EndInterface
;- IOPCDataCallback interface definition
;
Interface IOPCDataCallback
QueryInterface(a, b)
AddRef()
Release()
OnDataChange(a, b, c, d, e, f, g, h, i, j)
OnReadComplete(a, b, c, d, e, f, g, h, i, j)
OnWriteComplete(a, b, c, d, e, f)
OnCancelComplete(a, b)
EndInterface
;- IOPCAsyncIO2 interface definition
;
Interface IOPCAsyncIO2
QueryInterface(a, b)
AddRef()
Release()
Read(a, b, c, d, e)
Write(a, b, c, d, e, f)
Refresh2(a, b, c)
Cancel2(a)
SetEnable(a)
GetEnable(a)
EndInterface
;- IOPCItemProperties interface definition
;
Interface IOPCItemProperties
QueryInterface(a, b)
AddRef()
Release()
QueryAvailableProperties(a, b, c, d, e)
GetItemProperties(a, b, c, d, e)
LookupItemIDs(a, b, c, d, e)
EndInterface
;- IOPCShutdown interface definition
;
Interface IOPCShutdown
QueryInterface(a, b)
AddRef()
Release()
ShutdownRequest(a)
EndInterface
;- IOPCCommon interface definition
;
Interface IOPCCommon
QueryInterface(a, b)
AddRef()
Release()
SetLocaleID(a)
GetLocaleID(a)
QueryAvailableLocaleIDs(a, b)
GetErrorString(a, b)
SetClientName(a)
EndInterface
;- IOPCEventServer interface definition
;
Interface IOPCEventServer
QueryInterface(a, b)
AddRef()
Release()
GetStatus(a)
CreateEventSubscription(a, b, c, d, e, f, g, h)
QueryAvailableFilters(a)
QueryEventCategories(a, b, c, d)
QueryConditionNames(a, b, c)
QuerySubConditionNames(a, b, c)
QuerySourceConditions(a, b, c)
QueryEventAttributes(a, b, c, d, e)
TranslateToItemIDs(a, b, c, d, e, f, g, h, i)
GetConditionState(a, b, c, d, e)
EnableConditionByArea(a, b)
EnableConditionBySource(a, b)
DisableConditionByArea(a, b)
DisableConditionBySource(a, b)
AckCondition(a, b, c, d, e, f, g, h)
CreateAreaBrowser(a, b)
EndInterface
;- IOPCEventSubscriptionMgt interface definition
;
Interface IOPCEventSubscriptionMgt
QueryInterface(a, b)
AddRef()
Release()
SetFilter(a, b, c, d, e, f, g, h, i)
GetFilter(a, b, c, d, e, f, g, h, i)
SelectReturnedAttributes(a, b, c)
GetReturnedAttributes(a, b, c)
Refresh(a)
CancelRefresh(a)
GetState(a, b, c, d)
SetState(a, b, c, d, e, f)
EndInterface
;- IOPCEventAreaBrowser interface definition
;
Interface IOPCEventAreaBrowser
QueryInterface(a, b)
AddRef()
Release()
ChangeBrowsePosition(a, b)
BrowseOPCAreas(a, b, c)
GetQualifiedAreaName(a, b)
GetQualifiedSourceName(a, b)
EndInterface
;- IOPCEventSink interface definition
;
Interface IOPCEventSink
QueryInterface(a, b)
AddRef()
Release()
OnEvent(a, b, c, d, e)
EndInterface
;- OPCEventServerCATID interface definition
;
Interface OPCEventServerCATID
EndInterface
; *********************************************************************************************************
;------------------------------------------------
; *********************************************************************************************************
;- Opc-Enum Interfaces
;-
Interface IOPCServerList2 Extends IUnknown
EnumClassesOfCategories(a,b,c,d,e)
GetClassDetails(a,b,c,d)
CLSIDFromProgID(a,b)
EndInterface
Interface IOPCEnumGUID Extends IUnknown
Next(a,b,c)
Skip(a)
Reset()
Clone(a)
EndInterface
Interface IOPCServerList Extends IUnknown
EnumClassesOfCategories(a,b,c,d,e)
GetClassDetails(a,b,c)
CLSIDFromProgID(a,b)
EndInterface
Interface CATID_OPCDAServer10 Extends IUnknown
EndInterface
Interface CATID_OPCDAServer20 Extends IUnknown
EndInterface
Interface CATID_OPCDAServer30 Extends IUnknown
EndInterface
Interface CATID_XMLDAServer10 Extends IUnknown
EndInterface
; *********************************************************************************************************
;------------------------------------------------
; *********************************************************************************************************
;- IID OPC-Server DataSection
DataSection
IID_IOPCServer:
Data.l $39c13a4d
Data.w $011e,$11d0
Data.b $96,$75,$00,$20,$af,$d8,$ad,$b3
IID_IOPCServerPublicGroups:
Data.l $39c13a4d
Data.w $011e,$11d0
Data.b $96,$75,$00,$20,$af,$d8,$ad,$b3
IID_IOPCBrowseServerAddressSpace:
Data.l $39c13a4f
Data.w $011e,$11d0
Data.b $96,$75,$00,$20,$af,$d8,$ad,$b3
IID_IOPCGroupStateMgt:
Data.l $39c13a50
Data.w $011e,$11d0
Data.b $96,$75,$00,$20,$af,$d8,$ad,$b3
IID_IOPCPublicGroupStateMgt:
Data.l $39c13a51
Data.w $011e,$11d0
Data.b $96,$75,$00,$20,$af,$d8,$ad,$b3
IID_IOPCSyncIO:
Data.l $39c13a52
Data.w $011e,$11d0
Data.b $96,$75,$00,$20,$af,$d8,$ad,$b3
IID_IOPCAsyncIO:
Data.l $39c13a53
Data.w $011e,$11d0
Data.b $96,$75,$00,$20,$af,$d8,$ad,$b3
IID_IOPCItemMgt:
Data.l $39c13a54
Data.w $011e,$11d0
Data.b $96,$75,$00,$20,$af,$d8,$ad,$b3
IID_IEnumOPCItemAttributes:
Data.l $39c13a55
Data.w $011e,$11d0
Data.b $96,$75,$00,$20,$af,$d8,$ad,$b3
IID_IOPCDataCallback:
Data.l $39c13a70
Data.w $011e,$11d0
Data.b $96,$75,$00,$20,$af,$d8,$ad,$b3
IID_IOPCAsyncIO2:
Data.l $39c13a71
Data.w $011e,$11d0
Data.b $96,$75,$00,$20,$af,$d8,$ad,$b3
IID_IOPCItemProperties:
Data.l $39c13a72
Data.w $011e,$11d0
Data.b $96,$75,$00,$20,$af,$d8,$ad,$b3
LIBID_OPCDA:
Data.l $B28EEDB2
Data.w $AC6F,$11d1
Data.b $84,$D5,$00,$60,$8C,$B8,$A7,$E9
EndDataSection
; *********************************************************************************************************
;------------------------------------------------
; *********************************************************************************************************
;- IID OPC Enum DataSection
DataSection
LIBID_OPCCOMN: ; '{B28EEDB1-AC6F-11D1-84D5-00608CB8A7E9}'
Data.l $B28EEDB1
Data.w $AC6F,$11D1
Data.b $84,$D5,$00,$60,$8C,$B8,$A7,$E9
IID_IOPCCommon: ; '{F31DFDE2-07B6-11D2-B2D8-0060083BA1FB}'
Data.l $F31DFDE2
Data.w $07B6,$11D2
Data.b $B2,$D8,$00,$60,$08,$3B,$A1,$FB
IID_IOPCShutdown: ; '{F31DFDE1-07B6-11D2-B2D8-0060083BA1FB}'
Data.l $F31DFDE1
Data.w $07B6,$11D2
Data.b $B2,$D8,$00,$60,$08,$3B,$A1,$FB
IID_IOPCServerList: ; '{13486D50-4821-11D2-A494-3CB306C10000}'
Data.l $13486D50
Data.w $4821,$11D2
Data.b $A4,$94,$3C,$B3,$06,$C1,$00,$00
IID_IOPCEnumGUID: ; '{55C382C8-21C7-4e88-96C1-BECFB1E3F483}'
Data.l $55C382C8
Data.w $21C7,$4e88
Data.b $96,$C1,$BE,$CF,$B1,$E3,$F4,$83
IID_IOPCServerList2: ; '{9DD0B56C-AD9E-43ee-8305-487F3188BF7A}'
Data.l $9DD0B56C
Data.w $AD9E,$43ee
Data.b $83,$05,$48,$7F,$31,$88,$BF,$7A
CLSID_OPCServerList: ; '{13486D51-4821-11D2-A494-3CB306C10000}'
Data.l $13486D51
Data.w $4821,$11D2
Data.b $A4,$94,$3C,$B3,$06,$C1,$00,$00
IID_CATID_OPCDAServer10: ; {63D5F430-CFE4-11d1-B2C8-0060083BA1FB}
Data.l $63D5F430
Data.w $CFE4,$11d1
Data.b $B2,$C8,$00,$60,$08,$3B,$A1,$FB
IID_CATID_OPCDAServer20: ; {63D5F432-CFE4-11d1-B2C8-0060083BA1FB}
Data.l $63D5F432
Data.w $CFE4,$11d1
Data.b $B2,$C8,$00,$60,$08,$3B,$A1,$FB
IID_CATID_OPCDAServer30: ; {CC603642-66D7-48f1-B69A-B625E73652D7}
Data.l $CC603642
Data.w $66D7,$48f1
Data.b $B6,$9A,$B6,$25,$E7,$36,$52,$D7
IID_CATID_XMLDAServer10: ; {3098EDA4-A006-48b2-A27F-247453959408}
Data.l $3098EDA4
Data.w $A006,$48b2
Data.b $A2,$7F,$24,$74,$53,$95,$94,$08
EndDataSection