![]() ![]() ![]() ![]() ![]() ![]() |
||
![]() |
||
![]() ![]() ![]() ![]() This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc. |
||
![]() |
![]() |
#1 |
Member
![]() ![]() 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. |
![]() |
![]() |
#2 |
Member
|
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. |
![]() |
![]() |
#3 |
Lifetime Supporting Member
![]() ![]() Join Date: Jun 2013
Location: MI
Posts: 3,151
|
|
![]() |
![]() |
#4 |
Member
![]() ![]() 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. |
![]() |
![]() |
#5 |
Lifetime Supporting Member
![]() ![]() 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. |
![]() |
![]() |
#6 |
Lifetime Supporting Member
![]() ![]() Join Date: Nov 2006
Location: UK
Posts: 6,656
|
Example calls:
__________________
S7-300 to 1500 conversions done - email (minus the spam) to spams7conversions@hotmail.com |
![]() |
![]() |
#7 | |
Member
![]() ![]() Join Date: Oct 2020
Location: Leicester, England
Posts: 1,044
|
Quote:
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. |
|
![]() |
![]() |
#8 | |
Lifetime Supporting Member
|
Quote:
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. |
|
![]() |
![]() |
#9 |
Lifetime Supporting Member
![]() ![]() 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.
__________________
|
![]() |
![]() |
#10 | |
Member
![]() ![]() Join Date: Mar 2015
Location: Italy
Posts: 7
|
Quote:
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 |
|
![]() |
![]() |
#11 | |
Member
![]() ![]() Join Date: Oct 2020
Location: Leicester, England
Posts: 1,044
|
Quote:
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 |
|
![]() |
![]() |
#12 |
Member
![]() ![]() Join Date: Oct 2020
Location: Leicester, England
Posts: 1,044
|
Anyone know how to resolve this compilation error?
Thanks |
![]() |
![]() |
#13 |
Member
![]() ![]() 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... |
![]() |
![]() |
#14 |
Member
![]() ![]() 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?
|
![]() |
![]() |
#15 |
Member
|
If I Remember correctly you do not need the output Var fc1_Parse_String as the function it'self is the return.
|
![]() |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Display Modes | |
|
|
![]() |
||||
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 |