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
OPC server tag doesn't change value after first change
April 12, 2018
9:35, EEST
Avatar
Fransua33
Member
Members
Forum Posts: 39
Member Since:
October 27, 2014
sp_UserOfflineSmall Offline

I create an OPC server using TPsOPCProvider. I add a variable VAR1 as TPsBool using the add variable method of the TPsOPCProvider. I initialise it to false.

This serve as a update tag. When it change to true, I need to do some actions and when the actions are finalized I need to set it to false. You can see the code of the OnChange event of the tag.

void __fastcall Main::UpdateTagChange(TPsVar *Sender, TPsVarPropTypes props) {
if(Sender->Value.boolVal) {
this->doSomething();
Sender->Value.boolVal=false;
}
}

From a comercial OPC Explorer I can change the value the first time setting it to true but after this first change I can’t change the value again. I assume there something wrong in my code (certainly a recursive cal or a thread control problem) but I can’t see the way I can solve it.

My Sentrol SDK version is 6.5.0 Build 630

April 12, 2018
11:58, EEST
Avatar
Fransua33
Member
Members
Forum Posts: 39
Member Since:
October 27, 2014
sp_UserOfflineSmall Offline
April 12, 2018
14:57, EEST
Avatar
Jouni Aro
Moderator
Moderators
Forum Posts: 963
Member Since:
December 21, 2011
sp_UserOfflineSmall Offline

(Hmm, your reply to the thread seems to be missing now, but I got your addition via RSS, which explains the problem a bit more)

I expose the OnChange code:

void __fastcall Main::Var1Change(TPsVar *Sender, TPsVarPropTypes props) {
if(Sender->Value.boolVal) {
Var2->Value=true;
}
}

OnChange event handler is actually a “bad” place for changing the value of the variable itself: the changes inside the event handler are not notified out of the variable, since that might create an infinite loop.

In this case, though it looks like you are changing another variable, so it should be OK – assuming your code is otherwise correct (‘Sender->Value.boolVal’ is true)

So, I am not quite sure what is the problem in your case. Could you try to describe it in more detail, how you are actually doing it.

An alternative place to react to changes is the OnChanging event.

April 20, 2018
15:41, EEST
Avatar
Fransua33
Member
Members
Forum Posts: 39
Member Since:
October 27, 2014
sp_UserOfflineSmall Offline

I use a second OPC tag to change the value and avoid the loop situation.

But I’m interested in the OnChanging way. Can you explain a bit more the secuence of the events in that case? Is it the OnChange first or the OnChanging first?

April 20, 2018
16:34, EEST
Avatar
Jouni Aro
Moderator
Moderators
Forum Posts: 963
Member Since:
December 21, 2011
sp_UserOfflineSmall Offline

OnChanging is called before the actual change happens in the variable and you have an option to modify the incoming value or even reject the change in the handler.

OnChange is called after the value has changed.

Forum Timezone: Europe/Helsinki

Most Users Ever Online: 518

Currently Online:
7 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

hbrackel: 124

pramanj: 86

ibrahim: 74

rocket science: 65

kapsl: 57

Sabari: 51

gjevremovic: 49

Xavier: 43

fred: 41

TimK: 41

Member Stats:

Guest Posters: 0

Members: 684

Moderators: 15

Admins: 1

Forum Stats:

Groups: 3

Forums: 15

Topics: 1335

Posts: 5711

Newest Members:

daniel.boada@soprasteria.com, Ratheesh, Dustingen, janessawhittell, ravi_prabhakar, dustyy137676428, Douglasabibe, DonaldWibip, kennithmazza4, Heiko Geissler

Moderators: Jouni Aro: 963, Otso Palonen: 32, Tuomas Hiltunen: 5, Pyry: 1, Petri: 0, Bjarne Boström: 877, Heikki Tahvanainen: 402, Jukka Asikainen: 1, moldzh08: 0, Jimmy Ni: 25, Teppo Uimonen: 21, Markus Johansson: 42, Niklas Nurminen: 0, Matti Siponen: 230, Lusetti: 0

Administrators: admin: 1