Question Data aquisation

Rayk411

Member
Joined
Feb 20, 2012
Messages
5
Programming Experience
1-3
Hey!

I'm having some problems with a program I'm working on and was hoping that you guys could help me out..

The goal is to monitor live data from a OPC system, I already established a connection and I'm able to get live data from the database.
The problem is that I have to monitor multiple 'tags' at once (15 to be precise), so the clsTag object checks the database every 3 seconds or so for updated information.
I have a 'tag' class where I have a function that returns the value for a given sqlcommand. In the class where I initiate the tag class I made a for loop
where I initiate a new tag class for every 'tag' I need to retrieve

For
i = 1 To 15
SelectCase i
Case 1
sTagVar =
"dTempLNG"
sTag = "63TI026.PNT"'C
oTag = New clsTag(sTagVar, oServer, sTag)
arrTags.Add(oTag)

Case 2
sTagVar =
"dDrukLNG"
sTag = "68PIC007.MEAS"'barg
oTag = New clsTag(sTagVar, oServer, sTag)
arrTags.Add(oTag)

...

when the value in the clsTag class is updated I fire an event that is being handled in the same class where I initiated the clsTag

Private Sub oTag_gotUpdate (Byval sender As clsTag, Byval dValue As Double) Handles oTag.gotUpdate
SelectCase sender.TagVar
Case"dTempLNG"
dTempLNG = dValue
MessageBox.Show("Var: " & sender.TagVar & " value1: " & dValue)

Case"dDrukLNG"
dDrukLNG = dValue
MessageBox.Show("Var: " & sender.TagVar & " value1: " & dValue)

...

but for some reason the only tag that has a value is the last tag that was initiated in that for loop earlier.. why is that?
I do a RaiseEvent in clsTag everytime a value changes in comparison with the previous value, but in the beginning that means all of them because the previous value for all of them is 0.
I thought I would get 15 messageboxes at start, but instead I received one.., the same one that was initiated last and doesn't have a value = 0
is it because I don't work with threads?? Maybe the program couldn't handle 15 clsTag object that check the database every 3 seconds.. I have no clue :(

does anyone have an idea?

thx!
 
Last edited:
Hi Rayk411,

If I understand correctly, it is becuase you declare oTag = New clsTag for each case, so you need to add the gotUpdate Handler to each oTag, because the 15th tag will be the only one with the Event oTag.gotUpdate.

The thing you need to do is the following:

Write the following procedure.

Private Sub Tags_gotUpdate (Byval sender As clsTag, Byval dValue As Double)

then in each case you add: Addhandler oTag.gotUpdate, AddressOf Tags_gotUpdate

So each New oTag will be addressed to that Procedure, try it and see ;)

Gunze
 
Back
Top