How to use Data Mask to extract Health Bit from individual devices with BMXNOE0100
There is a built in health bit in NOE module. Below FAQ give you the detail:
FAQ: What is the I/O scanning health bit address for a M340 NOE module
https://www.se.com/au/en/faqs/FA240970/
However the health bit is a INT variable, it is necessary to code a data mask to pick out those bits variable from Int variable.
The health variable (IW0.1.0.1) is a Int type, it contains the health bit information from device 1-15. Below table shows the relationship in between Decimal value and a Binary value.
Decimal Binary Bits
1 0001 bit 0
2 0010 bit 1
3 0100 bit 2
4 0011 bit 0 + bit 1
So if you get your health variable = 1 in Int, you know your binary is 0001, which means your 1st device is healthy. if you get your health variable = 2, you know your binary is 0010, which means your 2nd device is healthy. If you get health variable = 4, you know your binary is 0011, which means your 1st and 2nd device is healthy.
To extract those bit information out of a INT in your logic, you usually need to code a data mask. A data mask is a number used to pick out (test) specific bits inside a WORD / INT / BYTE. Below is a simple example in ST.
Device_1 := (Health_Variable_INT AND 1) <> 0; // bit 0
Device_2 := ((Health_Variable_INT AND 2) <> 0; // bit 1
Device_3 := ((Health_Variable_INT AND 4) <> 0; // bit 2