Help needed with structured text

chrisk_81

Member
Join Date
Mar 2011
Location
Adelaide
Posts
58
Hi all,

I'm trying to assign the individual characters from a STRING data type to an array of BYTE's as below:

text : STRING(5) := 'hello';
char : ARRAY[0..4] OF BYTE;

Does anyone know how to get this to work? I thought this below would work but it doesn't:

char[0] := text[0];
char[1] := text[1];
char[2] := text[2];
char[3] := text[3];
char[4] := text[4];
 
Last edited:
to get a better answer please tell up what PLC you are using

eg RSLogix 5000 does not have Byte data type
The STRING data type that is a system defined data type containing .LEN DINT and .DATA SINT[82] where the SINT is the contains the individual characters you are wanting to manipulate
 
The software I'm using is cp1131 and is used to program Berghof cpu's.

I've tried accessing the characters via text.DATA[n] but cp1131 doesn't like it.

Would love to know if anyone out there has an idea on how this data might be accessed.
 
Last edited:
It uses Codesys 2? If so you can download oscat basic library from oscat.de and use CODE to extract chars from string.

Code:
FOR Index := 1 TO 100 DO
    Chars[i] := CODE(STR := STR, POS := i);
END_FOR;
 
Code:
VAR
 text : STRING[5]:='hello';
 char : ARRAY[0..4] OF BYTE;
 PT : POINTER TO BYTE;
 i : INT;
END_VAR
 
-------------------------------------------
 
pt:=ADR(text);
FOR i:=0 TO 4 DO
 char[i]:=pt^;
 pt:=pt+1;
END_FOR
 
Thanks everyone for their input but Archie you are the man! That solution worked beautifully and also taught me a few things I didn't know. Thanks again for your help.
 

Similar Topics

I have an old PLC (circa 2007) consisting of Telemecanique/Modicon/Schneider Electric devices. The system has developed errors and unfortunately...
Replies
2
Views
294
Hi I’m after some help , I have a plc program with a baumer verisens vision camera attached I have got the signals working ect but I have an...
Replies
9
Views
980
Hi all, We are facing synching issues with redundancy module, where the Primary is ending up with disqualified secondary. Normally this would...
Replies
2
Views
656
Hi all, I have got this machine that needs to be up and running soon. This machine has Schneider's Controller and I/O modules, 3 vfd's, 2...
Replies
2
Views
928
Is it possible to write to the high speed counter function file "high speed preset" on an AB micro 1100. I have the HSC set up with a MOV...
Replies
3
Views
1,106
Back
Top Bottom