Вы находитесь на странице: 1из 20

WTOPCSvr DLL Users Guide

The WinTECH Software Rapid Development DLL for OPC Servers, (WTOPCSvr), provides an eas to !se "P#
for inte$ratin$ %!stom data with OPC& "ll the details of CO' and OPC are handled ( the DLL, whi%h allows
an appli%ation to present data points to OPC at a hi$h)level, witho!t havin$ to (e %on%erned with the a%t!al
implementation of the !nderlin$ interfa%es& The DLL ma (e easil inte$rated with e*istin$ appli%ations, or
new ones& "ll re+!ired OPC #nterfa%es are s!pported for (oth OPC ,&- and OPC .&- Data "%%ess Standards as
well as the /rowse #nterfa%e&
WTOPCSvr (asi%all operates as a data li(rarian& The %ontrollin$ appli%ation %reates Pro%ess Ta$s ( passin$
a name and val!e to the DLL& The DLL re%ords the data point and ma0es it availa(le to an OPC Client
appli%ation ( name& The %ontrollin$ appli%ation ma %han$e the val!e of the data at an time, and all atta%hed
%lients wo!ld (e a!tomati%all notified& Call(a%0 notifi%ation is provided for an Pro%ess Ta$ that is modified
( an OPC Client %onne%tion& (The appli%ation has %ontrol over whi%h ta$s are OPC1WR#TE"/LE&)
WTOPCSvr now s!pports dnami% %reation of OPC Ta$s& " %all(a%0 f!n%tion is s!pplied whi%h ret!rns %ontrol
to the appli%ation if a %lient re+!ests a ta$ that has not (een previo!sl defined& The appli%ation ma in t!rn
%reate the ta$ !sin$ the re+!ested path and name %om(ination or i$nore the re+!est&

Creating a Custom OPC Server using WTOPCSvr.DLL
#nstallin$ the OPC Pro* DLL2s
The first step in %reatin$ an OPC Server is to o(tain and install the OPC Pro*3St!( DLL2s from
OPC4o!ndation (http533www&op%fo!ndation&or$)
Download and !p6ip the pro*3st!( files&
Cop op%%omn1ps&dll, op%pro*&dll, op%ae1ps&dll, op%hda1ps&dll to the S7STE'8. Dire%tor& 9/e s!re not
to overwrite an newer versions9
Tpe RE:S;R8. op%%omn1ps&dll
Tpe RE:S;R8. op%pro*&dll
Tpe RE:S;R8. op%1aeps&dll
Tpe RE:S;R8. op%hda1ps&dll
7o! will also need to download and install the OPC Server /rowser O(<e%t s!pplied ( the OPC 4o!ndation&
The OPC 4o!ndation also advises that o! verif that o!r sstem %ontains the a%t*pr*&dll and if not, install
the "%tive= Redistri(!ta(le #nstallation >it from 'i%rosoft& The apr*dist&6ip file %ontainin$ the 'i%rosoft
software is also availa(le from the OPC 4o!ndation We()Site&
Lin0 WTOPCSvr&li( with the "ppli%ation
WTOPCSvr&li( %ontains the e*port definitions for the DLL2s "P#& #n%l!de this file with the pro<e%t files for the
%!stom appli%ation and in%l!de WTOPCSvr"P#&h with those mod!les whi%h will (e ma0in$ %alls into the DLL&
:enerate a new CLS#D
Ea%h OPC Server is identified ( a !ni+!e CLS#D& The :?#D:en&e*e !tilit s!pplied ( 'i%rosoft ma (e
!sed to $enerate a !ni+!e identifier for the new server appli%ation& R!n :?#D:en&e*e, (lo%ated in the ;is!al
C@@A/in dire%tor)& :enerate a new CLS#D and %op to the %lip(oard to (e pasted in to o!r server appli%ation
as des%ri(ed (elow&
Re$istr Entries
The WTOPCSvr&DLL e*ports two "P# f!n%tions that ma0e modifi%ations to the Windows Re$istr for
installation of the %!stom server&
?pdateRe$istr (/7TE 9pCLS#D1Svr, LPCSTR Bame, LPCSTR Des%r, LPCSTR E*ePath)C
?nre$isterServer (/7TE 9pCLS#D1Svr, LPCSTR Bame)C
These f!n%tions ta0e as ar$!ments the CLS#D $enerated a(ove, (as well as te*t strin$s to identif and des%ri(e
the new server)& While the ?pdateRe$istr and ?nre$isterServer f!n%tions ma (e %alled from the %ontrollin$
appli%ation at an time, it is $enerall preferred to implement the re$istr f!n%tions (ased on %ommand)line
entries d!rin$ start)!p of the appli%ation& " self)re$isterin$ server wo!ld pro%ess the ARe$Server and
A?nre$Server %ommand line options similar to the %ode (elow, (e*tra%ted from OPCSimSvr "ppli%ation)5
%onst :?#D
CLS#D1OPCSimSvr D E-*FF(GfHI,, -*%-.I, -*,,d., E-*G-, -*(G, -*-, -*J-, -*FI, -*KG, -*KG, -*(eLLC
/OOL COPCSimSvr"pp55#nit#nstan%e()
E
TCH"R s6To0ensMN D 1T(O)3 O)C
CStrin$ HelpPathC
CStrin$ SvrBame, SvrDes%ripC
int iC
HelpPath D "f*:et"pp())Pm1ps6Help4ilePathC
i D HelpPath&Reverse4ind(QAAQ)C
HelpPath D HelpPath&Left(i@,)C
HelpPath @D OOPCS#'S;R&E=EOC
33
33 Self)Re$istration %ode
33 (loo0 for %mdline options to re$ister R !nre$ister server)
33
SvrBame D OWinTECH&OPCServerOC
SvrDes%rip D OWinTECH Software OPC Server Sim!latorOC
CStrin$ tempCmdLine(m1lpCmdLine)C
LPTSTR lps6To0en D 1t%sto0(tempCmdLine&:et/!ffer(,), s6To0ens)C
while (lps6To0en SD B?LL)
E
if (1t%si%mp(lps6To0en, 1T(O?nre$ServerO))DD-)
E
?nre$isterServer ((/7TE 9)RCLS#D1OPCSimSvr, SvrBame)C
ret!rn (4"LSE)C
L
else if (1t%si%mp(lps6To0en, 1T(ORe$ServerO))DD-)
E
?pdateRe$istr ((/7TE 9)RCLS#D1OPCSimSvr,
SvrBame,
SvrDes%rip,
HelpPath)C
ret!rn (4"LSE)C
L
lps6To0en D 1t%sto0(B?LL, s6To0ens)C
L
#nitiali6ation of WTOPCSvr&DLL
The Windows Re$istration f!n%tions des%ri(ed a(ove ma (e %alled prior to the initiali6ation of the
WTOPCSvr&DLL& D!rin$ the self)re$istration pro%ess, the fo%!s is on ma0in$ the ne%essar %han$es to the
Re$istr and then e*itin$ the appli%ation& There is no need at this point to $o thro!$h the effort of initiali6in$
DCO' and loadin$ !p the OPC Server s!pport& The e*ported f!n%tion5
#nitWTOPCsvr (/7TE 9pCLS#D1Svr, ?#BT ServerRate)C
does <!st that& When this f!n%tion is e*e%!ted, the DLL performs all ne%essar initiali6ation of CO'3DCO'
and %reates the OPCServer #nterfa%e o(<e%t to (e !sed for %lient %onne%tions& The spe%ified ServerRate defines
how fast the OPC Client data %onne%tions are refreshed&

Creatin$ Pro%ess Ta$s
"fter initiali6ation, the WTOPCSvr&DLL is now read to a%%ept data points from the %!stom appli%ation& Three
e*ported f!n%tions are provided5
CreateTa$ (LPCSTR Bame, ;"R#"BT ;al!e, WORD #nitialT!alit, /OOL #sWritea(le)C
?pdateTa$ (H"BDLE Ta$Handle, ;"R#"BT ;al!e, WORD T!alit)C
?pdateTa$/Bame (LPCSTR Bame, ;"R#"BT ;al!e, WORD T!alit)C
SetWtOPCsvrT!alifier (%har Delimiter)C
"s ea%h pro%ess ta$ is %reated, the DLL ret!rns a H"BDLE to identif the point for f!t!re referen%es,
(!pdates), from the appli%ation& The namin$ %onvention !sed ( WTOPCSvr&DLL for (rowsin$ operations,
(OPC1BS14L"T or OPC1BS1H#ER"RCH#"L), is a f!n%tion of how the names are assi$ned ( the %ontrollin$
appli%ation& #f se$mented names are !sed to %reate the ta$s, (strin$s %ontainin$ the delimiter U&2,
s!%h as VPL"BT "&PROCESS,&T":,IW), WTOPCsvr&DLL will a!tomati%all %onfi$!re the name spa%e as
hierar%hial, otherwise a flat name spa%e is !sed& #f o! want to !se a delimitin$ %hara%ter other than U&2, o! %an
sele%t it !sin$ SetWtOPCsvrT!alifier()&
Dnami% Ta$ Creation
#f the desi$n warrants, WTOPCSvr&DLL ma (e !sed to provide for dnami% %reation of OPC Ta$s as re+!ested
( atta%hed %lients& Rather than %reate all the OPC Ta$s !p)front, the appli%ation ma %hoose to have the DLL
iss!e a %all(a%0 f!n%tion whenever an OPC Client re+!ests a ta$ name that is not alread listed&
Ena(le?n0nown#temBotifi%ation (?B>BOWB#TE'PROC lpCall(a%0)C
#f ena(led, the %all(a%0 f!n%tion will re%eive %ontrol antime a %lient re+!ests a ta$ that has not (een previo!sl
defined& The re+!ested ta$ name and path ma then (e !sed as ar$!ments to CreateTa$"() to dnami%all
%reate the ta$ (efore ret!rnin$ from the %all(a%0 and $ivin$ %ontrol (a%0 to the %lient& #f the appli%ation %hooses
to i$nore the re+!est, the %lient will re%eive a OPC1E1?B>BOWB#TE'#D response from the DLL&
WTOPCSvr&DLL also s!pports a !ser %all(a%0 f!n%tion that indi%ates when the last %lient referen%e to a ta$ has
(een removed& This ma (e !sed ( the server appli%ation to delete the ta$ when it is no lon$er needed& The
followin$ e*ported f!n%tion ena(les this f!n%tionalit5
Ena(le#temRemovalBotifi%ation (#TE'RE'O;EDPROC lpCall(a%0)C
The %all(a%0 will re%eive the handle to the removed item, as well as the path and item names&
Write Call(a%0 Botifi%ation
#f pro%ess ta$s are %reated as OPC1WR#TE"/LE, atta%hed %lient appli%ations ma %han$e the val!e of data
points %ontained within WTOPCSvr&DLL& WTOPCSvr&DLL provides the a(ilit for the %ontrollin$ appli%ation
to define a %all(a%0 ro!tine for notifi%ation of %lient writes& This wo!ld (e re+!ired in most sit!ations to allow
the server appli%ation to a%%ept the new val!e and perform the write to the a%t!al devi%e&
Ena(leWriteBotifi%ation (WR#TEBOT#47PROC lpCall(a%0)C
#f ena(led, the %all(a%0 f!n%tion will re%eive the H"BDLE of an data point written ( an atta%hed OPC Client,
as well as the val!e to (e written and a pointer to an error DWORD to allow feed(a%0 to the %lient if the write
operation fails
Clean)!p 4!n%tions
The onl remainin$ f!n%tions e*ported from WTOPCSvr&DLL provide the me%hanism for $ra%ef!ll %losin$ the
%!stom server&
int B!m(rClientConne%tions ()C
void Re+!estDis%onne%t ()C
RemoveTa$ (H"BDLE Ta$Handle)C
?ninitWTOPCsvr()C
:enerall, the server lo$i% sho!ld %he%0 to see if an OPC Clients are %onne%ted (efore allowin$ the appli%ation
to %lose& OPC .&- %lients ma (e re+!ested to dis%onne%t& "n ta$s %reated ( the appli%ation sho!ld (e
removed !sin$ the defined f!n%tion& The ?nintWTOPCsvr() f!n%tion %alls Co?nitiali6e and sho!ld (e pla%ed
in the E*it#nstan%e pro%ed!re of the appli%ation&
Performan%e Related 4!n%tions
/e$innin$ with version H&- of the WtOPCsvr&dll, there have (een several e*tended "P# f!n%tions added to
s!pport more effi%ient !pdatin$ for lar$e item %o!nts& The dll now s!pports an option to !se hashin$ for stora$e
and loo0!p of te*t strin$s representin$ item names& Si$nifi%ant performan%e $ains are provided in the areas of
intensive strin$ manip!lation s!%h as the item (rowsin$ f!n%tions& " se%ond series of "P# f!n%tions improves
!pon the data !pdate %%le ( !pdatin$ m!ltiple items with a sin$le %ommand rather than one at a time& The
WtSvrTst. e*ample appli%ation that is pa%0a$ed with the WtOPCsvr&dll ma (e !sed to $enerate performan%e
n!m(ers !sin$ vario!s ta$ %o!nts and vario!s %om(inations of these two options& Refer to the "P# des%riptions
(elow for detailed information relative to the !se of these f!n%tions&
OPC "larms R Events
The WtOPCsvr&dll provides (asi% s!pport for the "larms R Events standard ( providin$ level %he%0in$ for
ea%h pro%ess ta$& The dll will a!tomati%all %reate an OPC "RE Server !sin$ the same CLS#D as the Data
"%%ess Server& "s ea%h ta$ is %reated, the %ontrollin$ appli%ation ma spe%if two levels of hi$h and low alarm
limits s!rro!ndin$ it2s val!e& "s a ta$2s val!e is !pdated, either ( the %ontrollin$ appli%ation or ( an atta%hed
%lient, the dll will %he%0 its val!e a$ainst these limits and $enerate the appropriate "RE messa$es if e*%eeded&
These messa$es are a%%essi(le from an standard OPC "RE %lient appli%ation& WtOPCsvr&dll also e*ports
f!n%tions that allow the %ontrollin$ appli%ation to $enerate te*t!al events to an interested %lient& 4inall, if
$reater %ontrol over "RE Server operation is desired, the appli%ation ma disa(le the internal limit %he%0in$
and pro%ess all the "RE #nterfa%e %alls from a %lient dire%tl& " simple %all(a%0 o(<e%t is provided that ma (e
overridden ( the appli%ation to pro%ess the individ!al "RE #nterfa%es as re+!ired&
BT Se%!rit "dditions
To a%%ommodate OPC Server desi$ns where it is desired to %ontrol a%%ess to %ertain ta$s (ased on the identit
of the %onne%ted !ser, WtOPCsvr&dll s!pports api f!n%tions that allow a se%!rit mas0 to (e applied for (oth
read and write a%%ess to individ!al ta$s& The !ser ma then define a list of !ser names with spe%ifi% ri$hts&
When the se%!rit option is ena(led, WtOPCsvr&dll will verif the a%%ess ri$hts of the %lient a$ainst the sever
defined !ser list and allow or den a%%ess a%%ordin$l& "dditionall, an e*tended write %all(a%0 is provided that
%ontains the !ser name of the %lient ma0in$ a write re+!iest for a ta$& This information ma then (e !sed to
maintain an a!dit trail of !sers who have !pdated a parti%!lar ta$&
WTOPCSvr.DLL Exported functions
nitia!i"ation and #egistr$ %unctions
&OOL nitWTOPCsvr '&(TE )pCLSD*Svr+ U,T Server#ate-.
?se this f!n%tion to initiali6e DCO' and %reate the OPC Server&
CLSD*Svr defines the CLS#D whi%h OPC Clients will !se to %onne%t to this server&
Server#ate is e*pressed in mse%s and defines the rate at whi%h %lient %onne%tions are !pdated&
The ret!rn val!e will (e T#UE if the f!n%tion s!%%eeds, otherwise %/LSE&
&OOL Update#egistr$ '&(TE )pCLSD*Svr+ LPCST# ,ame+ LPCST# Descr+ LPCST# ExePat0-.
This f!n%tion ma0es modifi%ations to the Windows Re$istr to allow other appli%ations to find
and e*e%!te the server&
CLSD*Svr defines the CLS#D whi%h OPC Clients will !se to %onne%t to this server,
(this is a /7TE Pointer to the C)stle :?#D str!%t!re)&
,ame defines the Server Bame
Descr ma (e anthin$ to des%ri(e the server, and will !s!all %ontain the vendor name&
ExePat0 defines the f!ll Windows Dire%tor path to the e*e%!ta(le (i&e& %5AOPCAtestAmsvr&e*e)&
The ret!rn val!e will (e T#UE if the f!n%tion s!%%eeds, otherwise %/LSE&
&OOL /ddLoca!Service1e$sTo#egistr$ 'LPCST# ,ame-.
This f!n%tion ma0es additional modifi%ations to the Windows Re$istr to allow the server to r!n
as an BT Servi%e&
,ame defines the Server Bame
&OOL UnregisterServer '&(TE )pCLSD*Svr+ LPCST# ,ame-.
This f!n%tion removes entries from the Windows Re$istr&
CLSD*Svr defines the CLS#D whi%h OPC Clients will !se to %onne%t to this server&
,ame defines the Server Bame
The ret!rn val!e will (e T#UE if the f!n%tion s!%%eeds, otherwise %/LSE&
Tag Creation 2 Update %unctions
3/,DLE CreateTag 'LPCST# ,ame+ 4/#/,T 4a!ue+ WO#D nitia!5ua!it$+ &OOL sWritea6!e-.
This f!n%tion %reates a pro%ess ta$ within WTOPCSvr&DLL&
,ame defines the identifier that OPC Clients will !se to a%%ess the ta$& This name ma (e an
strin$ of te*t as re+!ired ( the server& Se$mented names, (those %ontainin$ the delimiter
%hara%ter U&2), are valid and will %a!se WTOPCSvr&DLL to str!%t!re the OPC name spa%e as
hierar%hial, for (rowsin$ operations&
4a!ue defines the initial data to (e asso%iated with the ta$
nitia!5ua!it$ defines the OPC T!alit fla$s asso%iated with the ta$&
sWritea6!e determines whether or not the ta$ ma (e written from an OPC Client
The ret!rn val!e will (e a 3/,DLE to the %reated point or ,4/LD*3/,DLE*4/LUE if
the ta$ %o!ld not (e %reated&
&OOL SetTagProperties '3/,DLE Tag3and!e+ DWO#D Propert$D+ LPCST# Description+
4/#/,T 4a!ue-.
"n n!m(er of OPC #tem properties ma (e set for a defined ta$ with this f!n%tion& The DLL
maintains a list of all defined properties and their %!rrent val!e for a%%ess ( an OPC Client&
The ret!rn val!e will (e T#UE if the f!n%tion s!%%eeds, otherwise %/LSE&
&OOL UpdateTag '3/,DLE Tag3and!e+ 4/#/,T 4a!ue+ WO#D 5ua!it$-.
&OOL UpdateTagWit0TimeStamp '3/,DLE Tag3and!e+ 4/#/,T 4a!ue+ WO#D 5ua!it$+
%LET7E
timestamp-.
This f!n%tion allows the %ontrollin$ appli%ation to %han$e the val!e, +!alit fla$, and
timetstammp of a defined pro%ess ta$& #f the timestamp is not s!pplied ( the appli%ation, the
dll will !se the %!rrent PC time settin$&
Tag3and!e defines the point&
4a!ue defines the new data&
5ua!it$ defines the new T!alit %ondition
The ret!rn val!e will (e T#UE if the f!n%tion s!%%eeds, otherwise %/LSE&
&OOL UpdateTag&$,ame 'LPCST# ,ame+ 4/#/,T 4a!ue+ WO#D 5ua!it$-.
This f!n%tion also allows the %ontrollin$ appli%ation to %han$e the val!e and +!alit fla$s of a
defined pro%ess ta$&
,ame defines the point&
4a!ue defines the new data&
5ua!it$ defines the new T!alit %ondition
The ret!rn val!e will (e T#UE if the f!n%tion s!%%eeds, otherwise %/LSE&
unsigned !ong Set3as0ing 'unsigned !ong 3as0Si"e-.
Ena(les hashin$ and sets the s!$$ested hash ta(le si6e&
&OOL StartUpdateTags'-.
&OOL W,/P UpdateTagToList '3/,DLE Tag3and!e+ 4/#/,T 4a!ue+ WO#D 5ua!it$-.
&OOL W,/P EndUpdateTags '-.
These three f!n%tions m!st (e !sed to$ether, and provide a more effi%ient means of !pdatin$
m!ltiple ta$s& ?pdateTa$ToList repla%es ?pdateTa$ %all, re+!ires prior Start?pdateTa$s else
fails and End?pdateTa$s after all ta$s are !pdated&
&OOL SuspendTagUpdates '3/,DLE Tag3and!e+ &OOL OnOff-.
This f!n%tion ma (e !sed in %on<!n%tion with the ?n0nown #tem %all(a%0 to allow the server
appli%ation to 0now when a parti%!lar ta$ is (ein$ s!(s%ri(ed to ( a %lient& #n most %ases, the
server appli%ation will %ontin!o!sl !pdate the ta$s as their respe%tive val!es %han$e& The dll
will then handle all %lient s!(s%riptions, notifi%ations and !pdates& #n %ertain sit!ations, it2s
desira(le for the server to onl !pdate the OPC Ta$ data(ase whenever a %lient is a%tivel
s!(s%ri(in$ to an item& / s!spendin$ !pdates, the dll will iss!e the ?B>BOWB#TE'
%all(a%0 whenever a %lient attempts to s!(s%ri(e to the item& The server ma then res!me
!pdates and wait for the #TE'RE'O;ED %all(a%0 to a$ain s!spend !pdates&
Tag3and!e defines the item to (e s!spended&
OnOff s!spends or res!mes !pdates& (The appli%ation sho!ld %all S!spendTa$?pdates (&&, TR?E)
"fter the first ?B>BOWB#TE' notifi%ation to prevent additional %all(a%0s if another %lient
s!(s%ri(es to the same data point)&
The ret!rn val!e will (e T#UE if the f!n%tion s!%%eeds, otherwise %/LSE&
&OOL #eadTag '3/,DLE Tag3and!e+ 4/#/,T )p4a!ue-.
&OOL #eadTagWit0Timestamp '3/,DLE Tag3and!e+ 4/#/,T )p4a!ue+ WO#D )p5ua!it$+
%LET7E )pTimestamp-.
This f!n%tion allows the appli%ation to o(tain the %!rrent val!e of a defined ta$ %ontained within
WTOPCSvr&DLL&
Tag3and!e defines the point&
p4a!ue points to the (!ffer to re%eive the data&
p5ua!it$ points to a val!e to re%eive the OPC T!alit indi%ation&
pTimeStamp re%eives the %!rrent timestamp for the ta$&
The ret!rn val!e will (e T#UE if the f!n%tion s!%%eeds, otherwise %/LSE&
&OOL #emoveTag '3/,DLE Tag3and!e-.
This f!n%tion removes a pro%ess ta$ from the WTOPCSvr&DLL& #f %lient %onne%tions are
a%%essin$ the point when it is removed, the %onne%tion will remain valid, (!t no new data will
(e presented to the %lient&
Tag3and!e defines the point&
The ret!rn val!e will (e T#UE if the f!n%tion s!%%eeds, otherwise %/LSE&
Ca!!6ac8 ,otification %unctions
&OOL Ena6!eUn8no9ntem,otification 'U,1,OW,TE7P#OC !pCa!!6ac8-.
This f!n%tion defines the %all(a%0 ro!tine that re%eives %ontrol from the WTOPCSvr&DLL
whenever a %lient re+!ests an OPC Ta$ that has not (een previo!sl defined&
!pCa!!6ac8 points to a ro!tine defined s!%h as the followin$5
void C/LL&/C1 E:PO#T Un8no9nTagProc 'LPST# Pat0+ LPST# ,ame)
Pat0 defines the re+!ested path name&
,ame defines the re+!ested ta$ name&
&OOL Ena6!etem#emova!,otification 'TE7#E7O4EDP#OC !pCa!!6ac8-.
This f!n%tion defines the %all(a%0 ro!tine that re%eives %ontrol from the WTOPCSvr&DLL
whenever the last %lient referen%e to a defined ta$ is removed&
!pCa!!6ac8 points to a ro!tine defined s!%h as the followin$5
void C/LL&/C1 E:PO#T #emoveTagProc '3/,DLE 0Tag+ LPST# Pat0+ LPST# ,ame)
0Tag spe%ifies the handle of the ta$ that has (een removed&
Pat0 defines the re+!ested path name&
,ame defines the re+!ested ta$ name&
&OOL Ena6!eWrite,otification 'W#TE,OT%(P#OC !pCa!!6ac8+ &OOL ConvertTo,ativeT$pe-.
This f!n%tion defines the %all(a%0 ro!tine whi%h re%eives %ontrol from the WTOPCSvr&DLL
whenever an OPC Client appli%ation writes to a defined pro%ess ta$& Bormall, the dll wo!ld (e
%onfi$!red to %onvert val!es to the item2s native variant tpe, (!t in some %ases it ma (e
desira(le for the appli%ation itself to perform spe%ial %onversion pro%essin$&
!pCa!!6ac8 points to a ro!tine defined s!%h as the followin$5
void C/LL&/C1 E:PO#T ,otification3and!er '3/,DLE 0and!e+
4/#/,T )p,e94a!ue+ DWO#D )pDeviceError-
0and!e defines the handle of the pro%ess ta$ whi%h was written&
p,e94a!ue defines the val!e to (e written& The appli%ation needs to write the new val!e to the
a%t!al devi%e and %all ?pdateTa$ to !pdate the new val!e to the DLL %a%he&
pDeviceError allows the appli%ation to fla$ an error (a%0 to the %lient if the data val!e %annot
(e written&
&OOL Ena6!eDisconnect,otification 'DSCO,,ECTP#OC !pCa!!6ac8-.
This f!n%tion defines the %all(a%0 ro!tine whi%h re%eives %ontrol from the WTOPCSvr&DLL
whenever an OPC Client appli%ation dis%onne%ts&
!pCa!!6ac8 points to a ro!tine defined s!%h as the followin$5
void C/LL&/C1 E:PO#T Disconnect3and!er 'DWO#D ,um6r-
,um6r defines the the n!m(er of %lient %onne%tions remainin$&
&OOL Ena6!eEvent7sgs 'E4E,T7SGP#OC !pCa!!6ac8-.
This f!n%tion allows the server appli%ation to re%eive event messa$es from the WtOPCsvr&dll
d!rin$ normal operation of the OPC Server #nterfa%es& Event messa$es are availa(le as a
de(!$$in$ tool to tra%e e*e%!tion of the lo$i% thro!$h the vario!s #nterfa%e pro%ed!res&
!pCa!!6ac8 points to a ro!tine defined s!%h as the followin$5
void C/LL&/C1 E:PO#T Event3and!er 'LPCST# 7sg-
7sg is a (te strin$ des%ri(in$ the event&
&OOL Ena6!e#ate,otification '#/TEC3/,GEP#OC !pCa!!6ac8-.
This f!n%tion defines a %all(a%0 pro%ed!re that re%eives %ontrol whenever the minim!m re+!est
!pdate rate for an item %han$es& ;ario!s %lients ma re+!est an item from the server at different
rates& This %all(a%0 allows the server appli%ation to optimi6e it2s data a%+!isition lo$i% to o(tain
the data for an item at the most effi%ient rate&
!pCa!!6ac8 points to a ro!tine defined s!%h as the followin$5
void C/LL&/C1 E:PO#T #ateC0ange3and!er '3/,DLE 0tem+ DWO#D #ate-
0tem defines the item&
#ate is the newl re+!ested !pdate rate&
&OOL Ena6!eDevice#ead 'DE4CE#E/DP#OC !pCa!!6ac8-.
This f!n%tion allows the appli%ation to s!ppl a %all(a%0 pro%ed!re to servi%e DE;#CE1RE"D
re+!ests from a %lient& The %all(a%0, if defined, will (e %alled whenever a %lient re+!ests a
Sn%#O55Read with dwSo!r%e set to OPC1DS1DE;#CE& #f the %all(a%0 is not defined,
WtOPCsvr&dll will treat OPC1DS1DE;#CE as OPC1DS1C"CHE
!pCa!!6ac8 points to a ro!tine defined s!%h as the followin$5
void C/LL&/C1 E:PO#T Device#ead3and!er '3/,DLE 0tem+ 4/#/,T )p4a!ue+
WO#D )p5ua!it$+ %LET7E )pTimestamp-
0tem defines the item&
)p4a!ue+ )p5ua!it$+ and )pTimestamp are to (e s!pplied ( the appli%ation to represent the
%!rrent val!e of the defined item&
7isce!!aneous %unctions
c0ar SetWtOPCsvr5ua!ifier 'c0ar ;ua!ifier-.
This f!n%tion sets the delimitin$ %hara%ter !sed ( the dll to se$ment the node names of a
hiear%hial namespa%e& The defa!lt delimiter is the U&2 %hara%ter&
int ,um6rC!ientConnections '-.
This f!n%tion ret!rns the n!m(er of OPC Clients %!rrentl %onne%ted to WTOPCSvr&DLL
void #e;uestDisconnect '-.
This f!n%tion re+!ests that all OPC Clients dis%onne%t from the server& This f!n%tion does not
$!arantee that the re+!est will (e honored, or that the %lients will a%t!all dis%onne%t& The
a(ilit for an OPC Server to re+!est a %lient dis%onne%t onl applies to those %lients %onne%ted
a%%ordin$ to the OPC .&- spe%ifi%ation&
&OOL #efres0/!!C!ients '-.
This f!n%tion ma (e !sed ( the server appli%ation to initiate a refresh operation to all atta%hed
OPC Clients& Bormall, %lient appli%ations are refreshed (ased on an asn%hrono!s %lo%0 ti%0
within the WTOPCSvr&DLL& This f!n%tion ma (e !sed to for%e the server to !pdate all %lient
data&
The ret!rn val!e will (e T#UE if the f!n%tion s!%%eeds, otherwise %/LSE&
&OOL #esetServer#ate 'U,T Server#ate-.
This f!n%tion ma (e !sed ( the server appli%ation to %han$e the %!rrent settin$ for the rate at
whi%h data is refreshed ( the server&
The ret!rn val!e will (e T#UE if the f!n%tion s!%%eeds, otherwise %/LSE&
&OOL Set4endornfo 'LPCST# 4endornfoString-.
The appli%ation ma set the vendor information des%ription that is ret!rned ( the server in
response to a %lient re+!est for Server #nformation&&
The ret!rn val!e will (e T#UE if the f!n%tion s!%%eeds, otherwise %/LSE&
void SetServerState 'OPCSE#4E#ST/TE SvrState-.
This f!n%tion allows the appli%ation to set the state of the server as a%%essed ( a %lient& ?sef!l
d!rin$ desi$n and %ommissionin$ to displa internal dia$nosti%s related to server operation&
/!arms 2 Events %unctions
&OOL SettemLeve!/!arm '3/,DLE Tag3and!e+ int Leve!D+ f!oat Limit+ DWO#D Severit$+
&OOL Ena6!ed-.
'!ltiple levels of alarms ma (e %onfi$!red for ea%h defined Ta$& #f ena(led, WtOPCsvr will
%he%0 the alarm limits and notif an atta%hed OPC "larms R Events Client of level %han$es as
an item is !pdated& Level#D refers to the followin$ literal definitions5
Xdefine #D1LOLO1L#'#T ,
Xdefine #D1LO1L#'#T .
Xdefine #D1H#1L#'#T 8
Xdefine #D1H#H#1L#'#T H
&OOL GettemLeve!/!arm '3/,DLE Tag3and!e+ int Leve!D+ f!oat )pLimit+ DWO#D )pSeverit$+
&OOL )pEna6!ed-.
This f!n%tion allows the appli%ation to retrieve the asso%iated alarm limits for a $iven Ta$
&OOL User/E7essage 'LPCST# 7sg+ DWO#D Severit$-.
&OOL User/E7essageEx 'O,E4E,TST#UCT 7sg-.
&OOL User/E7essageEx< 'DWO#D 0EventSu6scription+ O,E4E,TST#UCT 7sg+ &OOL 6#efres0+
&OOL 6Last#efres0-.
These f!n%tions send a !ser)defined event messa$e to all %onne%ted OPC "larm R Event
Clients&
C9t/ExCa!!6ac8 %unctions
The appli%ation %an !se the CWt"E*Call(a%0 o(<e%t definition des%ri(ed (elow to $enerate
overloaded f!n%tions to %han$e the defa!lt (ehavior of the WtOPCsvr&dll with re$ard to "larms
R Events&
/asi% s!pport for "larms R Events is s!pplied ( the dll in the form of Hi$h R Low level
alarms s!rro!ndin$ ea%h defined OPC #tem& "s the data val!es %han$e, these level limits are
%ompared and event messa$es $enerated as appropriate& The defa!lt (ehavior of the
WtOPCsvr&dll does not provide for a%0nowled$ements from an OPC Client or an filterin$ to
(e applied to the event s!(s%ription&
/ (asin$ a C@@ o(<e%t on the CWt"E*Call(a%0 o(<e%t and overloadin$ an of the virt!al
f!n%tions the appli%ation %an e*pand !pon or repla%e the (asi% "RE f!n%tionalit of the dll as
re+!ired&
virtua! 3#ESULT GetStatus 'OPCE4E,TSE#4E#ST/TUS)) ppEventServerStatus+
%LET7E LastUpdateTime-.
This f!n%tion is %alled ( the dll (ased !pon C#OPCEventServer55:etStat!s(&&&)&
The dll s!pplies the Last ?pdate Time parameter to mat%h the re+!estin$ s!(s%ri(er& The
defa!lt implementation of this f!n%tion ret!rns valid parameters to the %lient& Onl overload
this f!n%tion if o! have spe%ifi% information to add to the stat!s str!%t!re
virtua! 3#ESULT 5uer$/vai!a6!e%i!ters 'DWO#D )pd9%i!ter7as8-.
This f!n%tion is %alled from C#OPCEventServer55T!er"vaila(le4ilters(&&&)
The defa!lt implementation of this f!n%tion ret!rns 6ero for the 4ilter'as0 and
S1O>, (i&e& 4ilters not s!pportedS)
virtua! 3#ESULT 5uer$EventCategories 'DWO#D d9EventT$pe+
DWO#D )pd9Count+
DWO#D ))ppd9EventCategories+
LPWST# ))pps"EventCategor$Descs-.
This f!n%tion is %alled from C#OPCEventServer55T!erEventCate$ories (&&&)&
The defa!lt implementation of this f!n%tion s!pports two %ate$ories
OPC1S#'PLE1E;EBT )) OPC1'S:1C"T5Sstem 'essa$e
OPC1COBD#T#OB1E;EBT )) OPC1LE;EL1C"T5Level
)) OPC1D#SCRETE1C"T5Dis%rete
virtua! 3#ESULT 5uer$Condition,ames ' DWO#D d9EventCategor$+
DWO#D )pd9Count+
LPWST# ))pps"Condition,ames-.
This f!n%tion is %alled from C#OPCEventServer55T!erConditionBames (&&&)
The defa!lt implementation of this f!n%tion ret!rns the followin$ %ondition names
OPC1'S:1C"T )) O#nformational Te*tO
OPC1LE;EL1C"T )) OLevel "larmO
OPC1D#SCRETE1C"T )) ODis%rete "larmO
virtua! 3#ESULT 5uer$Su6Condition,ames ' LPWST# s"Condition,ame+
DWO#D )pd9Count+
LPWST# ))pps"Su6Condition,ames-.
This f!n%tion is %alled from C#OPCEventServer55T!erS!(ConditionBames(&&&)
The defa!lt implementation of this f!n%tion ret!rns fo!r s!(Condition Bames for the OLevel
"larmO %ondition5
OLoO
OLo LoO
OHiO
OHi HiO
virtua! 3#ESULT 5uer$SourceConditions ' LPWST# s"Source+
DWO#D )pd9Count+
LPWST# ))pps"Condition,ames-.
This f!n%tion is %alled from C#OPCEventServer55T!erSo!r%eConditions(&&&)
The defa!lt implementation of this f!n%tion ret!rns E1BOT#'PL&
virtua! 3#ESULT 5uer$Event/ttri6utes ' DWO#D d9EventCategor$+
DWO#D )pd9Count+
DWO#D ))ppd9/ttrDs+
LPWST# ))pps"/ttrDescs+
4/#T(PE ))ppvt/ttrT$pes-.
This f!n%tion is %alled from C#OPCEventServer55T!erEvent"ttri(!tes(&&&)
The defa!lt implementation of this f!n%tion ret!rns E1BOT#'PL
virtua! 3#ESULT Trans!ateTotemDs ' LPWST# s"Source+
DWO#D d9EventCategor$+
LPWST# s"Condition,ame+
LPWST# s"Su6condition,ame+
DWO#D d9Count+
DWO#D )pd9/ssoc/ttrDs+
LPWST# ))pps"/ttrtemDs+
LPWST# ))pps",ode,ames+
CLSD ))ppCLSDs-.
This f!n%tion is %alled from C#OPCEventServer55TranslateTo#tem#Ds(&&&)
The defa!lt implementation of this f!n%tion ret!rns E1BOT#'PL
virtua! 3#ESULT GetConditionState ' LPWST# s"Source+
LPWST# s"Condition,ame+
DWO#D d9,umEvent/ttrs+
DWO#D )pd9/ttri6uteDs+
OPCCO,DTO,ST/TE ))ppConditionState-.
This f!n%tion is %alled from C#OPCEventServer55:etConditionState(&&&)
The defa!lt implementation of this f!n%tion ret!rns E1BOT#'PL
virtua! 3#ESULT Ena6!eCondition&$/rea ' DWO#D d9,um/reas+
LPWST# )ps"/reas-.
This f!n%tion is %alled from C#OPCEventServer55Ena(leCondition/"rea(&&&)
The defa!lt implementation of this f!n%tion ret!rns E1BOT#'PL
virtua! 3#ESULT Ena6!eCondition&$Source ' DWO#D d9,umSources+
LPWST# )ps"Sources-.
This f!n%tion is %alled from C#OPCEventServer55Ena(leCondition/So!r%e(&&&)

The defa!lt implementation of this f!n%tion ret!rns E1BOT#'PL
virtua! 3#ESULT Disa6!eCondition&$/rea ' DWO#D d9,um/reas+
LPWST# )ps"/reas-.
This f!n%tion is %alled from C#OPCEventServer55Disa(leCondition/"rea(&&&)
The defa!lt implementation of this f!n%tion ret!rns E1BOT#'PL
virtua! 3#ESULT Disa6!eCondition&$Source ' DWO#D d9,umSources+
LPWST# )ps"Sources-.
This f!n%tion is %alled from C#OPCEventServer55Disa(leCondition/So!r%e(&&&)
The defa!lt implementation of this f!n%tion ret!rns E1BOT#'PL
virtua! 3#ESULT /c8Condition ' DWO#D d9Count+
LPWST# s"/c8no9!edgerD+
LPWST# s"Comment+
LPWST# )ps"Source+
LPWST# )ps"Condition,ame+
%LET7E )pft/ctiveTime+
DWO#D )pd9Coo8ie+
3#ESULT ))ppErrors-.
This f!n%tion is %alled from C#OPCEventServer55"%0Condition(&&&)
The defa!lt implementation of this f!n%tion ret!rns S14"LSE
virtua! 3#ESULT Create/rea&ro9ser ' #E%D riid+
LPU,1,OW, )ppUn8-.
This f!n%tion is %alled from C#OPCEventServer55Create"rea/rowser(&&&)
The defa!lt implementation of this f!n%tion ret!rns E1BOT#'PL
virtua! 3#ESULT CreateEventSu6scription 'DWO#D 0EventSu6scription+
DWO#D d9&ufferTime+
DWO#D d97axSi"e+
OPC3/,DLE 0C!ientSu6scription-.
virtua! 3#ESULT #emoveEventSu6scription 'DWO#D 0EventSu6scription-.
WtOPCsvr&dll will e*e%!te these f!ntions in the appli%ation %all(a%0 o(<e%t whenevr a %lient
s!(%ri(es and !ns!(s%ri(es to the event server& This allows the appli%ation to implement filters
on an individ!al s!(s%ription (asis ( %allin$ ?ser"E'essa$eE*.&
virtua! 3#ESULT SetEventSu6scription%i!ter ' DWO#D 0EventSu6scription+
DWO#D d9EventT$pe+
DWO#D d9,umCategories+
DWO#D )pd9EventCategories+
DWO#D d9Lo9Severit$+
DWO#D d93ig0Severit$+
DWO#D d9,um/reas+
LPWST# )ps"/reaList+
DWO#D d9,umSources+
LPWST# )ps"SourceList-.
This f!n%tion is %alled from C#OPCEventS!(s%ription'$t55Set4ilter (&&&)
The defa!lt implementation of this f!n%tion ret!rns E1BOT#'PL
virtua! 3#ESULT GetEventSu6scription%i!ter ' DWO#D 0EventSu6scription+
DWO#D )pd9EventT$pe+
DWO#D )pd9,umCategories+
DWO#D ))ppd9EventCategories+
DWO#D )pd9Lo9Severit$+
DWO#D )pd93ig0Severit$+
DWO#D )pd9,um/reas+
LPWST# ))pps"/reaList+
DWO#D )pd9,umSources+
LPWST# ))pps"SourceList-.
This f!n%tion is %alled from C#OPCEventS!(s%ription'$t55:et4ilter (&&&)
The defa!lt implementation of this f!n%tion ret!rns E1BOT#'PL
virtua! 3#ESULT Se!ectEventSu6scription#eturned/ttri6utes ' DWO#D 0EventSu6scription+
DWO#D d9EventCategor$+
DWO#D d9Count+
DWO#D )d9/ttri6uteDs-.
This f!n%tion is %alled from C#OPCEventS!(s%ription'$t55Sele%tRet!rned"ttri(!tes (&&&)
The defa!lt implementation of this f!n%tion ret!rns E1BOT#'PL
virtua! 3#ESULT GetEventSu6scription#eturned/ttri6utes ' DWO#D 0EventSu6scription+
DWO#D d9EventCategor$+
DWO#D )pd9Count+
DWO#D ))ppd9/ttri6uteDs-.

This f!n%tion is %alled from C#OPCEventS!(s%ription'$t55:etRet!rned"ttri(!tes (&&&)
The defa!lt implementation of this f!n%tion ret!rns E1BOT#'PL
virtua! 3#ESULT #efres0EventSu6scription ' DWO#D 0EventSu6scription+
DWO#D d9Connection-.
This f!n%tion is %alled from C#OPCEventS!(s%ription'$t55Refresh (&&&)
The defa!lt implementation of this f!n%tion ret!rns E1BOT#'PL
virtua! 3#ESULT Cance!EventSu6scription#efres0 ' DWO#D 0EventSu6scription+
DWO#D d9Connection-.

This f!n%tion is %alled from C#OPCEventS!(s%ription'$t55Can%elRefresh (&&&)
The defa!lt implementation of this f!n%tion ret!rns E1BOT#'PL
virtua! 3#ESULT GetEventSu6scriptionState ' DWO#D 0EventSu6scription+
&OOL )p6/ctive+
DWO#D )pd9&ufferTime+
DWO#D )pd97axSi"e+
OPC3/,DLE )p0C!ientSu6scription-.
This f!n%tion is %alled from C#OPCEventS!(s%ription'$t55:etState (&&&)
The defa!lt implementation of this f!n%tion ret!rns E1BOT#'PL
virtua! 3#ESULT SetEventSu6scriptionState ' DWO#D 0EventSu6scription+
&OOL )p6/ctive+
DWO#D )pd9&ufferTime+
DWO#D )pd97axSi"e+
OPC3/,DLE 0C!ientSu6scription+
DWO#D )pd9#evised&ufferTime+
DWO#D )pd9#evised7axSi"e-.
This f!n%tion is %alled from C#OPCEventS!(s%ription'$t55SetState (&&&)
The defa!lt implementation of this f!n%tion ret!rns E1BOT#'PL
Securit$ %unctions
&OOL Ena6!e,TSecurit$ '&OOL Ena6!eSecurit$+ DWO#D 7inmpersonationLeve!-.
Call this f!n%tion to ena(le se%!rit %he%0in$ for ea%h ta$& The 'in#mpersonationLevel is !sed
to define the minim!m re+!irements for a %lient %onne%tion&
3#ESULT Define,TUser 'LPCST# Group,ame+ LPCST# User,ame+ DWO#D /ccessLeve!-.
This f!n%tion defines the name of a parti%!lar !ser and the a%%ess ri$hts to (e assi$ned for
a%%ess to server ta$s& "%%ess ri$hts ma (e an %om(ination of the followin$5
/CCESSLE4EL,O,E =x========
/CCESSLE4EL> =x===>====
/CCESSLE4EL< =x===<====
/CCESSLE4EL? =x===@====
/CCESSLE4EL@ =x===A====
/CCESSLE4ELB =x==>=====
/CCESSLE4ELC =x==<=====
/CCESSLE4ELD =x==@=====
/CCESSLE4ELA =x==A=====
/CCESSLE4ELE =x=>======
/CCESSLE4EL>= =x=<======
/CCESSLE4EL>> =x=@======
/CCESSLE4EL>< =x=A======
/CCESSLE4EL>? =x>=======
/CCESSLE4EL>@ =x<=======
/CCESSLE4EL>B =x@=======
/CCESSLE4EL>C =xA=======
3/,DLE CreateSecureTag 'LPCST# ,ame+ 4/#/,T 4a!ue+ WO#D nitia!5ua!it$+ DWO#D
#ead/ccessLeve!+ DWO#D Write/ccessLeve!-.
When a ta$ is %reated, the a%%ess level re+!ired for (oth read and write a%%ess m!st (e spe%ified&
#f BT Se%!rit is ena(led, the WtOPCsvr&dll will %ompare the a%%ess level re+!ired to read
and3or write a ta$ with the a%%ess ri$hts that have (een assi$ned to the !ser definition& #f the
%onne%ted !ser does not have the proper a%%ess ri$hts, the dll will den a%%ess and ret!rn an
error to the %lient&
&OOL Ena6!eWrite,otification< 'W#TE,OT%(P#OC< !pCa!!6ac8+ &OOL ConvertTo,ativeT$pe-.
This f!n%tion defines the %all(a%0 ro!tine that re%eives %ontrol from the WTOPCSvr&DLL
whenever an OPC Client appli%ation writes to a defined pro%ess ta$&
!pCa!!6ac8 points to a ro!tine defined s!%h as the followin$5
void C/LL&/C1 E:PO#T ,otification3and!er '3/,DLE 0and!e+
4/#/,T )p,e94a!ue+ DWO#D )pDeviceError+ c0ar )pUser-
This %all(a%0 is identi%al to the standard write notifi%ation %all(a%0 with an e*tra parameter on
the end that des%ri(es the name of the !ser re+!estin$ the write&
WTSvrTest 7%C Examp!e
The WTSvrTest appli%ation was desi$ned to demonstrate how an OPC Server ma (e assem(led !sin$ the
WTOPCSvr dll& WTSvrTest was (!ilt !sin$ 'SDE; ;ersion J&-& "ll pro<e%t and reso!r%e files are %ontained
in the distri(!tion file WtSvrTest&6ip&
This simple appli%ation !ses the standard '4C framewor0, ("ppli%ation3Do%!ment3;iew), ar%hite%t!re
$enerated ( the 'i%rosoft development platform for a sin$le)do%!ment interfa%e& "ll %!stom lo$i% to interfa%e
with the WTOPCsvr dll has (een added to WTSvrTest;iew&%pp& 4or demonstration p!rposes, men! options are
in%l!ded whi%h Re$ister and ?nre$ister the server, instead of the preferred method of pro%essin$ %ommand line
options d!rin$ self)re$istration&
'en! options are availa(le to add ta$s to the server and !pdate their val!e& "n option is also availa(le to ena(le
write notifi%ation (a%0 from the WTOPCsvr dll if an atta%hed OPC Client writes a ta$ or re+!ests an !ndefined
ta$& The men! options %losel mat%h the a%t!al %alls that wo!ld (e made to the server dll for %reatin$ and
!pdatin$ ta$s for an a%t!al OPC Server appli%ation&
WTSvrTst< 7%C Examp!e
The WTSvrTst. appli%ation was desi$ned to demonstrate different te%hni+!es for writin$ an OPC Server with
lar$e ta$ %o!nts& #t too was written !sin$ 'SDE; J&- and is desi$ned aro!nd the standard '4C framewor0&
The WtSvrTst. appli%ation !ses a sin$le form view that displas a tree %ontrol depi%tin$ the server ta$ list and
an event window that displas DCO' #nterfa%e %alls pro%essed ( the server& 'en! %ommands allow o! to
Re$ister and ?nre$ister the server and to %reate a list of ta$s !p to .-,--- in si6e& The ta$ list ma (e %reated
!sin$ an %om(ination of options for !pdatin$ the val!es, (Hashin$3Bo)Hashin$, sin$le
?pdates3?pdate/List)& Te*t messa$es are displaed that show the times involved with %reation of the ta$ list
and the !pdate times&

Вам также может понравиться