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.

New Here? Please read this important info!!!


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

Reply
 
Thread Tools Display Modes
Old July 25th, 2023, 11:01 AM   #1
Mas01
Member
United Kingdom

Mas01 is offline
 
Join Date: Oct 2020
Location: Leicester, England
Posts: 1,044
Siemens S7/TIA v18: Only allow input of alphanumeric values......

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 by Mas01; July 25th, 2023 at 11:16 AM.
  Reply With Quote
Old July 26th, 2023, 03:08 AM   #2
parky
Member
United Kingdom

parky is offline
 
parky's Avatar
 
Join Date: Oct 2004
Location: Midlands
Posts: 5,485
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.
  Reply With Quote
Old July 26th, 2023, 04:40 PM   #3
mk42
Lifetime Supporting Member
United States

mk42 is offline
 
Join Date: Jun 2013
Location: MI
Posts: 3,151
Quote:
Originally Posted by aeliyamarine View Post
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.
  Reply With Quote
Old July 26th, 2023, 06:55 PM   #4
Mas01
Member
United Kingdom

Mas01 is offline
 
Join Date: Oct 2020
Location: Leicester, England
Posts: 1,044
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.
  Reply With Quote
Old July 27th, 2023, 01:02 PM   #5
L D[AR2,P#0.0]
Lifetime Supporting Member
United Kingdom

L D[AR2,P#0.0] is offline
 
Join Date: Nov 2006
Location: UK
Posts: 6,656
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
__________________
S7-300 to 1500 conversions done - email (minus the spam) to spams7conversions@hotmail.com

Last edited by L D[AR2,P#0.0]; July 27th, 2023 at 01:10 PM.
  Reply With Quote
Old July 27th, 2023, 01:06 PM   #6
L D[AR2,P#0.0]
Lifetime Supporting Member
United Kingdom

L D[AR2,P#0.0] is offline
 
Join Date: Nov 2006
Location: UK
Posts: 6,656
Example calls:
Attached Images
File Type: jpg parse.jpg (99.7 KB, 87 views)
__________________
S7-300 to 1500 conversions done - email (minus the spam) to spams7conversions@hotmail.com
  Reply With Quote
Old July 28th, 2023, 05:57 PM   #7
Mas01
Member
United Kingdom

Mas01 is offline
 
Join Date: Oct 2020
Location: Leicester, England
Posts: 1,044
Quote:
Originally Posted by L D[AR2,P#0.0] View Post
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 by Mas01; July 28th, 2023 at 05:59 PM.
  Reply With Quote
Old July 28th, 2023, 06:53 PM   #8
drbitboy
Lifetime Supporting Member
United States

drbitboy is online now
 
drbitboy's Avatar
 
Join Date: Dec 2019
Location: Rochester, NY
Posts: 7,302
Quote:
Originally Posted by Mas01 View Post
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.
__________________
_
Brian T. Carcich
i) Take care of the bits, and the bytes will take care of themselves.
ii) There is no software problem that cannot be solved with another layer of indirection.
iii) Measurement is hard.
iv) I solemnly swear that I am up to no good
v) I probably have the highest ratio of forum posts to actual applications in the field (but no longer ∞ ).
vi) Hakuna matata.
vii) Bookkeeping.
viii) But I should be ignored.
  Reply With Quote
Old July 28th, 2023, 09:40 PM   #9
Rob...
Lifetime Supporting Member
United Kingdom

Rob... is offline
 
Join Date: Jul 2016
Location: Manchester
Posts: 460
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.
__________________
  Reply With Quote
Old July 29th, 2023, 06:53 AM   #10
Guynrush
Member
Italy

Guynrush is offline
 
Join Date: Mar 2015
Location: Italy
Posts: 7
Quote:
Originally Posted by Mas01 View Post

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
  Reply With Quote
Old July 29th, 2023, 07:06 AM   #11
Mas01
Member
United Kingdom

Mas01 is offline
 
Join Date: Oct 2020
Location: Leicester, England
Posts: 1,044
Quote:
Originally Posted by Guynrush View Post
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
  Reply With Quote
Old September 6th, 2023, 07:52 AM   #12
Mas01
Member
United Kingdom

Mas01 is offline
 
Join Date: Oct 2020
Location: Leicester, England
Posts: 1,044
Anyone know how to resolve this compilation error?

Thanks
Attached Images
File Type: png fc4.png (103.5 KB, 28 views)
  Reply With Quote
Old September 6th, 2023, 08:04 AM   #13
Mas01
Member
United Kingdom

Mas01 is offline
 
Join Date: Oct 2020
Location: Leicester, England
Posts: 1,044
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...
Attached Images
File Type: png fc4 error 2.png (95.6 KB, 28 views)
  Reply With Quote
Old September 6th, 2023, 08:07 AM   #14
Mas01
Member
United Kingdom

Mas01 is offline
 
Join Date: Oct 2020
Location: Leicester, England
Posts: 1,044
To add to the above...the function does appear to return a boolean, look here?
Attached Images
File Type: png fc4 error 2-a.png (104.8 KB, 29 views)
  Reply With Quote
Old September 6th, 2023, 08:21 AM   #15
parky
Member
United Kingdom

parky is offline
 
parky's Avatar
 
Join Date: Oct 2004
Location: Midlands
Posts: 5,485
If I Remember correctly you do not need the output Var fc1_Parse_String as the function it'self is the return.
  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum


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
Studio 5000 reading analogue input low and high engineering values matt.smith LIVE PLC Questions And Answers 9 March 1st, 2017 09:14 AM
Siemens S5 115 timer values CRMCC LIVE PLC Questions And Answers 3 August 9th, 2015 09:50 AM
Siemen's S7300 AC input card delay becs LIVE PLC Questions And Answers 0 March 22nd, 2012 03:17 PM
Siemens S7300, PT100 input -> 4-20mA output Egil-s LIVE PLC Questions And Answers 6 March 2nd, 2011 03:14 AM
Siemens Analog Input and PT 100 RTD Labotomi LIVE PLC Questions And Answers 1 January 23rd, 2004 07:54 PM


All times are GMT -4. The time now is 08:06 AM.


.