You are not registered yet. Please click here to register!


 
 
plc storereviewsdownloads
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
 
Try our online PLC Simulator- FREE.  Click here now to try it.

---------->>>>>Get FREE PLC Programming Tips

New Here? Please read this important info!!!


Go Back   PLCS.net - Interactive Q & A > PLCS.net - Interactive Q & A > LIVE PLC Questions And Answers

PLC training tools sale

Reply
 
Thread Tools Display Modes
Old June 8th, 2017, 06:12 PM   #1
aaron_f
Member
Mexico

aaron_f is offline
 
Join Date: Dec 2009
Location: Monterrey
Posts: 4
Compare String Tags using Crimson 3

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

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!
  Reply With Quote
Old June 8th, 2017, 06:23 PM   #2
keshik
Lifetime Supporting Member
Canada

keshik is offline
 
Join Date: Jun 2011
Location: Portland, OR
Posts: 350
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:
Quote:
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 by keshik; June 8th, 2017 at 06:36 PM. Reason: Added more information
  Reply With Quote
Old June 8th, 2017, 06:25 PM   #3
keshik
Lifetime Supporting Member
Canada

keshik is offline
 
Join Date: Jun 2011
Location: Portland, OR
Posts: 350
Also, you can use the [.code] and [./code] wrappers here on the forum to format code snippets like that a little better (remove the ".").
  Reply With Quote
Old June 8th, 2017, 09:54 PM   #4
aaron_f
Member
Mexico

aaron_f is offline
 
Join Date: Dec 2009
Location: Monterrey
Posts: 4
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!

Quote:
Originally Posted by keshik View Post
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.
  Reply With Quote
Old June 9th, 2017, 10:57 AM   #5
keshik
Lifetime Supporting Member
Canada

keshik is offline
 
Join Date: Jun 2011
Location: Portland, OR
Posts: 350
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.
  Reply With Quote
Old June 15th, 2017, 12:00 AM   #6
aaron_f
Member
Mexico

aaron_f is offline
 
Join Date: Dec 2009
Location: Monterrey
Posts: 4
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.



Quote:
Originally Posted by keshik View Post
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.
  Reply With Quote
Old June 15th, 2017, 10:22 AM   #7
aaron_f
Member
Mexico

aaron_f is offline
 
Join Date: Dec 2009
Location: Monterrey
Posts: 4
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";
}
  Reply With Quote
Old June 15th, 2017, 10:37 AM   #8
keshik
Lifetime Supporting Member
Canada

keshik is offline
 
Join Date: Jun 2011
Location: Portland, OR
Posts: 350
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.
  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Topics
Thread Thread Starter Forum Replies Last Post
A Free HMI with Eye Catching Graphics is Now Available Archie LIVE PLC Questions And Answers 1006 November 1st, 2017 09:42 PM
Crimson 3.0/RedLion Addition On Internal Tags laserweld LIVE PLC Questions And Answers 2 January 23rd, 2017 09:33 AM
XML read problem in VB.Net Combo LIVE PLC Questions And Answers 8 October 15th, 2015 12:08 PM
S7 SCL - Compare string from Block_DB SeH LIVE PLC Questions And Answers 2 June 27th, 2011 08:34 AM
Simatic OP 177 string tags Polle LIVE PLC Questions And Answers 4 November 8th, 2006 05:05 PM


All times are GMT -5. The time now is 09:30 PM.


.