CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum by 3S-Smart Software Solutions GmbH | A member of the CODESYS Group
Deutsche Version English version russian version 
It is currently Sat Jan 25, 2020 4:05 am

All times are UTC+01:00

Post new topic  Reply to topic  [ 5 posts ] 
Author Message
 Post subject: mapping array or string
PostPosted: Fri Sep 09, 2016 12:14 am 

Joined: Tue Aug 09, 2016 10:24 pm
Posts: 1
Newbie to all of this. Working with Microscan ID-40 using EtherNet/IP to CodeSys Control Win.

The ID-40 is a barcode scanner and puts the ascii barcode string into 64 bytes in the T->O stream.

The provided EDS file (connection) defines symbol_str64 at %IB20 as BYTE of length 512 bits. I cannot figure out how to map this to an array of bytes in ST or CodeSys Editors. Whatever I do populates only the first byte in the array, the remainder are left as zero bytes.

If I create a generic connection of pure bytes, I can map (by hand) location 20 to array[1], location 21 to array[2],...

At that point I can convert the array of bytes to a string in ST, and do a %s visualization of the string. Works great, but tedious.

I poked around the forum a bit and found the 'AT' option, so I tried:
code : AT %IB20 : ARRAY[1..64] OF BYTE;
but that did not do what I wished for. Still only the first byte is transferred.

I saw some posts referring to ARRAY of BYTE definitions in assemblies, but I cannot figure out how to add such a Data Type to a generic input assembly.

Is there a way to do this sort of mapping?

PostPosted: Fri Sep 09, 2016 1:14 pm 

Joined: Wed Jan 20, 2016 4:24 pm
Posts: 1
Edit: well it wasn't actually the same as you were talking about. I read your post hastily. But as of copying bytes, I'm wondering the same thing. I guess the only thing is to do a FOR that copies the bytes one by one.

Funny that I have just figured a way to do this and logged in here to ask if there's any better way.

My current solution is to define a pointer to an array of bytes and then ask for the address of the string and assign it to the pointer. Then you can access the content of the pointer to get to the array of bytes. Seems to work, but I suspect there might be something more to this and this might not be the safest way to do this.

Anyway, declarations:
text :STRING(20);
pointer_to_text :POINTER TO ARRAY[1..20] OF BYTE;

pointer_to_text := ADR(text);
and then you can access
byte_at_i := pointer_to_text^[i];

Seems to work, but I'd like any comments or suggestions on how to do this better.

PostPosted: Sat Sep 10, 2016 9:57 pm 
Frequent User
Frequent User

Joined: Thu Jun 14, 2007 9:49 am
Posts: 987
get yourself the library of, it handles with this type of copy.

you can not structure input bytes/words, same for any type of hardware bytes, however you can point to a structure.

computer shooter
paul deelen
jacob van wassenaerstraat 29
NL 5224 GG 's-Hertogenbosch
skype shooter paul.deelen
phone +31736139136

PostPosted: Sun May 28, 2017 6:52 am 

Joined: Mon May 15, 2017 6:47 am
Posts: 58

Are you able to figure out this issue? I'm running into the same issue as well with EthernNet/IP devices since you can't create a structure or arrays of data.

PostPosted: Tue May 30, 2017 6:15 am 

Joined: Mon May 15, 2017 6:47 am
Posts: 58

In case you're still looking, another post had the answer (viewtopic.php?f=11&t=7861). Change your code to:

code AT %IB20 : ARRAY[1..64] OF BYTE;

Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 5 posts ] 

All times are UTC+01:00

Who is online

Users browsing this forum: No registered users and 3 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited