SCL String Handling question.. STEP7

bara_hence

Member
Join Date
Aug 2007
Location
Ockelbo
Posts
225
I have this code:

Code:
FUNCTION_BLOCK FB100

VAR_INPUT
    DennaForm : INT;
    DettaRecept : STRING[20];
    FormTakt : BOOL;
END_VAR

VAR
    SenasteForm : INT;
    SenasteRecept : STRING[20];
    NyForm : BOOL;
    NyRcpt : BOOL;
END_VAR

VAR_OUTPUT
    NyFormRcpt : BOOL;
END_VAR

 BEGIN
 
 IF (Formtakt=1) AND (DennaForm<>0)AND(DennaForm<>SenasteForm) 
 THEN NyForm:=1;
ELSE NyForm:=0;
END_IF;
 IF (Formtakt=1) AND (DettaRecept<>'') AND (DettaRecept<>SenasteRecept)
 THEN NyRcpt:=1;
ELSE NyRcpt:=0;
END_IF;
IF (NyRcpt=1) OR (NyForm=1)
THEN NyFormRcpt:=1;
ELSE NyFormRcpt:=0;
    END_IF;

 SenasteRecept := DettaRecept;
 SenasteForm := DennaForm;
 
 END_FUNCTION_BLOCK

The trouble is when assigning the string variable if for example dettarecept holds in byte 1 20(The lenght) and in byte 2 97 (the character a) the other string holds 20 in its first two bytes.. So something must be wrong but what??
 
Ive made a VAT where I declared the variables from the instance data block.

In the instance data block i can se for an example that the string named DettaRecept starts at Byte2

First i declared every byte as an character but when that didnt work i declared them as DEC and testing gave this results:

Byte 2 holds the lenght (20)
Byte 3 is the one I am testing with From 0-20 the corresponding byte in the variable DettaRecept follows but over 20 it stays there..

The same goes for every byte 0-20 the corresponding byte follows over 20 the corresponding byte halts...
 
I've taken your FB and simplified it:

Code:
FUNCTION_BLOCK FB100
VAR_INPUT
    DennaForm : INT;
    DettaRecept : STRING[20];
    FormTakt : BOOL;
END_VAR
VAR
    SenasteForm : INT;
    SenasteRecept : STRING[20];
    NyForm : BOOL;
    NyRcpt : BOOL;
END_VAR
VAR_OUTPUT
    NyFormRcpt : BOOL;
END_VAR
 BEGIN
 
 SenasteRecept := DettaRecept;
 END_FUNCTION_BLOCK


Here's the results from the VAT table. Are you sure your input string is valid ?

berty009.jpg
 
Aah lights up I see what the trouble was...
I only played around with one character and all the others where empty there was an error but when i have a character in every byte the copy works..

The only trouble I see is the String DettaRecept comes from the RFID system and What if the string only is lets say 5characters does the other 15bytes get filled with : ' '

If they dont my block doesnt work..

So I better hope this is the case..


I really must thank you so much helping...
 
Last edited:

Similar Topics

I feel like I'm going crazy, new to Siemens, coming from AB, and I cannot get a dang string copied in SCL. This is a S7-300, V16 PLC. I have a...
Replies
10
Views
3,495
I am trying to take several individual CHAR bytes and turn them into a string. The CHAR bytes are located in a DB. I am trying to figure out the...
Replies
4
Views
3,499
Hello everyone, I have a question. I'm using SCL code to create a function block. With that function block I want to get from a DB 3 strings...
Replies
10
Views
3,150
Hi I am playing around with SCL & Strings, what is the problem with the string assignment VAR_TEMP MyString : STRING[20] ; END_VAR MyString...
Replies
5
Views
3,056
Hello all, my task is to send an array of ASCII codes through VIPA CP341. The device which I want to connect uses its own framing like this...
Replies
5
Views
8,111
Back
Top Bottom