Codesys copying structures to arrays

osogood2323

Member
Join Date
Apr 2013
Location
Michigan
Posts
10
Hello,
Is it possible to copy an array of 100 bytes into a structure that is the equal? Could go through and pick all the points. New to structured text for about a month. Reading and writing to a gateway 100 in and out. An example
TYPE DataSTRUCT :
STRUCT
DINT : ARRAY[0..3] OF DINT;
INT : ARRAY[0..3] OF INT;
BOOL : ARRAY[0..15] OF BOOL;
END_STRUCT
END_TYPE

Input address array:
%IB0 array [0..15] of SINT


Thank you
 
Last edited:
Found it, so I can see the array and counts, would I leave the Structure its name at a length of 100?
SYSMEMCPY30(ADR(Struct) , ADR(Array[0]), 100);
 
I'd use something like this:

SYSMEMCPY30(ADR(Struct) , ADR(Array[0]), SIZEOF(Array));

I'm not familiar with SysMemCpy30 (where does the 30 come from?) and I don't remember if the 1st parameter is source or destination. The most important thing to look out for is to insure that you don't overwrite something outside of your destination variable. You mentioned that they're both the same size so that shouldn't be a problem . If they're not you just have to make sure not to overwrite as I mentioned.

Good Luck,

Yosi
 
You will have to convert it by yourself, as there is no function to do this,
However you can use a pointer and calculate the length of the structure and with these you can copy them use Marker memory.
So put the structure somewhere in markers and then you can take a array out of this.
 
OK, You've got to add the library SysLibMem.Lib.

The function SysMemCpy has the following 3 paramters.
dwDest: DWORD; (* New buffer *)
dwSrc: DWORD; (* Buffer to copy from *)
dwCount: DWORD; (* Number of characters to copy*)

So if you want to copy a structure (Src) to a byte array (Dest) you'd do it as follows:

SysMemCpy(ADR(Dest), ADR(Src), Sizeof(Src));

IMPORTANT! Dest has to be at least as large as Src otherwise you risk overwritting other data.

Hope this helps.

Yosi
 
Oh, and regarding OSCAT, it's just a great tool to have on hand. It doesn't have all of the solutions just a remarkable number of them.
 

Similar Topics

Hello to all, I'm just starting with using CodeSys. Immediately, I have noticed that Codesys doesn't use data blocks like for example S7 does...
Replies
11
Views
167
Hello, I am using a Hitachi Micro EHV+ for a small project, and I wanted to have a Web visu, done with Codesys V3.5 SP13 Patch 2. I test the...
Replies
7
Views
358
Hello, I have a requirement to manage the text alignment dynamically. So, for example: 1. English Texts should be displayed from Left in...
Replies
0
Views
102
Hello, I am new to Codesys, and am trying to learn about it for a project we're developing. I've got a couple questions, but first a little...
Replies
1
Views
171
Hi everyone, as this is my first experience with Rockwell Software i would like to know what's the best way to make Enumerations?
Replies
10
Views
527
Back
Top Bottom