S7 IEC Function (FC26) MID

pethoek

Member
Join Date
Apr 2009
Location
Järbo
Posts
105
I can't get the MID function to work. Anoyone with same experience ?

CALL "MID"
IN :=#MYSTR
L :=5
P :=6
RET_VAL:=#PART
NOP 0

MYSTR STRING[17] = 'This is my string'

PART should evaluate to 'is my'

But when monitoring the FB where this snippet is executed, i don't get that "green" frame around the block indicating that it does not compute, something does not work.

I tried with LEFT function (FC20) and that worked fine, also FIND (FC11) works. But for some reason the MID function does not work.

Need help with this one.

The CPU i use is a IM151-8 PN/DP (Step7 5.4 SP4)

o_O
 
It could be that the previous network has one or more "orphaned" STL code lines.
If there is a line with for example "A M21.4" with no following output logic, then the RLO can carry over into the next network.

As always, post your code.
 
And what would the solution of that be ?

Network emmideately above is written in FDB. (Its a simple FIND function, find the first occurance of STR in COMPLETE_STRING)

I have tested the MID function solely by it self in a program with HARD coded STAT:STRING variable within an FB but same result there. MID refuses to return the sub_string.

Best regards
/Pethoek

It could be that the previous network has one or more "orphaned" STL code lines.
If there is a line with for example "A M21.4" with no following output logic, then the RLO can carry over into the next network.

As always, post your code.
 
Last edited:
I have just made a test with MID. It works as intended in PLCSIM. I dont have an IM151-8 available to test on.
If you want this pogram I can send it to you, at 472 kB it is too large to attach here. PM me your email if you are interested.
 
Solution

I involved the SIMATIC support in sweden. There is a "BUG" in the MID function that involves the RLO-bit.

In order to get the MID function to work, you must do a SET before you call the MID (fc26) function.

/Pethoek.
 
What version of FC26 are you using ? I've got V1.2 and the first two instructions in the block are:

Code:
SET
SAVE

Why don't you create a small project with your bug present and then post it for analysis.
 
I also use version 1.2, code below, works when SET is in network 1, if i remove NW1 the MID function will not work.



FUNCTION_BLOCK FB 100
TITLE =
VERSION : 0.1

VAR
MYSTR : STRING [17 ] := 'This Is My String';
RET : STRING [254 ];
END_VAR
BEGIN
NETWORK
TITLE =

SET ;
NETWORK
TITLE =
CALL "MID" (
IN := #MYSTR,
L := 5,
P := 6,
RET_VAL := "RXDB".RESPONSE);
NOP 0;
END_FUNCTION_BLOCK
DATA_BLOCK DB 1
TITLE =
VERSION : 0.0
FB 100
BEGIN
MYSTR := 'This Is My String';
RET := '';
END_DATA_BLOCK
 
What's this ?

Code:
"RXDB".RESPONSE

I used the RET string variable and it works for me if the set is present or not. POST THE PROJECT WITH THE BUG PRESENT (Create a project with no h/w config - just a S7 program, it will zip to a tiny file)

 
Last edited:
RXDB.RESPONSE is just a DB with a String Variable at DBB0 [32] chars long


The MID Function seem to work in the PLCSIM but not in the real CPU. This has happend to me before but then it the TOF or TON SFB that was not working properly, and for which they released a hotfix.

You must test this in a real CPU, And without HW Config you could just do as follows.

Create OB1 Which calls FB100 With no parameters
FB100 only contains the MID function in network 1
Declare a STAT:MYSTR STRING[17] = 'This is my string' in FB100
Also declare STAT:RESPONS STRING[5] ='' (or temp)

Apply those variables on the mid function so
RESPONS = MID(MYSTR,6,5)

Download and monitor FB100, the MID function is not doing anything
unless you insert a network before NW1 that do a SET.

I will send the project later, i'm out in the field for now.

Best Regards
//Pethoek
 
Ok i will try this with another S7-300 cpu, i'll se what's on the shelf.. I'll get back with the result as soon as i tested it.
 
I tested with a S7 315-2 PN/DP And it worked fine.

Tested again with a clean IM151-8 PN/DB And it also worked fine. Will do some more testing, but at the moment it seems that something in the code generate the error.

I'll get back.
 
The Project

Here is the complete project, hope you can find what is causing the problem with the mid function.

/Pethoek
 

Similar Topics

I am looking for some expert advice. I have always made function blocks both with inputs and outputs and without inputs or outputs. I make the...
Replies
21
Views
6,750
Hi, For Mitsubishi's GX IEC Developer, can anyone tell me the difference between function blocks TEST_K_MD, TEST_MD, TEST_P_MD and TEST_K_P_MD...
Replies
0
Views
2,944
I am trying to deal with fragmented data, and have been getting stuck. So far I am able to command the Fuchs VE Software version correctly and I...
Replies
0
Views
163
Hi all, I am getting back to using IEC for schematics and was wondering about the 81346-2:2019 codes. What does everyone use for a diffuse...
Replies
3
Views
558
I just took a skim through 81346-2:2019 and was wondering which codes you all used for Safety devices like Safety Controllers, EStops, and guard...
Replies
0
Views
556
Back
Top Bottom