I am trying to cleanup some variable mapping. I have an I/O device that has its points defined as BIT. I would like to map these into an array of something but I cannot use an array of BIT. Mapping to an array allows me to access bits through a common FB so I only need to map the points once.
I have created a Union based on a Forum response (https://forge.codesys.com/forge/talk/Engineering/thread/9613d49992/) and it seems to do what I would like. However, when I map the bits to my device, I get a C0355 warning (A single bit cannot be referenced. A reference to the complete byte will be stored.).
What does this warning mean and is there a better way to map this?
Thank you @i-campbell. Using testBools[x] in the mapping does work.
I am trying to pass these points along to a client over a network and I would like to just send a bunch of Bytes (without manually converting them). The BOOL type does not map nicely to Bytes.
I would like to do something like:
InputBytes:ARRAY[0..9]OFBYTE;
and then use 'InputBytes[0].2' in the mapping. However, this will not even compile.
Using an array of BOOL makes the network sending messy.
The benefit of the Union is that the value of the 8 BITS is exposed in through the BYTE object (aByte in the example). If I use BOOL in the Output_Byte structure, this relationship breaks.
I will look at it more with your suggestion in mind and see if I am approaching this wrong.
Thank you again.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
As you have 4 distinct parameters, it will not be possible to map them to a BIT variable from the mapping dialog.
You could try
testBytes AT %QB200 : Output_Union;
OR
testBytes AT %QB400 : Output_Union;
Depending on which addressing mode your PLC uses.
You could also use Util.Pack() / Util.Unpack() somewhere in your code
Last edit: i-campbell 2021-02-23
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I am trying to cleanup some variable mapping. I have an I/O device that has its points defined as BIT. I would like to map these into an array of something but I cannot use an array of BIT. Mapping to an array allows me to access bits through a common FB so I only need to map the points once.
I have created a Union based on a Forum response (https://forge.codesys.com/forge/talk/Engineering/thread/9613d49992/) and it seems to do what I would like. However, when I map the bits to my device, I get a C0355 warning (A single bit cannot be referenced. A reference to the complete byte will be stored.).
What does this warning mean and is there a better way to map this?
Thank you
My code:
Usage in Global:
Usage in my device map:
Last edit: mike-at-gms 2021-02-23
Try
testBools : ARRAY [0..9] OF BOOL;
Thank you @i-campbell. Using testBools[x] in the mapping does work.
I am trying to pass these points along to a client over a network and I would like to just send a bunch of Bytes (without manually converting them). The BOOL type does not map nicely to Bytes.
I would like to do something like:
and then use 'InputBytes[0].2' in the mapping. However, this will not even compile.
Using an array of BOOL makes the network sending messy.
The benefit of the Union is that the value of the 8 BITS is exposed in through the BYTE object (aByte in the example). If I use BOOL in the Output_Byte structure, this relationship breaks.
I will look at it more with your suggestion in mind and see if I am approaching this wrong.
Thank you again.
As you have 4 distinct parameters, it will not be possible to map them to a BIT variable from the mapping dialog.
You could try
testBytes AT %QB200 : Output_Union;
OR
testBytes AT %QB400 : Output_Union;
Depending on which addressing mode your PLC uses.
You could also use Util.Pack() / Util.Unpack() somewhere in your code
Last edit: i-campbell 2021-02-23