PLCNext Engineer showing incorrect byte sizes
Hello,
I have created/modified some custom structs in order to copy Profinet data and make it more legible. I am working with a UR10e. One of the structs I have created has a combination of USINT, UINT, BOOL and Real. The struct itself has 32 bytes, however, the statistics screen is report it as 56 bytes. I am wondering if this is causing some of the weird data I am seeing, as some data looks correct (at the start of the packet) but once it gets further, it seems to cause issues.
[code type="markup"]
TYPE
UR_1_T2O_State:STRUCT
Robot : UR_T2O_Robot;
Safety : UR_T2O_Safety;
END_STRUCT;
[/code]
[code type="markup"]
TYPE
UR_T2O_Robot:STRUCT
Controller_major_version : USInt;
Controller_minor_version : USInt;
Reserved : UInt;
Robot_mode : USInt;
Real_time_machine_seconds : USInt;
Real_time_machine_milliseconds : UInt;
Real_time_machine_minutes : USInt;
Real_time_machine_hours : USInt;
Real_time_machine_days : UInt;
Robot_current_A : Real;
PW_Is_power_on : Bool;
PR_Is_program_running : Bool;
TB_Is_teach_button_pressed : Bool;
PB_Is_power_button_pressed : Bool;
Reserved_4 : Bool;
Reserved_5 : Bool;
Reserved_6 : Bool;
Reserved_7 : Bool;
Reserved_8_15 : USInt;
Reserved_16_31 : UInt;
Speed_slider_fraction : Real;
END_STRUCT;
END_TYPE
[/code]
[code type="markup"]
TYPE
UR_T2O_Safety:STRUCT
Safety_mode : USInt;
Reserved_1 : USInt;
Reserved_2 : UInt;
NO_Is_normal_mode : Bool;
RD_Is_reduced_mode : Bool;
PS_Is_protective_stopped : Bool;
RC_Is_recovery_mode : Bool;
SS_Is_safeguard_stopped : Bool;
SES_Is_system_emergency_stopped : Bool;
RES_Is_robot_emergency_stopped : Bool;
ES_Is_emergency_stopped : Bool;
VL_Is_violation : Bool;
FT_Is_fault : Bool;
ST_Is_stopped_due_to_safety : Bool;
Reserved_11 : Bool;
Reserved_12 : Bool;
Reserved_13 : Bool;
Reserved_14 : Bool;
Reserved_15 : Bool;
Reserved_16_31 : UInt;
END_STRUCT;
END_TYPE
[/code]
[code type="markup"]
TYPE
myT2Ostate : ARRAY[0..31] of BYTE; // 32 byte array
END_TYPE
[/code]
It almost seems as if PLCNext Engineer is treating each BOOL in the struct as a byte. I have attached pictures of the variable declaration as well as the FB of the memory_copy. Any ideas if this struct could be causing the data issues?
Thanks,
Mark
[attachment]memcopy.png[/attachment][attachment]varDeclare.png[/attachment]
I have created/modified some custom structs in order to copy Profinet data and make it more legible. I am working with a UR10e. One of the structs I have created has a combination of USINT, UINT, BOOL and Real. The struct itself has 32 bytes, however, the statistics screen is report it as 56 bytes. I am wondering if this is causing some of the weird data I am seeing, as some data looks correct (at the start of the packet) but once it gets further, it seems to cause issues.
[code type="markup"]
TYPE
UR_1_T2O_State:STRUCT
Robot : UR_T2O_Robot;
Safety : UR_T2O_Safety;
END_STRUCT;
[/code]
[code type="markup"]
TYPE
UR_T2O_Robot:STRUCT
Controller_major_version : USInt;
Controller_minor_version : USInt;
Reserved : UInt;
Robot_mode : USInt;
Real_time_machine_seconds : USInt;
Real_time_machine_milliseconds : UInt;
Real_time_machine_minutes : USInt;
Real_time_machine_hours : USInt;
Real_time_machine_days : UInt;
Robot_current_A : Real;
PW_Is_power_on : Bool;
PR_Is_program_running : Bool;
TB_Is_teach_button_pressed : Bool;
PB_Is_power_button_pressed : Bool;
Reserved_4 : Bool;
Reserved_5 : Bool;
Reserved_6 : Bool;
Reserved_7 : Bool;
Reserved_8_15 : USInt;
Reserved_16_31 : UInt;
Speed_slider_fraction : Real;
END_STRUCT;
END_TYPE
[/code]
[code type="markup"]
TYPE
UR_T2O_Safety:STRUCT
Safety_mode : USInt;
Reserved_1 : USInt;
Reserved_2 : UInt;
NO_Is_normal_mode : Bool;
RD_Is_reduced_mode : Bool;
PS_Is_protective_stopped : Bool;
RC_Is_recovery_mode : Bool;
SS_Is_safeguard_stopped : Bool;
SES_Is_system_emergency_stopped : Bool;
RES_Is_robot_emergency_stopped : Bool;
ES_Is_emergency_stopped : Bool;
VL_Is_violation : Bool;
FT_Is_fault : Bool;
ST_Is_stopped_due_to_safety : Bool;
Reserved_11 : Bool;
Reserved_12 : Bool;
Reserved_13 : Bool;
Reserved_14 : Bool;
Reserved_15 : Bool;
Reserved_16_31 : UInt;
END_STRUCT;
END_TYPE
[/code]
[code type="markup"]
TYPE
myT2Ostate : ARRAY[0..31] of BYTE; // 32 byte array
END_TYPE
[/code]
It almost seems as if PLCNext Engineer is treating each BOOL in the struct as a byte. I have attached pictures of the variable declaration as well as the FB of the memory_copy. Any ideas if this struct could be causing the data issues?
Thanks,
Mark
[attachment]memcopy.png[/attachment][attachment]varDeclare.png[/attachment]
Comments
I have moved this question to the PLCnext Engineer topic.
Please search the PLCnext Engineer help system for "SIZEOF". The description of this function includes information about how data in STRUCT variables is arranged. It states:
... which is what you are seeing.
If the description in the PLCnext Engineer help does not fully explain your situation, please let us know.
~ Martin.
Thanks,
Mark
I have just tried this myself, and each BOOL in the structure occupies 1 byte. So the MEMORY_COPY will copy one byte from the source array into one BOOL variable in the destination structure.
So, if you want to do the complete data transfer in one operation, then you won't be able to include BOOL fields in the Struct. You could use intermediate BYTE fields in the struct, or else you could transfer the data in multiple chunks, working around the BOOLs, and then set the BOOL fields in the struct separately.