You are not registered yet. Please click here to register!


 
 
plc storereviewsdownloads
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
 
Try our online PLC Simulator- FREE.  Click here now to try it.

New Here? Please read this important info!!!


Go Back   PLCS.net - Interactive Q & A > PLCS.net - Interactive Q & A > LIVE PLC Questions And Answers

Reply
 
Thread Tools Display Modes
Old January 15th, 2022, 12:53 PM   #1
Hal9000
Member
United Kingdom

Hal9000 is offline
 
Join Date: Jun 2010
Location: London
Posts: 140
Tia Portal Pro - Word Array to Real Struct?

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
Attached Images
File Type: jpg Word to Real.jpg (218.0 KB, 67 views)
  Reply With Quote
Old January 15th, 2022, 01:02 PM   #2
drbitboy
Lifetime Supporting Member
United States

drbitboy is offline
 
drbitboy's Avatar
 
Join Date: Dec 2019
Location: Rochester, NY
Posts: 7,007
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.
__________________
_
Brian T. Carcich
i) Take care of the bits, and the bytes will take care of themselves.
ii) There is no software problem that cannot be solved with another layer of indirection.
iii) Measurement is hard.
iv) I solemnly swear that I am up to no good
v) I probably have the highest ratio of forum posts to actual applications in the field (but no longer ∞ ).
vi) Hakuna matata.
vii) Bookkeeping.
  Reply With Quote
Old January 15th, 2022, 03:35 PM   #3
L D[AR2,P#0.0]
Lifetime Supporting Member
United Kingdom

L D[AR2,P#0.0] is offline
 
Join Date: Nov 2006
Location: UK
Posts: 6,616
Example code to swap the modbus words to give different flooting point results. As already said, what should the data be?
Attached Images
File Type: jpg mswap1.jpg (165.9 KB, 67 views)
__________________
S7-300 to 1500 conversions done - email (minus the spam) to spams7conversions@hotmail.com
  Reply With Quote
Old January 15th, 2022, 03:37 PM   #4
Lare
Member
Finland

Lare is offline
 
Join Date: Jan 2006
Location: Finland
Posts: 1,945
https://support.industry.siemens.com.../view/42603881


Example 2 is for copying between different types, but do you need also word -> real conversion between?
  Reply With Quote
Old January 15th, 2022, 03:37 PM   #5
L D[AR2,P#0.0]
Lifetime Supporting Member
United Kingdom

L D[AR2,P#0.0] is offline
 
Join Date: Nov 2006
Location: UK
Posts: 6,616
db contents:
Attached Images
File Type: jpg mswap2.jpg (175.3 KB, 62 views)
__________________
S7-300 to 1500 conversions done - email (minus the spam) to spams7conversions@hotmail.com
  Reply With Quote
Old January 16th, 2022, 12:45 AM   #6
drbitboy
Lifetime Supporting Member
United States

drbitboy is offline
 
drbitboy's Avatar
 
Join Date: Dec 2019
Location: Rochester, NY
Posts: 7,007
@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?
__________________
_
Brian T. Carcich
i) Take care of the bits, and the bytes will take care of themselves.
ii) There is no software problem that cannot be solved with another layer of indirection.
iii) Measurement is hard.
iv) I solemnly swear that I am up to no good
v) I probably have the highest ratio of forum posts to actual applications in the field (but no longer ∞ ).
vi) Hakuna matata.
vii) Bookkeeping.
  Reply With Quote
Old January 16th, 2022, 06:27 AM   #7
mad4x4
Member
United Kingdom

mad4x4 is offline
 
mad4x4's Avatar
 
Join Date: Mar 2009
Location: ST CYrus
Posts: 326
Quote:
Originally Posted by Hal9000 View Post
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
  Reply With Quote
Old January 16th, 2022, 07:52 AM   #8
Hal9000
Member
United Kingdom

Hal9000 is offline
 
Join Date: Jun 2010
Location: London
Posts: 140
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
  Reply With Quote
Old January 16th, 2022, 08:06 AM   #9
L D[AR2,P#0.0]
Lifetime Supporting Member
United Kingdom

L D[AR2,P#0.0] is offline
 
Join Date: Nov 2006
Location: UK
Posts: 6,616
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.
__________________
S7-300 to 1500 conversions done - email (minus the spam) to spams7conversions@hotmail.com
  Reply With Quote
Old January 16th, 2022, 11:22 AM   #10
Lare
Member
Finland

Lare is offline
 
Join Date: Jan 2006
Location: Finland
Posts: 1,945
Quote:
Originally Posted by L D[AR2,P#0.0] View Post
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.
  Reply With Quote
Old January 16th, 2022, 04:14 PM   #11
drbitboy
Lifetime Supporting Member
United States

drbitboy is offline
 
drbitboy's Avatar
 
Join Date: Dec 2019
Location: Rochester, NY
Posts: 7,007
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
__________________
_
Brian T. Carcich
i) Take care of the bits, and the bytes will take care of themselves.
ii) There is no software problem that cannot be solved with another layer of indirection.
iii) Measurement is hard.
iv) I solemnly swear that I am up to no good
v) I probably have the highest ratio of forum posts to actual applications in the field (but no longer ∞ ).
vi) Hakuna matata.
vii) Bookkeeping.

Last edited by drbitboy; January 16th, 2022 at 04:18 PM.
  Reply With Quote
Old January 16th, 2022, 04:25 PM   #12
drbitboy
Lifetime Supporting Member
United States

drbitboy is offline
 
drbitboy's Avatar
 
Join Date: Dec 2019
Location: Rochester, NY
Posts: 7,007
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
__________________
_
Brian T. Carcich
i) Take care of the bits, and the bytes will take care of themselves.
ii) There is no software problem that cannot be solved with another layer of indirection.
iii) Measurement is hard.
iv) I solemnly swear that I am up to no good
v) I probably have the highest ratio of forum posts to actual applications in the field (but no longer ∞ ).
vi) Hakuna matata.
vii) Bookkeeping.
  Reply With Quote
Old January 16th, 2022, 05:56 PM   #13
Lare
Member
Finland

Lare is offline
 
Join Date: Jan 2006
Location: Finland
Posts: 1,945
Quote:
Originally Posted by drbitboy View Post
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.

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.
  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Topics
Thread Thread Starter Forum Replies Last Post
TIA Portal Indirect Addressing/Recipe Management ASF LIVE PLC Questions And Answers 19 April 6th, 2018 12:52 AM
TIA Portal: change tag value ASF LIVE PLC Questions And Answers 3 September 27th, 2016 01:45 PM
TIA Portal V12 FireBeard LIVE PLC Questions And Answers 1 September 24th, 2014 04:07 PM
Siemens OP77B Trouble in TIA Portal Tim James LIVE PLC Questions And Answers 4 December 24th, 2012 03:27 PM
Not able to understand this S7-code drspanda LIVE PLC Questions And Answers 8 November 13th, 2007 01:06 PM


All times are GMT -4. The time now is 08:52 AM.


.