Avatar

Please consider registering
guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed Topic RSS sp_TopicIcon
unique or not
March 15, 2014
12:54, EEST
Avatar
jura
Member
Members
Forum Posts: 16
Member Since:
March 14, 2014
sp_UserOfflineSmall Offline

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 ?

March 17, 2014
8:19, EEST
Avatar
Jouni Aro
Moderator
Moderators
Forum Posts: 853
Member Since:
December 21, 2011
sp_UserOfflineSmall Offline

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.:

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’ );
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’);

March 17, 2014
8:46, EEST
Avatar
jura
Member
Members
Forum Posts: 16
Member Since:
March 14, 2014
sp_UserOfflineSmall Offline

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?

March 17, 2014
9:24, EEST
Avatar
Jouni Aro
Moderator
Moderators
Forum Posts: 853
Member Since:
December 21, 2011
sp_UserOfflineSmall Offline

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,

// Find KITP after adding new nodes to SKZ
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;

March 17, 2014
9:48, EEST
Avatar
jura
Member
Members
Forum Posts: 16
Member Since:
March 14, 2014
sp_UserOfflineSmall Offline

Thanks for the reply. I understand how to organize the tree.

Forum Timezone: Europe/Helsinki

Most Users Ever Online: 267

Currently Online:
12 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

hbrackel: 103

pramanj: 86

ibrahim: 70

kapsl: 57

gjevremovic: 49

TimK: 41

Fransua33: 39

fred: 38

Rainer Versteeg: 32

Thomas Reuther: 31

Member Stats:

Guest Posters: 0

Members: 1118

Moderators: 14

Admins: 1

Forum Stats:

Groups: 3

Forums: 15

Topics: 1034

Posts: 4352

Newest Members:

aldayr, Python techie, emanuel45q, Patrick, sammycontrols, hellema, linoy, subranna, ray, richN9177

Moderators: Jouni Aro: 853, Otso Palonen: 32, Tuomas Hiltunen: 5, janimakela: 0, Pyry: 1, Terho: 0, Petri: 0, Bjarne Boström: 559, Heikki Tahvanainen: 402, Jukka Asikainen: 1, Teppo Uimonen: 21, Markus Johansson: 24, Matti Siponen: 64, Lusetti: 0

Administrators: admin: 1