Hi all,
Straight up question: I'm using TIA Portal and an S7-1200, and wanting to do a straight bitwise copy of all the data in a Word to put it into a Struct (which consists of a byte and 8 bools). Is there a way to do this? I've tried all the instructions that I can think of, but they all give me data type mismatches.
Context (in case there's a better way to approach what I'm doing): I'm getting a 16-bit integer coming in from a Modbus TCP device, and this particular status word contains:
- Bit 0-7: Value 1
- Bit 8-12: Value 2
- Bits 13, 14 and 15: status bits
I can bring it straight into a Struct tag of one byte and 8 bools, but then I have no easy way of re-assembling the value from Bits 8-12 back into a meaningful value. So I decided to bring it into an Int. Then I can use AND's and bit shift instructions to extract Value 1 and Value 2, and all I have to do then is extract the Bool's.
I can think of two ways to do this:
1. Address the bit within the Int: e.g. just use %DB331.DBX2.13 to turn on a coil. That coil becomes my bool. This works, but gives me IEC warnings
2. Move the Int into an M word (e.g. MW100) and then address (e.g.) M100.5 to get my Bool. Which also works
And while they both work, I'm thinking it would still be much simpler if I could just do a straight copy. Is it possible, or should I just pick one of my two options above and move on?
Thanks!
Straight up question: I'm using TIA Portal and an S7-1200, and wanting to do a straight bitwise copy of all the data in a Word to put it into a Struct (which consists of a byte and 8 bools). Is there a way to do this? I've tried all the instructions that I can think of, but they all give me data type mismatches.
Context (in case there's a better way to approach what I'm doing): I'm getting a 16-bit integer coming in from a Modbus TCP device, and this particular status word contains:
- Bit 0-7: Value 1
- Bit 8-12: Value 2
- Bits 13, 14 and 15: status bits
I can bring it straight into a Struct tag of one byte and 8 bools, but then I have no easy way of re-assembling the value from Bits 8-12 back into a meaningful value. So I decided to bring it into an Int. Then I can use AND's and bit shift instructions to extract Value 1 and Value 2, and all I have to do then is extract the Bool's.
I can think of two ways to do this:
1. Address the bit within the Int: e.g. just use %DB331.DBX2.13 to turn on a coil. That coil becomes my bool. This works, but gives me IEC warnings
2. Move the Int into an M word (e.g. MW100) and then address (e.g.) M100.5 to get my Bool. Which also works
And while they both work, I'm thinking it would still be much simpler if I could just do a straight copy. Is it possible, or should I just pick one of my two options above and move on?
Thanks!