Problem with Siemens SLC Code

dimmarkov

Member
Join Date
Jan 2009
Location
Sofia
Posts
33
Hello All,
I Have the following problem with Siemens SCL code View attachment FB2012.pdf.
This code should do:
It transform a DINT to String but also it made the string with constant lenght:
IF DINT=1 then String='00000000000000000001'
IF DINT=123 then String='00000000000000000123'
and so on.
The problem is that DI_STRNG(Siemens library function) should work in that way:
IF DINT=1 then String='+1'
IF DINT=123 then String='+123'
But its not work in that way in SCL.
I wrote another SCL Code View attachment FB2011.pdf When I Call DI_STRNG in STL/LAD/FBD and after that the second FB there is no problem.
I use PLCSIM 5.4 SP3 AND SCL 5.3 SP5.
If You see some error in my code please tell me.
The code is not optimized for best performance and it's not writen in FC because of that problem

Regards Mitko
 
It is not clear to me what it is that you want and what the problem is.
Do you want the DINT=1 to be the STRING='00000000000000000001', or the STRING='+1' ?

I can see a few differences between the two FBs, but I have no idea why they are there.

I think you have to write exactly what you want first.
And then what the problem is.
 
Since a DINT can also be negative, where in your string do you intend to place the sign? Since any DINT can be represented with one sign and no more than 10 digits, why do you want to use 20 characters in your string?

Kind regards,
 
Thanks for the quick reply
I use that program to generate a barcode. its ONLY for test.
So I don't need a sign and I need a 20 digital barcode.
I know that DINT has only 10 digits.
The problem is that In first SCL code function DI_STRNG NOT return a correct value from DINT.
I use a lot of scl code and This bother me, becouse I'm not sure in the SCL compiler any more

Regards
Mitko.
 
I think you have to use: dint_to_string, concat and delete, i think there was also function to check for string lenght, as you have to check how long was that string that came from dint_to_string, then delete the + and add enough zeros. Look at manual SCL_e, can be found on siemens website.
 
The problem is that In first SCL code function DI_STRNG NOT return a correct value from DINT.

What have you done to establish this ?

I took your code and commented out the code after the call to DI_STRING, then ran it in plcsim (I used 123 as the input parameter) and then used a VAT table to check the result produced by DI_STRING - the correct values are located in memory.

di009008.JPG
 
Last edited:
If I run the code as you posted, you can see from the VAT table that your code is modifying the max string length.

di009009.JPG
 
Here's your original block with corrections:

Code:
FUNCTION_BLOCK FB2012
VAR_INPUT
 DInteger: DINT;
 END_VAR
VAR_IN_OUT
 END_VAR
VAR_OUTPUT
 Barcod: STRING[20];
 END_VAR

 VAR
 Barcod_TMP1: STRING[20];
 BC_Char1 AT Barcod_TMP1 : ARRAY[1..22] OF CHAR;
 BC_Byte1 AT Barcod_TMP1 : ARRAY[1..22] OF BYTE;
 Barcod_TMP2: STRING[20];
 BC_Char2 AT Barcod_TMP2 : ARRAY[1..22] OF CHAR;
 BC_Byte2 AT Barcod_TMP2 : ARRAY[1..22] OF Byte;
 Lenght: INT;
 Start_Adr_Str1: INT;
 Start_Adr_Str2: INT;
 Cnt: INT;
 END_VAR

 BEGIN
 Barcod_TMP1:='00000000000000000000';
 Barcod_TMP2:=DI_STRNG(I := DInteger // IN: DINT
 ); // STRING
 Lenght:=LEN(S :=Barcod_TMP2) - 1; // reduce length by 1 as the sign is not required 
 Start_Adr_Str2:=4; //[1]=max len [2]=actual len [3]=sign [4]=first char required
 Start_Adr_Str1:= 22 - (Lenght - 1); //if 1 char to copy, then destination will be [22]
 FOR Cnt := 0 TO Lenght-1 BY 1 DO
 BC_Char1[Start_Adr_Str1 + Cnt]:=BC_Char2[Start_Adr_Str2 + Cnt];
 END_FOR;
 Barcod:=Barcod_TMP1;
 END_FUNCTION_BLOCK
 

Similar Topics

Ciao guys, I'm not used to program on Siemens PLCs, but sometimes I have to. I'm experiencing a strange problem when I try to connect to a PLC...
Replies
9
Views
3,863
Hi, Im working on adding multilanguage to my project. When using a button to change language I get "invalid value 0 in parameter xxx". The zero...
Replies
0
Views
1,023
Good morning Please i need an advise, I have a s5 135u cpu system , it is installed on printing machine. Nowadays its stop about 10 times in 8...
Replies
27
Views
4,251
Hello, I have connected ethernet cable with my laptop and the s120 control unit. setup my laptop ip 169.254.11.1 and subnet mast 255.255.0.0 ...
Replies
20
Views
5,557
Hi all, I'm hardly a Siemens expert, and am struggling with a conversion I'm working on right now. A system was purchased at auction, and I'm...
Replies
1
Views
1,850
Back
Top Bottom