Tia Portal Pro - Word Array to Real Struct?

Hal9000

Member
Join Date
Jun 2010
Location
London
Posts
140
Hi there,

I have an array of 44 words that contain the two parts of a set of real numbers. I want to copy these words over to my Struct which contains the 22 Reals.

I've tried all the obvious Block Move type instruction options in TIA portal but non of them seem to work for me.

Can anyone suggest away to do this?

The image should make things clearer.

Many thanks,

Justin

Word to Real.jpg
 
What are the correct values for some of the REALs, and the corresponding values for the WORDs? Doesn't have to be exact, if the numbers are fluctuating.


Offhand, the REAL values being negative suggests the order of the words and/or of the bytes are reversed. Try swapping every other word before the block move, then try swapping bytes within the words. There are only so many possibilities.
 
Example code to swap the modbus words to give different flooting point results. As already said, what should the data be?

mswap1.jpg
 
@LD and @Lare have it:

Python:

>>> import struct

>>> struct.unpack('>5f',struct.pack('>10H' ,0x4280,0x4fcb ,0x420d,0x6776 ,0x4213,0xa2e8, 0x0000,0x0000, 0xc087,0x80ea))
(64.15584564208984, 35.351036071777344, 36.909088134765625, 0.0, -4.2344865798950195)

>>> [hex(v) for v in struct.unpack('>5I',struct.pack('>10H' ,0x4280,0x4fcb ,0x420d,0x6776 ,0x4213,0xa2e8, 0x0000,0x0000, 0xc087,0x80ea))]
['0x42804fcb', '0x420d6776', '0x4213a2e8', '0x0', '0xc08780ea']


I have no idea where OP is getting the data for their floating point values in [AlgInput], it is almost certainly not from the Words in [InputRegister]

>>> [hex(v) for v in struct.unpack('>4I',struct.pack('>4f',-689.4691,-5573.278,-252997.5,-9999.9))]
['0xc42c5e06', '0xc5ae2a39', '0xc8771160', '0xc61c3f9a']


There may be an issue with how the data are physically laid out in the Struct with the 22 reals. Isn't there an "optimized" option for data blocks?
 
Hi there,

I have an array of 44 words that contain the two parts of a set of real numbers. I want to copy these words over to my Struct which contains the 22 Reals.

I've tried all the obvious Block Move type instruction options in TIA portal but non of them seem to work for me.

Can anyone suggest away to do this?

The image should make things clearer.

Many thanks,

Justin
You should be able to set up a function to do it, I found this coded on another forum and it is similar to how I used to do it on Allen Bradley. I assume these are Modbus registers coming in, only problem might be the big endian / little endian fromat ( BCDA v CBAD)

If those 2 words contain floating point number formatted as IEEE 754, then proceed as follows:

Code:
L FirstModbusWord

T MW20

L SecondModbusWord

T MW22

...

L MD20
 
Hi everyone,

Please ignore the actual data in the reals. It's old data not any data that was copied across. Sorry for confusion.

I basically just need to understand what instruction will allow me to move the data from one data type to another. Being words in an array to Reals in a struct. the start address and count of the array I need to be able to adjust. The destination structs will of course be fixed.

I will have a look at the Siemens link Lare provided,

Many thanks
 
If you have to swap the words, there is no instruction to do this whilst performing a block move or the like. You will have to create in intermediate array as in my example - you can then block move the swapped array to your struct of reals.
 
If you have to swap the words, there is no instruction to do this whilst performing a block move or the like. You will have to create in intermediate array as in my example - you can then block move the swapped array to your struct of reals.


Swap command should work also for P area if data is words or dwords.



Haven't tested how it works if serialize blocks outputs is word area, then swap for entire structure and after that deserialize.


At least it should work if first moving from bytes to words and after that swap.
 
Even though you did not supply the actual values, I am pretty sure that @LD nailed it on the values:

  • It appears the Modbus receive buffer and S7-1200 Reals are both MSB-first, so a swap is not necessary
  • A range of 35-65 is reasonable for pressures and temperatures in any system of units.
The image below shows a minimal implementation of Example 2 from the link that @Lare supplied, for the first five pairs of words from the OP; OP will of course have to provide their own size for the [store] array in the "COP" FC.

xxx.png
 
Last edited:
P.S. I did uncheck [Optimized block access] for the block containing the Struct with the Reals, but that may not be necessary.

yyy.png
 
Even though you did not supply the actual values, I am pretty sure that @LD nailed it on the values:

  • It appears the Modbus receive buffer and S7-1200 Reals are both MSB-first, so a swap is not necessary
  • A range of 35-65 is reasonable for pressures and temperatures in any system of units.
The image below shows a minimal implementation of Example 2 from the link that @Lare supplied, for the first five pairs of words from the OP; OP will of course have to provide their own size for the [store] array in the "COP" FC.

View attachment 60683


I maybe would use temp bytes with lenght of 0..249 bytes. That way it would work to all modbus query lenghts, lenght 255 for sure.
 

Similar Topics

I have a Siemens 1511C that I programmed, I have V16 Pro, anyone know if you can program them with TIA Basic or do you need Pro? I saw a bunch of...
Replies
6
Views
2,273
I have an odd situation where I turn on a valve on the HMI, and the output in the PLC is on and indicates ON in the output map. But the actual...
Replies
4
Views
1,812
Is there a Netpro in Tia Portal? I am trying to configure an EKS Key for TCP/IP Protocol and I can not find where it is? or do I even need Netpro...
Replies
0
Views
2,373
We have a setup with a Siemens IPC547D as the server and 2 clients, also IPC547D's. We had these set up at Siemens Manchester on a local network...
Replies
1
Views
4,768
Hello everyone, I'm working on Step 7 Pro (TIA Portal), I would like to change the local time (GMT offset and Summer/Windter) of a S7-300 CPU...
Replies
3
Views
4,970
Back
Top Bottom