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: 518
Currently Online:
23 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
hbrackel: 135
pramanj: 86
Francesco Zambon: 81
rocket science: 77
ibrahim: 75
Sabari: 62
kapsl: 57
gjevremovic: 49
Xavier: 43
TimK: 41
Member Stats:
Guest Posters: 0
Members: 685
Moderators: 16
Admins: 1
Forum Stats:
Groups: 3
Forums: 15
Topics: 1467
Posts: 6259
Newest Members:
Jan-Pfizer, DavidROunc, fen.pang@woodside.com, aytule, rashadbrownrigg, christi10l, ahamad1, Flores Frederick, ellenmoss, harriettschererModerators: Jouni Aro: 1009, Otso Palonen: 32, Tuomas Hiltunen: 5, Pyry: 1, Petri: 0, Bjarne Boström: 983, Heikki Tahvanainen: 402, Jukka Asikainen: 1, moldzh08: 0, Jimmy Ni: 26, Teppo Uimonen: 21, Markus Johansson: 42, Niklas Nurminen: 0, Matti Siponen: 321, Lusetti: 0, Ari-Pekka Soikkeli: 5
Administrators: admin: 1