Compare String Tags using Crimson 3

aaron_f

Member
Join Date
Dec 2009
Location
Monterrey
Posts
4
Hello guys, I have the following setup:

1 x Graphite RLCs HMI
1 x Barcode Reader (Acting as Keyboard)
3 x Plcs Mapped using Modbus Tcp/IP

What I want to accomplish:
Using a String Data Tag (Internal) I can scan successfully most barcodes, and store then in the String Data Tag in the HMI.

For the sake of argument lets say I have 3 different screens which I don't want them to be manually accessible, but, rather be accessed if I scan the correct barcode, then It takes me to the correct screen. Each individual screen can be accessed by multiple barcodes. Lets say B.Codes: 1-ABC,2-ABC,3-CBA, any one one those barcodes when scanned should take me to screen#2, and so on for another array of 20 barcodes will take me to screen#3, etc...

I was thinking on solving this by doing the following:

1) Create a String Tag for the Barcode scanner, internal, volatile, and place it as a data entry field on the main screen; named: "Barcode_Scanner"

2) Then create say 100 String tags, internal, non-volatile, which hold the predefined barcodes that are expected to be scanned. Maybe create an Edit screen where I can edit each individually if changes are needed or any editing.

3) then, on the main screen, edit the "Barcode_Scanner" tag, go to the property box:Entry Tab:Actions:On Entry Complete; drag and Drop a Program called "Barcode_Comparison"

4) The Program named "Barcode_Comparison" will compare the barcode Scanner RAW String Num/Char's. versus the Internal Database RAW String Num/Char's.

The Operands and Code I taught of looks like this, but my program is not working, let alone when I click translate I get a message "This Expression must be an integer". I must say I have some experience with the RLC HMI but never done Programs/Functions/or Control; so please bare with me for any upcoming atrocity on my Crimson code skills :whistle:

My example Code for Program "Barcode_Comparison",:

___________Code begins below_______________________

if (Barcode_Scanner.AsText)== "1-ABC"|"2-ABC"|"3-CBA"
{

GOTOPAGE(Screen_2); //Screen corresponding to any of those Barcodes.
Barcode_Scanner.AsText ="XXX-XXXXX-XXX"; //Clear the TagValue, for Next Barcode Scann Cycle.

else if

(Barcode_Scanner.AsText)== "22-DEF"|"23-DEF"|"23-DEF-01230"

GOTOPAGE(Screen_1); //Screen corresponding to any of those Barcodes.
Barcode_Scanner.AsText ="XXX-XXXXX-XXX"; //Clear the TagValue, for Next Barcode Scann Cycle.

else if

(Barcode_Scanner.AsText)== "55-DEF"|"56-DEF"|"57-DEF-010"

GOTOPAGE(Screen_3); //Screen corresponding to any of those Barcodes.
Barcode_Scanner.AsText ="XXX-XXXXX-XXX"; //Clear the TagValue, for Next Barcode Scann Cycle.

else if

Barcode_Scanner.AsText = "INVALID BARCODE SCAN, Please Try Again"; //Warning for NON valid Code.

}

_______________ End of CODE___________

Please , Any advice is welcome guys, if you consider a different approach is more accurate feel free to point me in that direction, your help will be certainly appreciated.

Thanks in advance!🤞🏻
 
Try removing the ".AsText" from your Barcode_Scanner string. If it's a string, you shouldn't have to declare it as a string again. I would save the ".AsText" for when you are trying to get the string representation of a numeric value.

From the manual, under the "Comparing Values" section, there is the following text:
Each operator produces a value of 0 or 1, depending on the condition it tests. The operators can be used on integers, floating point values or strings. If strings are being compared, the comparison is case-insensitive such that “abc” is considered equal to “ABC”.

The lack of case sensitivity shouldn't be an issue for you but it does say that you can test string equalities using the "==" operator. For your "OR" part, you'll probably have to write them out a little longer than you currently are:

Code:
if ((Barcode_Scanner == "1-ABC") || (Barcode_Scanner == "2-ABC") || (Barcode_Scanner == "3-CBA"))
{
        GOTOPAGE(Screen_2);	//Screen corresponding to any of those Barcodes.

        //Clear the TagValue, for Next Barcode Scann Cycle.
        Barcode_Scanner.AsText ="XXX-XXXXX-XXX"; 
}
else if
...

It also looks like you may have missed some closing curly braces ("}") for each IF statement.
 
Last edited:
Also, you can use the [.code] and [./code] wrappers here on the forum to format code snippets like that a little better (remove the ".").
 
Well that Worked! removed the asText, and made the suggested code syntax corrections and presto. Thank you! do you have any other suggestion you might have tried in the past, regarding the String Database I suggested creating? is this a proper way or would a Recpie or Excel file in a PC with the barcodes, any thoughts or suggestions on that?

Thanks!

Try removing the ".AsText" from your Barcode_Scanner string. If it's a string, you shouldn't have to declare it as a string again. I would save the ".AsText" for when you are trying to get the string representation of a numeric value.

From the manual, under the "Comparing Values" section, there is the following text:


The lack of case sensitivity shouldn't be an issue for you but it does say that you can test string equalities using the "==" operator. For your "OR" part, you'll probably have to write them out a little longer than you currently are:

Code:
if ((Barcode_Scanner == "1-ABC") || (Barcode_Scanner == "2-ABC") || (Barcode_Scanner == "3-CBA"))
{
        GOTOPAGE(Screen_2);	//Screen corresponding to any of those Barcodes.

        //Clear the TagValue, for Next Barcode Scann Cycle.
        Barcode_Scanner.AsText ="XXX-XXXXX-XXX"; 
}
else if
...

It also looks like you may have missed some closing curly braces ("}") for each IF statement.
 
Here's what I would probably try. This is for something that I don't have to do a ton of edits on, or have someone else edit for me.

Create three tags:
Barcode_Scanner --> STRING
Barcodes --> Array of 100 STRING elements
Barcode_Page --> Array of 100 signed integers

Create a program similar to what you were talking about previously. This program will use a FOR loop (you could also use a different kind of loop if you want) to search through a string array for matching bar codes.
Code:
int idx, numBarcodes;
numBarcodes = 100;

for (idx = 0; idx < numBarcodes; idx++)
{
	// search for a barcode match
	if (Barcode_Scanner == Barcodes[idx])
	{
		// launch the appropriate display page
		switch (Barcode_Page[idx])
		{
			case 1:
				GotoPage(display1);
				break;
			case 2:
				GotoPage(display2);
				break;
			// add more display pages here as needed
			default:
				GotoPage(displayDefault);
				break;
		}
		//exit the FOR loop early
		break;
	}
}

// clear the barcode value
Barcode_Scanner = "";

Then create a program called "BarcodeList" that looks like the below. In here we are going to populate the array with a bunch of barcode IDs and an arbitrary page number that we will use to select a display page to load. Make sure that you call this program before you start searching for any barcodes.
Code:
Barcodes[0] = "A-DFS";
Barcode_Page[0] = 1;

Barcodes[1] = "A-DKFF";
Barcode_Page[1] = 1;

Barcodes[2] = "A-DKDA";
Barcode_Page[2] = 2;

Once you have these working, you should only have to edit the "BarcodeList" program with a new barcode. The rest of the logic won't have to be touched unless you want to launch a new/different display page.
 
Ok, I haven't tried that just yet, I tried to do something similar maybe less complicated to gather some experience before implementing your function, but ran with an issue that I believe I could have ran into doing this same function you suggest... its been puzzling me for some days now already, and I don't know what changed.

I did create 2 String Tags called "Barcodes_1" and "Barcodes_2" containing an Array of 100 strings or so each..
Then I toggled the Array and looked like this:

Barcodes_1:
barcodes_1[0]
barcodes_1[1]
barcodes_1[2]

Barcodes_2:
barcodes_2[0]
barcodes_2[1]
barcodes_2[2]

respectively and Retentive of course.

Then I went ahead, and before trying your suggested Loop function, I went ahead placed on the web server tab, those toggled array of "Barcodes_1" and "Barcodes_2" so I can edit them directly and individually from the web browser, and not need to go inside the crimson file each time I need editing.

So Now, I went ahead and tried to test this, I programmed the first 3 "barcodes_1" tags directly from the web server and the remaining "barcodes_2" from the HMI as Data Entry too... , but apparently the program doesn't want to recognize them directly as tags, the program looks like this:

//Barcode_Scanner belongs to a string tag

if ((Barcode_Scanner == "Barcodes_1[0]") || (Barcode_Scanner == "Barcodes_1[1]") || (Barcode_Scanner == "Barcodes_1[2]") )
{
GotoPage(Page1);

Barcode_Scanner ="XXX-XXXXX-XXX"; //Clear the TagValue, for Next Barcode Scann Cycle.
PlayRTTTL("Beethoven:d=3,o=6,b=100:a5,a5,a5,c,c,a5,a5,g5,f5,f5."); //Audible Confirmation Scann was successful.
}
else if

((Barcode_Scanner == "Barcodes_2[0]") || (Barcode_Scanner == "Barcodes_2[1]") || (Barcode_Scanner == "Barcodes_2[2]") )
{
GotoPage(Page2);

Barcode_Scanner ="XXX-XXXXX-XXX"; //Clear the TagValue, for Next Barcode Scann Cycle.
PlayRTTTL("Beethoven:d=3,o=6,b=100:a5,a5,a5,c,c,a5,a5,g5,f5,f5."); //Audible Confirmation Scann was successful.
}

else

{
Barcode_Scanner ="BarCode NOT Recognized, Please scan Again";
}

_______________________END__________________

The function as above, is not doing the Compare function, I tripled checked the values and they do Match, "barcode_Scanner" and "Barcodes_1[0]", they are equal, but the function is not taking me to the Page_1... I still don't know What changed? I did try adding the .asText but still no luck. Any advice????

Thanks in advance and sorry for the long reply, tried to pull my weight off, but still un able too.



Here's what I would probably try. This is for something that I don't have to do a ton of edits on, or have someone else edit for me.

Create three tags:
Barcode_Scanner --> STRING
Barcodes --> Array of 100 STRING elements
Barcode_Page --> Array of 100 signed integers

Create a program similar to what you were talking about previously. This program will use a FOR loop (you could also use a different kind of loop if you want) to search through a string array for matching bar codes.
Code:
int idx, numBarcodes;
numBarcodes = 100;

for (idx = 0; idx < numBarcodes; idx++)
{
	// search for a barcode match
	if (Barcode_Scanner == Barcodes[idx])
	{
		// launch the appropriate display page
		switch (Barcode_Page[idx])
		{
			case 1:
				GotoPage(display1);
				break;
			case 2:
				GotoPage(display2);
				break;
			// add more display pages here as needed
			default:
				GotoPage(displayDefault);
				break;
		}
		//exit the FOR loop early
		break;
	}
}

// clear the barcode value
Barcode_Scanner = "";

Then create a program called "BarcodeList" that looks like the below. In here we are going to populate the array with a bunch of barcode IDs and an arbitrary page number that we will use to select a display page to load. Make sure that you call this program before you start searching for any barcodes.
Code:
Barcodes[0] = "A-DFS";
Barcode_Page[0] = 1;

Barcodes[1] = "A-DKFF";
Barcode_Page[1] = 1;

Barcodes[2] = "A-DKDA";
Barcode_Page[2] = 2;

Once you have these working, you should only have to edit the "BarcodeList" program with a new barcode. The rest of the logic won't have to be touched unless you want to launch a new/different display page.
 
Never mind, Fixed it, it was the "" surrounding the array tags in the function, I removed them and it worked like this:

if ((Barcode_Scanner == Barcodes_1[0]) || (Barcode_Scanner == Barcodes_1[1]) || (Barcode_Scanner == Barcodes_1[2]) )
{
GotoPage(Page1);

Barcode_Scanner ="XXX-XXXXX-XXX"; //Clear the TagValue, for Next Barcode Scann Cycle.
PlayRTTTL("Beethoven:d=3,o=6,b=100:a5,a5,a5,c,c,a5 ,a5,g5,f5,f5."); //Audible Confirmation Scann was successful.
}
else if

((Barcode_Scanner == Barcodes_2[0]) || (Barcode_Scanner == Barcodes_2[1]) || (Barcode_Scanner == Barcodes_2[2]) )
{
GotoPage(Page2);

Barcode_Scanner ="XXX-XXXXX-XXX"; //Clear the TagValue, for Next Barcode Scann Cycle.
PlayRTTTL("Beethoven:d=3,o=6,b=100:a5,a5,a5,c,c,a5 ,a5,g5,f5,f5."); //Audible Confirmation Scann was successful.
}

else

{
Barcode_Scanner ="BarCode NOT Recognized, Please scan Again";
}
 
Yup, that's it.

One thing to be careful of with retentive tags and Red Lion is how often they actually get saved to non-volatile memory. They don't get saved immediately after the tag gets changed, but rather at set intervals (in an attempt to reduce the write cycles to the retentive memory). I believe that the intervals are approximately 1 minute after power up, and then every 7 minutes after that. That means that if you make a change 3 minutes after power up and lose power 4 minutes after power up your change won't be retained.

Just something to be aware of.
 

Similar Topics

hi all i hope your well i have got 2 plcs a siemens 1500 and 1200 comunicating a data black only 2 values in a wstring i need to get a code...
Replies
3
Views
2,013
Hey all, I was wondering if anyone could help me setup some trap logic that will compare incoming strings to all the strings received in the last...
Replies
12
Views
3,419
Hello, I know this will be easy for most. I currently scan a barcode on a part and it returns a string value with a mix of numbers and letters. I...
Replies
1
Views
1,352
Having an issue, this is my first attempt at setting something like this up, and hoping its just something minor im missing. scenario. have a...
Replies
5
Views
1,838
I am working on a Step 7 project where I have to read some barcodes and store the full code as a string which I'm fine with. I also need to...
Replies
1
Views
1,576
Back
Top Bottom