12:54, EET
March 14, 2014
When I add into the server address space tags by idx= MyOPCProvider.AddressSpace.AddChild ();
I get the duplicate numbers idx. I.e unique. So I can’t find the ID of the desired tag using the
function MyOPCProvider.AddressSpace.FindChild(idx,’Pressure’);
here is an example.
var
STATIONidx, RootIndex,i,idx:Integer;
softidx,hardidx,setupidx,commidx :Integer;
Pressure : TPsInteger ;
ID : TPsInteger ;
Setupval : TPsInteger ;
Comval : TPsInteger ;
idx1,idx2 ,KITP4 :Integer;
begin
MyOPCProvider.AddressSpace.AutoAddApplication := False;
MyOPCProvider.AddressSpace.AutoUpdate := False;
MyOPCProvider.AddressSpace.PathSeparator := ‘/’;
MyOPCProvider.AddressSpace.IncludeProps := False;
MyOPCProvider.AddressSpace.BeginUpdate;
RootIndex := MyOPCProvider.AddressSpace.AddModule(Self, -1, ‘MyDevice’);
skzindx:= MyOPCProvider.AddressSpace.AddChild( RootIndex,’SKZ’ );
kitpindx:= MyOPCProvider.AddressSpace.AddChild( RootIndex,’KITP’ );
KITP4:= MyOPCProvider.AddressSpace.AddChild( kitpindx,’KITP4′);
Pressure := TPsInteger.Create(nil); Pressure.Value:= 0;
idx:= MyOPCProvider.AddressSpace.AddVariable( KITP4 , Pressure, ‘Pressure’);
// idx=4 !!
for i:=1 to 10 do begin
STATIONidx:= MyOPCProvider.AddressSpace.AddChild( skzindx,’STATION’+inttostr(i) );
softidx:= MyOPCProvider.AddressSpace.AddChild( STATIONidx,’soft’ );
hardidx:= MyOPCProvider.AddressSpace.AddChild( STATIONidx,’hard’ );
// and here idx=4 !!
Pressure := TPsInteger.Create(nil); Pressure.Value:= 0;
idx:= MyOPCProvider.AddressSpace.AddVariable( hardidx , Pressure, ‘Pressure’);
ID := TPsInteger.Create(nil); ID.Value:= 0;
idx:= MyOPCProvider.AddressSpace.AddVariable( softidx , ID, ‘ID’);
setupidx:= MyOPCProvider.AddressSpace.AddChild( STATIONidx,’setup’ );
setupval := TPsInteger.Create(nil); setupval.Value:= 0;
idx:= MyOPCProvider.AddressSpace.AddVariable(setupidx , Setupval, ‘setupval’);
commidx := MyOPCProvider.AddressSpace.AddChild( STATIONidx,’comm’ );
comval := TPsInteger.Create(nil); comval.Value:= 0;
idx:= MyOPCProvider.AddressSpace.AddVariable(commidx , Comval, ‘Comm’);
end;
idx:= MyOPCProvider.AddressSpace.FindChild(kitpindx ,’KITP4′); // NOT FIND !!!
idx1:= MyOPCProvider.AddressSpace.FindChild(idx,’Pressure’);
What am I doing wrong.?
A second question . As finding the numeric ID of the desired tag to get the tag itself and change its value.
I have not found a suitable function ?
8:19, EET
December 21, 2011
The problem is that when you add the ‘STATION’ nodes, they move ‘KITP’ to a different location in the tree and it is no longer in kitpindx (which was 2). It is better to add the stations first and then add ‘KITP’ after that, e.g.:
MyOPCProvider.AddressSpace.AutoAddApplication := False;
MyOPCProvider.AddressSpace.AutoUpdate := False;
MyOPCProvider.AddressSpace.PathSeparator := ‘/’;
MyOPCProvider.AddressSpace.IncludeProps := False;
MyOPCProvider.AddressSpace.BeginUpdate;
RootIndex := MyOPCProvider.AddressSpace.AddModule(Self, -1, ‘MyDevice’);
skzindx:= MyOPCProvider.AddressSpace.AddChild( RootIndex,’SKZ’ );
for i:=1 to 10 do begin
STATIONidx:= MyOPCProvider.AddressSpace.AddChild( skzindx,’STATION’+inttostr(i) );
softidx:= MyOPCProvider.AddressSpace.AddChild( STATIONidx,’soft’ );
hardidx:= MyOPCProvider.AddressSpace.AddChild( STATIONidx,’hard’ );
Pressure := TPsInteger.Create(nil); Pressure.Value:= 0;
idx:= MyOPCProvider.AddressSpace.AddVariable( hardidx , Pressure, ‘Pressure’);
ID := TPsInteger.Create(nil); ID.Value:= 0;
idx:= MyOPCProvider.AddressSpace.AddVariable( softidx , ID, ‘ID’);
setupidx:= MyOPCProvider.AddressSpace.AddChild( STATIONidx,’setup’ );
setupval := TPsInteger.Create(nil); setupval.Value:= 0;
idx:= MyOPCProvider.AddressSpace.AddVariable(setupidx , Setupval, ‘setupval’);
commidx := MyOPCProvider.AddressSpace.AddChild( STATIONidx,’comm’ );
comval := TPsInteger.Create(nil); comval.Value:= 0;
idx:= MyOPCProvider.AddressSpace.AddVariable(commidx , Comval, ‘Comm’);
end;
// Add KITP after the stations
kitpindx:= MyOPCProvider.AddressSpace.AddChild( RootIndex,’KITP’ );
KITP4:= MyOPCProvider.AddressSpace.AddChild( kitpindx,’KITP4′);
Pressure := TPsInteger.Create(nil); Pressure.Value:= 0;
idx:= MyOPCProvider.AddressSpace.AddVariable( KITP4 , Pressure, ‘Pressure’);
idx:= MyOPCProvider.AddressSpace.FindChild(kitpindx ,’KITP4′); // FOUND !!! (kitpindx = 92)
idx1:= MyOPCProvider.AddressSpace.FindChild(idx,’Pressure’);
8:46, EET
March 14, 2014
Hello .
It’s not very fit for me because when a new device type SKZ, I have to add it to the branch SKZ. With this approach impossible.
New devices can be added only in the end of the tree.!
Next question : Using a function
skzindx:= MyOPCProvider.AddressSpace.AddChild( RootIndex,’SKZ’ );
Pressure := TPsInteger.Create(nil); Pressure.Value:= 0;
idx:= MyOPCProvider.AddressSpace.AddVariable( skzindx, Pressure, ‘PressureItem’);
idxp:= MyOPCProvider.AddressSpace.FindChild(skzindx,’PressureItem’);
I can find the index idxp of the desired tag ‘PressureItem’ and how to get a reference to the tag Pressure itself.
I just can’t find the right function? All search functions are looking for a tag for the parent index and return again index.
Or links I must keep its own structure?
9:24, EET
December 21, 2011
Yes, I understand. The problem is that the tree is not a real tree structure (It is actually a TStringList) and the indexes change, if you add new nodes in between. If you know how many nodes you add, you can increase the indexes. Or you can find the node indexes that you need again, starting from the top.
For example,
kitpindx := MyOPCProvider.AddressSpace.FindChild(RootIndex, ‘KITP’);
idx:= MyOPCProvider.AddressSpace.FindChild(kitpindx ,’KITP4′); // FOUND !!! (kitpindx = 92)
idx1:= MyOPCProvider.AddressSpace.FindChild(idx,’Pressure’);
// Get the Pressure object
Pressure := MyOPCProvider.AddressSpace.Objects[idx1] as TPsInteger;
Pressure.Value := 1;
Most Users Ever Online: 1919
Currently Online:
12 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Heikki Tahvanainen: 402
hbrackel: 144
rocket science: 88
pramanj: 86
Francesco Zambon: 83
Ibrahim: 78
Sabari: 62
kapsl: 57
gjevremovic: 49
Xavier: 43
Member Stats:
Guest Posters: 0
Members: 726
Moderators: 7
Admins: 1
Forum Stats:
Groups: 3
Forums: 15
Topics: 1529
Posts: 6471
Newest Members:
gabriellabachus, Deakin, KTP25Zof, Wojciech Kubala, efrennowell431, wilfredostuart, caitlynfajardo, jeromechubb7, franciscagrimwad, adult_galleryModerators: Jouni Aro: 1026, Pyry: 1, Petri: 0, Bjarne Boström: 1032, Jimmy Ni: 26, Matti Siponen: 349, Lusetti: 0
Administrators: admin: 1