Struct to Byte

emilg

Level-1
Beiträge
52
Reaktionspunkte
1
Zuviel Werbung?
-> Hier kostenlos registrieren
Hello

I have a struct fx:
TYPE
stTest :
STRUCT
BoolTest : bool;
ByteTest : byte;
IntTest : int;

END_STRUCT;
END_TYPE

I want to trasfer it over Profinet IO (ILC131) to a Siemens Master.
I Found the function MEMCPY, and in the Help file it says; "For this type of data management it is recommended to use the data types STRUCT and ARRAY"
But i can't connect the stTest Struct to the FB?

I'm a little lost now...


- Emil
 
Did you have your struct-Definition assigned to the FB ... or a Variable which has the Type of the struct-Definition ?
Perhaps you should show us the code which contains the FB-call ...
 
Zuviel Werbung?
-> Hier kostenlos registrieren
Hello
I have connected the struct to a variable. "Teststruct"
I found that Pack/unpack can do the job. But it uses the first 8 bytes for a check sum i think. The FB Helpfile don't contain any information about that.
Right now i'm just testing with a new empty program, so i don't mess up my working program.
struct_to_byte.jpg
 
I'm not familiar with the Phoenix-PLC - but I think that you have a generell understanding problem.
For the connection to the Siemens-PLC you need to have a configured memory-area on both sides (Siemens and also Phoenix). Now you can use this memory-area directly or you could assign your variable "TestStruct" to the memory-area. In this case MemCopy could be the solution. When I see your datatable I can't imagine that Pack is the right approach ...
 
Hello

It works like i want it to... if i just skip the first 8 bytes... ;)
The biggest problem is that the function has a R_Trig input, but if i use a clock pulse on it, i think it can work as it should anyway.
On my Siemens S7-1200 (Master), i connect to the Phoenix ILC131 (Device) over Profinet.
Then i just read the bytes in the Siemens Controller.
siemens tags.png
In this Example from the Siemens, it's not the Teststruct i'm reading out.
I know i can use special Siemens ISO communication library, but i want it to be directly on profinet, so it's easy to use on other vendor PLC's alsow.
 
Hey Emil,

you could also try using the Buf_To_Byte FB.

If you want to use the MemCopy FB you would have to change your structure that the first member contains the number of bytes you want to copy.

In either case you would have to watch out for padding bytes.

Mark
 
Zuletzt bearbeitet:
Hey Mark

Buf_To_Byte worked better. (Without checksum)
But i dont see any change in the byte order if i True Buf_format?
See my test here:
buf.jpg
I use a ILC191ME/AN
 
Zurück
Oben