LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

event structure string indicator value change

Hi,

 

I'm trying to use an event structure to notice the changes in an array (reading from a DB) and execute the event  when the array value has changed.

I'm using the signaling value of my array indicator. (see screenshot)

My method isn't working properly. Am I doing anything wrong? Is there a better way of doing this?

 

P.S: I'm a beginner. Any sample code or screenshots with your answers would be greatly appricated.

 

Capture.JPG

0 Kudos
Message 1 of 9
(4,559 Views)

A picture is typicall insufficient to inspect code, e.g. we cannot tell what's in the other cases.

 

How do your two code fragments relate to each other?

Where is the event structure?

0 Kudos
Message 2 of 9
(4,554 Views)

What does "isn't working properly" mean?

 

What is it doing that it shouldn't be?  What is it not doing that it should?

 

Where is your event structure?  Pictures of code segments don't tell us anything.  Please attach your VI.

 

Why are you doing a Not Equals comparison, then converting a boolean array to a number?  If you want to find out whether every element of your string array is equal, you might want to right click on your comparison and change between the comparison mode of elements and aggregate.

0 Kudos
Message 3 of 9
(4,552 Views)

I'll be more specific about it.

The purpose of this VI is to read a column from a DB, match the entry's and count them, and record the results to another DB.

 

What I need is for the event structure to be exectuted everytime Array 8 (from VI) changes. Basically, I want the event structure to run everytime a new entry is made in that column of the database. I've tried the File/Directory Info Function and I was unable to make the code work.

 

Is it more clear now?

 

Best,

0 Kudos
Message 4 of 9
(4,538 Views)

Let's talk about the problems I do see so far.

 

1.  It looks like you are opening the same database in 3 different locations.

2.  You are opening, reading, and closing it on every loop iteration.  It should be only opened before the loop, read inside the loop, and closed only after the loop ends.

3.  Event structures are generally meant for user interaction with the front panel.  But you can use Value signalling to programmatically fire events, and also use User Events to programmatically fire the event structure.  Your problem is that you are all wrapped up in one loop.  The event structure only executes when a value change occurs by way of the value(signalling) property node (since it is an indicator, a user can't change it.)  And that property node executes in the same loop and it will generally happen first. The loop needs to run at least twice in order to detect a change has occurred.  You are sitting there waiting forever for a change to happen, and you can only detect that change if the loop is able to run.

 

I think you should avoid the event structure in this situation.  If you are polling a database for changes, then you should just go ahead and do that in a loop that runs at a reasonable speed.

 

I don't see anything in your code about file/directory Info.

0 Kudos
Message 5 of 9
(4,521 Views)

Thanks for your quick input.

 

1.I'm openning it in two different location. The 3rd one is another DB. I can open it only once and reffer to the arrays in the other loop.

2. Any examples to guide me through this?

3. Would two loops with a value(signalling) property node programmatically fire the event structure?

Since you mentioned I should avoid event structures, how would I do that in a loop that runs at a reasonable speeds?

 

File/directory info function was in a previous version of the code. As I mentioned, I could not get it to work.

 

Best,

0 Kudos
Message 6 of 9
(4,515 Views)

@kineghp wrote:

Thanks for your quick input.

 

1.I'm openning it in two different location. The 3rd one is another DB. I can open it only once and reffer to the arrays in the other loop.

2. Any examples to guide me through this?

3. Would two loops with a value(signalling) property node programmatically fire the event structure?

Since you mentioned I should avoid event structures, how would I do that in a loop that runs at a reasonable speeds?

 

File/directory info function was in a previous version of the code. As I mentioned, I could not get it to work.

 

Best,


1.  I saw 3 DB opens.  It looked like they all had the same connection string.  Now I see the one says Write and the other 2 say Read.

2.  That is pretty straight forward.  You shouldn't need an example, but here it is.  I'm not sure if the Select part of the database series needs to be in the loop also.  But the image should give you the idea anyway.

3.  Yes, two loops would work.  But I'm wondering why do that.  You have one loop that needs to poll the database anyway, then just put it all there.  If you are going to tell me that you need to have an event structure for other reasons as well, and you want to closely integrate the writing of the database into the same loop that is doing user interaction, then using Value Signalling and and event structure might make sense.

 

To poll the database at a reasonable wait.  Put a wait function in its loop.  How often do you expect the database to change?  How quickly do you need to detect a change?  Once per second, every 10 seconds?  Once per minute, per hour?  For longer intervals, I would also put in an elapsed time Express VI to detect when the minute or the hour has passed and execute the database read only then.

 

0 Kudos
Message 7 of 9
(4,498 Views)

@RavensFan wrote:

@kineghp wrote:

Thanks for your quick input.

 

1.I'm openning it in two different location. The 3rd one is another DB. I can open it only once and reffer to the arrays in the other loop.

2. Any examples to guide me through this?

3. Would two loops with a value(signalling) property node programmatically fire the event structure?

Since you mentioned I should avoid event structures, how would I do that in a loop that runs at a reasonable speeds?

 

File/directory info function was in a previous version of the code. As I mentioned, I could not get it to work.

 

Best,


1.  I saw 3 DB opens.  It looked like they all had the same connection string.  Now I see the one says Write and the other 2 say Read.

2.  That is pretty straight forward.  You shouldn't need an example, but here it is.  I'm not sure if the Select part of the database series needs to be in the loop also.  But the image should give you the idea anyway.

3.  Yes, two loops would work.  But I'm wondering why do that.  You have one loop that needs to poll the database anyway, then just put it all there.  If you are going to tell me that you need to have an event structure for other reasons as well, and you want to closely integrate the writing of the database into the same loop that is doing user interaction, then using Value Signalling and and event structure might make sense.

 

To poll the database at a reasonable wait.  Put a wait function in its loop.  How often do you expect the database to change?  How quickly do you need to detect a change?  Once per second, every 10 seconds?  Once per minute, per hour?  For longer intervals, I would also put in an elapsed time Express VI to detect when the minute or the hour has passed and execute the database read only then.

 


I updated the code based on your suggestion. (attached)

 

But I'm still confused on how to make my loop run ONLY when there is a change in the database. What is the most efficent way to do this?

 

The changes in database would be randomly. It could go from every minute to every few hours. But on average I would say every few minutes.

 

Best,

 

0 Kudos
Message 8 of 9
(4,440 Views)

@kingehp wrote:

 

But I'm still confused on how to make my loop run ONLY when there is a change in the database. What is the most efficent way to do this?

 

The changes in database would be randomly. It could go from every minute to every few hours. But on average I would say every few minutes.

 

Best,

 


You can't.  Some way or another you are going to have to poll the database to determine when it changes.  What is most efficient?  I don't know.  You could try the file/date method like you were talking about.  Though that depends on how well filedate changes correlate with actual data changes.  What is causing the changes of data in the database?  Perhaps you can have that part signal your LabVIEW code that it has made changes.  You can use TCP/IP functions pretty reliable to signal between applications whether it is across a network or even on the same PC to send messages.

 

If it could change every few minutes, how immediately after a change occurs do you need to detect that change?  Can you wait another minute or so to find out?  Or do you need to know within seconds?  Your loop that polls the database could just execute the loop every few minutes to determine if a change occurred.

0 Kudos
Message 9 of 9
(4,417 Views)