Reading bits from 32-bit variable

A forum devoted to the discussion of all topics having to do with scripting and other advanced programming using iX Developer.
Post Reply
smolenak
Posts: 22
Joined: Tue Nov 20, 2012 3:06 am

Reading bits from 32-bit variable

Post by smolenak »

Hi,

is there any way to read bit status from 32-bit controller variable. I have OPC server where I have 32-bit variable, and I tried to make bit array (for tag datatype), but it was followed by error while creating a tag ("Array in not supported for this controller). I would want to show single bits status on the screen.

Thanks in advance!

mark.monroe
Posts: 824
Joined: Tue Mar 13, 2012 9:53 am

Re: Reading bits from 32-bit variable

Post by mark.monroe »

The OPC iX Controller copies the entire register that the tag is associated with. You can only associate a OPC register with a single tag. Which means that you would associate a UINT 32 iX tag with a register on your OPC server. You would handle parsing the bits on the iX Developer side.

You could use the tag's ValueChange event to parse the bits and assign them to 32 other tags. iX Developer does not allow you to use arrays anywhere but in the Chart object and in Script. Therefore if you want to display a bit's value it has to be in a tag, or you have to use an expression to parse the value and return just the single bit.
Best Regards,
Mark Monroe

Beijer Electronics, Inc. | Applications Engineer

smolenak
Posts: 22
Joined: Tue Nov 20, 2012 3:06 am

Re: Reading bits from 32-bit variable

Post by smolenak »

OK, thank you for the support!

Would there be examples (links etc.) somewhere how to do this parsing operation in correct way..?

Thanks!

mark.monroe
Posts: 824
Joined: Tue Mar 13, 2012 9:53 am

Re: Reading bits from 32-bit variable

Post by mark.monroe »

No, we do not have any examples. Standard bit wise functions are available and there is a lot of help online regarding how to deal with bits and masking using bit wise functions.
Best Regards,
Mark Monroe

Beijer Electronics, Inc. | Applications Engineer

selcukmola
Posts: 4
Joined: Mon May 11, 2015 7:11 am

Re: Reading bits from 32-bit variable

Post by selcukmola »

mark.monroe
Post subject: Re: Reading bits from 32-bit variable Reply with quote
No, we do not have any examples. Standard bit wise functions are available and there is a lot of help online regarding how to deal with bits and masking using bit wise functions.

would you mind to give us an example of reading each bits of the 32bit variable, because I havent found these a lot of help online!

liestol
Posts: 13
Joined: Thu Feb 11, 2016 5:11 am

Re: Reading bits from 32-bit variable

Post by liestol »

Hi,

Try doing something like this;

Code: Select all

using System.Linq;


int your32BitInt = 12345; //replace 12345 with your value, ex. Globals.Tags.xxx.Value;
		
string intConvert = Convert.ToString(your32BitInt, 2); //convert to binary in string

int[] individualBits = intConvert.PadLeft(32, '0') //add missing 0's from left
.Select(x => int.Parse(x.ToString())) //separate each individual char to int
.ToArray(); //convert to array
You can now access individual bits using their position in the array individualBits[]. Ex. individualBits[0] will give you the first position and so on.

LenDamedy
Posts: 5
Joined: Sun Aug 25, 2019 6:53 am
Location: Canada
Contact:

Reading bits from 32 bit variable

Post by LenDamedy »

Im trying to open a new screen using LUA but I cant get it to work. Ive tried using the gre.send_event"change_screen" example above but it doesnt work. Im using 5.0.

Is this the only way to change the screen using LUA or am I missing something?

Thanks.

Post Reply