Sign in to follow this  
Followers 0

From DINT to Struct (DUT)

3 posts in this topic

Hi does anyone have an idea how to convert a DINT to a Struct containing 32 bits?

Today i convert the DINT to an Array of 32 bits then i move each bit in the array to the struct like this.

I don't like the way to do this therefore my question.

hStatusArr[0]:=DINT_TO_BITARR(iInputStatus,32); (* Load status into array *)

oStatus.bit0:= hStatusArr[0];
oStatus.bit1:= hStatusArr[1];
oStatus.bit2:= hStatusArr[2];
oStatus.bit3:= hStatusArr[3];
oStatus.bit4:= hStatusArr[4];
oStatus.bit5:= hStatusArr[5];
oStatus.bit6:= hStatusArr[6];
oStatus.bit7:= hStatusArr[7];
oStatus.bit8:= hStatusArr[8];
oStatus.bit9:= hStatusArr[9];
oStatus.bit10:= hStatusArr[10];
oStatus.bit11:= hStatusArr[11];
oStatus.bit12:= hStatusArr[12];
oStatus.bit13:= hStatusArr[13];
oStatus.bit14:= hStatusArr[14];
oStatus.bit15:= hStatusArr[15];
oStatus.bit16:= hStatusArr[16];
oStatus.bit17:= hStatusArr[17];
oStatus.bit18:= hStatusArr[18];
oStatus.bit19:= hStatusArr[19];
oStatus.bit20:= hStatusArr[20];
oStatus.bit21:= hStatusArr[21];
oStatus.bit22:= hStatusArr[22];
oStatus.bit23:= hStatusArr[23];
oStatus.bit24:= hStatusArr[24];
oStatus.bit25:= hStatusArr[25];
oStatus.bit26:= hStatusArr[26];
oStatus.bit27:= hStatusArr[27];
oStatus.bit28:= hStatusArr[28];
oStatus.bit29:= hStatusArr[29];
oStatus.bit30:= hStatusArr[30];
oStatus.bit31:= hStatusArr[31];


Share this post

Link to post
Share on other sites


This is no good looking solution but it works.


And you must assign your struct to M0..M31

Share this post

Link to post
Share on other sites

Hi GreenMan

Thanks for the example.

No it seems that ist not any good solutions for that.

I cant assign the struct to a global variable. I use it in a FB, that I need to reuse several times.


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
Followers 0