Siemens S7/TIA v18: Only allow input of alphanumeric values......

Mas01

Member
Join Date
Oct 2020
Location
Leicester, England
Posts
1,114
For the project I'm doing, the operator has to enter a string of 7 alphanumeric characters. This represents the unique part number.

For now, the part number is not cross-checked with a "master list" of part numbers.
The part number is to be accepted, as long as it's alphanumeric. (i.e. any of 0-9, A-Z and a-z).
e.g.
48MS124 is valid
48M$124 is not valid.

Anyone got any ideas of how to program this in TIA/WinCC?

Is there a way of invoking a keypad on the touchscreen such that it only has alphanumeric characters? i.e. no maths functions, no minus sign etc.

p.s. These strings are to be saved (in a tag?) along with today's date.

Hope that makes sense. Happy to expand, if not clear.

Thanks
 
Last edited:
PLCS is a problem at the moment, it takes ages to load the site it's not my browser as firefox does the same thing so replying is slow.
I very much doubt the HMI can use special masks as numbers normally include +- & probably only be able to select either alpha numeric or numeric which would include +- I have no idea if the HMI is capable of filtering out certain chars i.e. $%£" etc. with a mask.
I think you will have to do this in the PLC not an easy task I think one way would be to take the string & check each char against the unwanted chars & flag that up on the HMI & make the operator re-input the string. This could be done by making sure each character (Hex value) is within certain limits i.e. H30 to H39 and H41 to 5A.
 
Validation Script: Add a script to validate the entered part number. TIA/WinCC supports programming in different languages like VBScript, C Script, etc.


OP is discussing WinCC Basic, which has no scripting. Your reference is for WinCC Pro.
 
Yes parky, definitely slow loading on this website lately, I've noticed it too.

Thanks for the reply, i guess I will have to do some range checking or something to validate the user input.
 
Here's a function you can use to parse your string. Create a file in notepad with extension .scl copy paste the code below and save it. In TIA use External source files to add a new source file, then compile the file to create the block in your program folder.
Code:
FUNCTION "fc1_ParseString" : Bool
{ S7_Optimized_Access := 'TRUE' }
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'
    //if string contains only these chars then return true
    //else return false
    //Return true for a string of zero length
    
    #iStrLen := LEN(#sData);
    #fc1_ParseString := True; //ok if no string - abitrary choice
    IF #iStrLen > 0 THEN
        FOR #j := 1 TO #iStrLen DO
            #fc1_ParseString := false; //default not ok
            #iChar := #sData[#j];
            CASE #iChar OF
                65..90: //A...Z
                    #fc1_ParseString := True;
                97..122: //a..z
                    #fc1_ParseString := True;
                48..57: //0..9
                    #fc1_ParseString := True;
            END_CASE;
            IF NOT #fc1_ParseString THEN
                EXIT;
            END_IF;
        END_FOR;
    END_IF;
END_FUNCTION
 
Last edited:
Here's a function you can use to parse your string. Create a file in notepad with extension .scl copy paste the code below and save it. In TIA use External source files to add a new source file, then compile the file to create the block in your program folder.
Code:
FUNCTION "fc1_ParseString" : Bool
{ S7_Optimized_Access := 'TRUE' }
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'
    //if string contains only these chars then return true
    //else return false
    //Return true for a string of zero length
    
    #iStrLen := LEN(#sData);
    #fc1_ParseString := True; //ok if no string - abitrary choice
    IF #iStrLen > 0 THEN
        FOR #j := 1 TO #iStrLen DO
            #fc1_ParseString := false; //default not ok
            #iChar := #sData[#j];
            CASE #iChar OF
                65..90: //A...Z
                    #fc1_ParseString := True;
                97..122: //a..z
                    #fc1_ParseString := True;
                48..57: //0..9
                    #fc1_ParseString := True;
            END_CASE;
            IF NOT #fc1_ParseString THEN
                EXIT;
            END_IF;
        END_FOR;
    END_IF;
END_FUNCTION

Apologies for the delay in replying...this website has been really slow to connect to recently, often timing out.

This looks brilliant, but I'm new to TIA....you'll have to excuse my ignorance...where would this code go into? Into a function block? If so, I've not used those before.
Thanks
 
Last edited:
Apologies for the delay in replying...this website has been really slow to connect to recently, often timing out.

This looks brilliant, but I'm new to TIA....you'll have to excuse my ignorance...where would this code go into? Into a function block? If so, I've not used those before.
Thanks


Put it into just a Function, not Function Block, but yes.

I suspect there is at least one YouTube explaining how to create a new function in TIA.
 
With a few tweaks, the FC that LD posted could be used to convert the input that has invalid characters into one that doesn't, by checking each character and if it's valid, concatenate a string with only the valid characters.
 
This looks brilliant, but I'm new to TIA....you'll have to excuse my ignorance...where would this code go into? Into a function block? If so, I've not used those before.
Thanks


1. Create a new text file on your desktop ( or wherever you want) and rename it "parseString.scl"
2. Copy the code above and paste into that file.
3. Open the project in Tia Portal. Be careful, if you already have another function called FC1 within your project the system will overwrite it. My suggestion is to do this operation in a blank project, then copy to your actual project.
4. In the "Project tree" expand your PLC and find a folder called "External source file"
5. Click "Add new external file" and import parseString.scl
6. Right click on the imported file and select "Geenerate blocks from source"
7. If the operation will be successfull, you'll find a new Function inside "Program blocks" folder
 
1. Create a new text file on your desktop ( or wherever you want) and rename it "parseString.scl"
2. Copy the code above and paste into that file.
3. Open the project in Tia Portal. Be careful, if you already have another function called FC1 within your project the system will overwrite it. My suggestion is to do this operation in a blank project, then copy to your actual project.
4. In the "Project tree" expand your PLC and find a folder called "External source file"
5. Click "Add new external file" and import parseString.scl
6. Right click on the imported file and select "Geenerate blocks from source"
7. If the operation will be successfull, you'll find a new Function inside "Program blocks" folder
Awesome, really appreciate the help everyone.

I've got managers breathing down my neck asking 'when will this be ready?'...meanwhile I'm learning TIA/WinCC on the fly having had no previous experience (only done Mitsubishi Q-series /GX Developer previously , which is significantly different) and then hit problems like this alphanumeric issue which causes me delays.
Anyway, rant over - I'm very grateful for your help.
I'll give it a try on Monday.
Cheers
 
cancel that last question....just 1 compilation error now.

Here's a new one.

How can I resolve this error?
Sorry for basic question - I've not done SCL before...

fc4 error 2.png
 
If I Remember correctly you do not need the output Var fc1_Parse_String as the function it'self is the return.
 

Similar Topics

Context: PLC= S7-1212C, HMI=KTP1200 Basic. Hi again, When the "REPORT" button is pressed (on a different screen), it takes the operator to the...
Replies
7
Views
760
Context: PLC= S7-1212C, HMI=KTP1200 Basic. Hi, The operator has reported that, from time-to-time, when he presses the "Generate Report" button...
Replies
5
Views
544
General Question: The PLC and HMI that I've been working on (a laser measurement system) is soon to be transported to the site where it will be...
Replies
2
Views
740
Hi, I'm not sure how to do this... Basically, I want to restrict the user input values for this tag to be in the range 20.001 to 25.0. I...
Replies
17
Views
1,792
Can someone help me with this? I'm no good at SCL - virtually everything I've done so far has been ladder logic. The return value from the...
Replies
13
Views
1,162
Back
Top Bottom