CONCAT 2 words into a real machine expert-basic

BNP

Member
Join Date
Dec 2020
Location
Adelaide
Posts
1
Hello,

I am using Machine expert - basic with an M221 PLC.

I have two 16 bit modbus registers coming in and I want to convert to a 32bit real value.

I want to join two words into one real value as shown below

(e.g. %mw100 = 1234 %mw101 = 5678, real = 12345678)

Thanks in advance,
Bill
 
I assume (I know, I know) that the two Modbus registers contain the bit pattern for an IEEE 754 single precision floating point number and you just need to get that bit pattern into a REAL variable. If this is the case then the UNION that drbitboy shows in the link is one pretty good way to approach this.

Keith
 
I assume (I know, I know) that the two Modbus registers contain the bit pattern for an IEEE 754 single precision floating point number and you just need to get that bit pattern into a REAL variable. If this is the case then the UNION that drbitboy shows in the link is one pretty good way to approach this.

Keith


Drbitboys exmple is for Machine expert (Codesys, 241/251 platforms) which is totally different programming environment than Machine expert basic (M221) platform.


On M221 you can directly read %MF (Float) memory area.
One float consistent of two integer memorys (%MF0, =%MW0 & %MW1, %MF2= %MW2 & %MW3 ... %MF100= %MW100 & %MW101


If you need to swap bits on integers, you can use swap-command. (y)
 
Drbitboys exmple is for Machine expert (Codesys, 241/251 platforms) which is totally different programming environment than Machine expert basic (M221) platform.


On M221 you can directly read %MF (Float) memory area.
One float consistent of two integer memorys (%MF0, =%MW0 & %MW1, %MF2= %MW2 & %MW3 ... %MF100= %MW100 & %MW101


If you need to swap bits on integers, you can use swap-command. (y)


When I looked through the manual but did not see that addressing scheme, I guess I missed it. So in the OP's case:


I have two 16 bit modbus registers coming in and I want to convert to a 32bit real value.

I want to join two words into one real value as shown below

(e.g. %mw100 = 1234 %mw101 = 5678, real = 12345678)


then %MF50 contains the float (assuming LSB-first in both systems, and no byte ordering is required)?


OP: if you state the values of the two 16-bit modbus registers, it is possible to determine what possible 32-bit floating-point values they can represent, and if you know what the actual real value will be, then it is possible to determine if any byte-swapping is necessary.
 
Of Course you missed adressing for M221. You have wrong manual and wrong program for M221.
Schneider have allmost same names for 3 different plc programming softwares!
 
ah, here it is:


https://download.schneider-electric.com/files?p_Doc_Ref=EIO0000003289&p_File_Ext=#M3.9.DSE002786738


Wait a minute, that says that the "i" in the %MFi for 32-bit floating-point values refers to the the same memory address as the "i" in the %MWi for 16-bit integer values, so you should never work with two %MFi and %MFj values where i and j differ by 1. However, that Machine Expert - Basic manual has this example:


xxx.png


which is wrong because it uses both %MF12 and %MF13, which overlap in memory, in the same expression.


That is what threw me the first time I looked at that manual: when I saw %MF12 and %MF13 in that example, I assumed that the %MF and %MW syntax referred to different memory.
 
Last edited:
Of Course you missed adressing for M221. You have wrong manual and wrong program for M221.
Schneider have allmost same names for 3 different plc programming softwares!




No, I started with the right manual (- basic), but saw the "error" and moved on to the wrong manual.


d'Oh!
 
Last edited:
You are right. You should use every second float addresses. %MF12 and %MF13 overlaps and help document have error.
 

Similar Topics

Hi all I am trying to set up a lhttp instruction to connect to an api https (with our IT) this will send data back to the plc? I have an api https...
Replies
9
Views
1,786
I'm writing a new program for a CompactLogix 5069-L310ER. I used a GSV to grab the date and time from the processor. Then several DTOS and...
Replies
5
Views
2,018
Can I take 2 strings, concatenate them and use that result as a TagName of a Bool or any other element? I'm creating an AOI for MSG stats and it...
Replies
3
Views
1,475
Good Morning , I'm working on trying to get timestamping done on some doses. I am very close, thanks to many of you with your advice. I...
Replies
7
Views
2,654
Hi all, Quick question if anyone knows offhand - In a ControlLogix (or Compact Logix), the default STRING datatype has a maximum length of 82...
Replies
5
Views
2,187
Back
Top Bottom