Skip to content

PLCNext Engineer showing incorrect byte sizes

edited March 2021 in PLCnext Engineer
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]

Comments

  • Hi Mark,
    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:
    ... depending on the composition of the STRUCT, the SIZEOF function may deliver a bigger value than you would get when simply adding the sizes of the contained elements.
    ... 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.
  • Thank you, Martin. So, with that being the case, I can assume that BOOL's in the struct are treated correctly, i.e. the byte in that specific memory location where the BYTE is being 'sent' would be broken down into the individual BOOL bits? The only reason I am questioning this, is I was viewing some data that looked correct in the Profinet buffer I had created, but it didn't seem to be getting associated correctly into the BOOL area of my struct (talking specifically about I/O status from the UR robot) after the MEMORY_COPY. I will double check on Monday to make sure I am not doing something incorrectly.

    Thanks,
    Mark
  • I can assume that BOOL's in the struct are treated correctly, i.e. the byte in that specific memory location where the BYTE is being 'sent' would be broken down into the individual BOOL bits?
    No, that's not correct.
    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 does this mean I can't have any BOOL in my custom struct? Will I have to use a byte variable to get the byte (containing the desired BOOL's) from the raw data copied in, then further break it into separate BOOL variables, outside of my struct?
  • Since a single BOOL will always occupy a minimum of 1 byte in a struct, you're correct - you cannot use MEMORY_COPY to copy bits to the BOOL fields in a struct.
    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.
Sign In or Register to comment.