TIA Portal v18: Does TIA Portal support "regular expressions"?

Mas01

Member
Join Date
Oct 2020
Location
Leicester, England
Posts
1,109
Does TIA Portal support "regular expressions" (regex)?

The operator needs to input a unique serial number in this format (see pic).

I want to be able to check that the operator has entered the part number in the correct format.

I did ask a similar question on this recently, so I may be implementing that as a solution.
https://www.plctalk.net/qanda/showthread.php?t=136851

Thanks in advance.

Capture.PNG
 
Last edited:
No idea, however, just use like was posted before if you have an array of bytes you could do 3 loops one of 6, one of 2 & one of 7 & check that the first loop (6) is numerals, second is letters (2), 3rd is numerals (7)
 
No idea, however, just use like was posted before if you have an array of bytes you could do 3 loops one of 6, one of 2 & one of 7 & check that the first loop (6) is numerals, second is letters (2), 3rd is numerals (7)

That's not a bad idea that. Cheers
 
Revised parser


Code:
FUNCTION "fc1_ParseString" : "strgparser"
{ S7_Optimized_Access := 'TRUE' ; Published := 'FALSE' }
VERSION : 0.1
   VAR_INPUT 
      sData : String;
   END_VAR

   VAR_TEMP 
      iChar : Int;
      j : Int;
      iStrLen : Int;
   END_VAR


BEGIN
    //Parse string for chars 'A..Z a..z 0..9'
    // String must be formatted as 6 numbers + 2 letters + 7 numbers e.g. 123456AB1234567
    //if string contains only these chars in these positions then return true
    //else return false
    //Return false for a string length not 15 chars
    
    #iStrLen := LEN(#sData);
    #fc1_ParseString.bOK := False; //not ok if no string
    #fc1_ParseString.sResult := 'String is not 15 chars long';
    IF (#iStrLen = 15) THEN
        FOR #j := 1 TO #iStrLen DO
            CASE #j OF
             1..6:  //positions must be numeric     
                 #fc1_ParseString.bOK :=false; //default not ok
                 #fc1_ParseString.sResult := 'First 6 chars must be numeric';
                    #iChar := #sData[#j];
                  
                    CASE #iChar OF
                        48..57: //0..9
                            #fc1_ParseString.bOK := True;
                    END_CASE;
            
                    IF NOT #fc1_ParseString.bOK THEN
                        EXIT;
                    END_IF;
                7..8: //positions must be Alphabet
                    #fc1_ParseString.bOK := false; //default not ok
                    #fc1_ParseString.sResult := 'Chars 7 and 8 must be alpha';
                    #iChar := #sData[#j];
                    CASE #iChar OF
                        65..90: //A...Z
                            #fc1_ParseString.bOK := True;
                        97..122: //a..z
                            #fc1_ParseString.bOK := True;
                    END_CASE;
                    IF NOT #fc1_ParseString.bOK THEN
                        EXIT;
                    END_IF;
                9..15: //positions must be numeric
                    #fc1_ParseString.bOK := false; //default not ok
                    #fc1_ParseString.sResult := 'Chars 9 to 15 must be numeric';
                    
                    #iChar := #sData[#j];
                    CASE #iChar OF
                        48..57: //0..9
                            #fc1_ParseString.bOK := True;
                            #fc1_ParseString.sResult := 'String format good';
                    END_CASE;
                    IF NOT #fc1_ParseString.bOK THEN
                        EXIT;
                    END_IF;
                 
                    
            END_CASE;
        END_FOR;
    END_IF;
END_FUNCTION
 
udt


Code:
TYPE "strgparser"
{ Published := 'FALSE' }
VERSION : 0.1
   STRUCT
      bOK : Bool;
      sResult : String;
   END_STRUCT;

END_TYPE
 
Add it as an external source file (strgparser.udt) and then generate block from source and it will appear in the PLC data types folder

udt.jpg
 

Similar Topics

hello every one. i'm new to tiaportal, i have created new project and HMI screen the program works fine with PLC-sim, but when i try to cntrol the...
Replies
9
Views
416
My PLC (S7-1200) and HMI (KTP-1200 Basic) has been delivered on-site to the customer. To be able to do "off-line" updates to the code, I am using...
Replies
4
Views
224
hi everyone. i hope you guys are doing great. i am trying to built communication between aveva intouch hmi 2023 and tia portal v18. i dont have...
Replies
1
Views
569
Hi, My PLC hardware has been delivered to customer site - many thanks for the invaluable help on this forum! I was looking into see if it's...
Replies
12
Views
2,518
Tia portal v18 issue,online icon greyed out but plc comms must be established as.blocks showing and no offline copy on laptop.
Replies
7
Views
1,107
Back
Top Bottom