Red Lion Crimson 3.0 - Run Program on Data Change

gimli

Member
Join Date
Nov 2014
Location
nowhere
Posts
34
Hello all,

Kinda new to Crimson 3.0. Looking to run a program when a string tag data value has changed. I haven't seen any setting to do that for string tags. I guess I could set up a integer to increment every time the string value changes and use (change of state) for that integer to trigger the program. Any other ideas would be great...not sure if that is the best way.

thanks
much
 
What I like to do is run a continuous program in a background task (I usually call it "Main"). This program gets called on power-up. In that program I do something like this:

Code:
int firstScan;
cstring newString, oldString;

if (!firstScan) {
  // set up variables
  firstScan = true;
}

// main loop - continuously executed
while (1) {
  if (newString != oldString) {
    stringProcressingProgram();
  }
  oldString = newString;
}
 
Is the string tag being modified by the user in a data box? In that case you can use the On Entry Complete and On Entry Error actions in the data box properties to execute a program.

If the tag is changed by an external signal or device, then keshik's suggestion may be the best way. There don't seem to be Triggers available for string tags.
 
Kolyur,

The string tag is being modified via barcode reader.

Looks like Keshiks example should work just fine. But good to know about the data box triggers also.

Ill give it a try

thanks much(y)
 
So reading how backround programs function it says that "values cannot be returned from programs running in the backround". I guess that means values cant be returned to data tags? Also it seems you can not add declared program variables to the watch window?

Anyways
This does not seem to work for me...looping where indicated...any help would be greatly appreciated.o_O

Code:
int firstScan;
cstring newString, oldString;
if (!firstScan) 
{
// Sets new and old string to same value...only does this once
    newString := ProductScan; 
    oldString := ProductScan; 
    firstScan = true;
}
// main loop - continuously executed
while (1) 
{
  if (newString != oldString) 
{
     dothisprogam(); //looping
}
  oldString = ProductScan;
}
 
I would put the oldString initialization part in as a startup program.

As long as it is okay for the program to run up to one second after the data changes, I would have a program (without loops) that runs "on tick" or "on update" to compare the oldString to the tag data.

A program can have locally scoped variables that cannot be monitored in a watch window. If you want to monitor an element used in your program, use a data tag there.
 
How are you calling this program? Is it being launched on powerup?

I'd make a tag and increment every scan through the while loop:
Code:
while(1) {
  tag1 = tag1 + 1;
}

Put this tag on a display and it should update quickly. If it's not, you're not actually running the program.

*****

The variables that you declare in a program (for example, int firstScan;) are only valid on that scan through the logic. They have no memory to the next scan. For example, if you have a program like:

Code:
int tag1 = 0;
tag1 = tag1 + 1;

At the end of each scan through that program tag1 will always equal 1. Each time the variable is re-initialized to 0 so you always get 0+1. If you want to access any variables over multiple scans and/or from outside the program it will need to be declared as a tag. You can then use it normally. My little while loop program from my initial example never actually completes executing which is why I can use local variables the way that I am. Keep in mind that doing it that way will hog that background task and you shouldn't use that background task for anything else.

*****

Personally, I'm not a huge fan of using the "on tick" method of calling programs. I find that it will result in a system that feels much less responsive. Just my personal opinion on that though.
 

Similar Topics

How do you install update on Red Lion Crimson ver 3.1. Do I just need to run the exe file on the host server?
Replies
1
Views
106
Hi, I am trying to increase the size of the user login pop up using a Red Lion CR1000 7” HMI with Crimson 3.1 software. The login pop up is very...
Replies
2
Views
668
Hello, We are currently running a bunch of g310's connected to their SLC5 PLCs through ethernet. I've attempted to upgrade the program from 2.0...
Replies
1
Views
1,121
Hi I have been using Red Lion products for some time, I had a thought over the bank holiday weekend, As you do. It would be nice if whenever a...
Replies
4
Views
1,015
Well, I have yet another question for the great minds on this forum! We have a red lion HMI for one of our machines and every time I hook my...
Replies
11
Views
1,670
Back
Top Bottom