Common Practices: Control/Status Words
Table of Contents
Introduction
Many devices have control and status words. A common practice is to intercept or set the bits by masking: controlWord := (controlWord OR MASK_ACK_ERRORS);
or isErrorPending := (statusWord AND MASK_ERROR_IS_PENDING);
.
This method of working with the bits works quite well, but is complicated and difficult to read. Especially if you look at the raw data of e.g. controlWord.
Therefore, it is mandatory that we use unions for this.
Example
For the example, I take a Siemens G120 frequency converter (shame on me, I use a Siemens device, I know), I only list the control word because with that, it should be clear how it works.
First, we create a data structure for the individual bits. Here it is important that the data type BIT
is used because with BOOL
it does not work.
Next we create the union, in my GSDML file for the Siemens G120 is the control word an UINT
.
The Siemens G120 class, I know there is an interface, but it’s just an empty interface and an empty class to show it.
Main
IO Mapping
Set a few bits online for fun
Summary
It would also work if only our bit data structure is mapped, but only if the matching type is omitted from the mapping. Then you don't have the possibility for word operation like an off method THIS^.AO_CtrlWord.rawData := 0;
.