UINT to INT

I think a picture is worth a thousand words here.


On the right is the poll of the modicon starting at 40500. That is put into the compactlogix starting at 4xxx[0] So 4xxx[0] = 40501 on the left


On the left - 40504,40505 make up a float in the Modicon. (slight difference due to time, its pressure)
On the right - 4xxx[4],4xxx[5] is what gets put into the INT array. CANNOT CHANGE THE DATATYPE.

The data in the INT is still correct, it is just displaying as a signed number. the bit pattern of 1011 0010 0011 1111 is -19905 signed or 46031 unsigned. Bits is bits, it doesn't matter how it displays. COP the two INTS into a REAL in the right order and your floating point number is there intact.
 
I have put the UINT into successive 16 bit registers (not using symbolic)
Then again using the 16 bit actual registers as a real in other words D0 & D1 are 16 bit either integers or UINT but the function EMOV is a real (float) so when you populate it with the first register D0 It thinks it's a real as it would not accept a real in symbolic form but as an actual address it treats it as one i.e. My_Real = D0 + D1
Perhaps is hard to grasp but think of it in Siemens flagwords FD10 is actually either a 32 bit Dword or 32 bit float so by maniplulating the FW 10 & 11 you can use it then use it again as a float.
As per picture you can assign a different symbol to the two 16 bit words as long as for example you use a 16 bit MOVE function MOVE is 16 bit move function, if you use a 32 bit float then it would be the function EMOV (EMove is 32 bit float move)
When the program is compiled because it uses the symbolic actual address i.e. D0 + D1 but it only needs D0 as the input pin on the function the compiler automatically knows it is a real because of the function name fortunately, mitsubishi does not check for symbol actual adaresses only symbols are not duplicated

Registers.png
 
Last edited:
It's one of the few things I like more about Mitsi and Siemens than I do about RW. What data means and what its type is depends on how you look at it and how you use it. So you can implement something like a C union with a dataspace. I am currently working on a Siemens project after quite some time away so I was just reminded how much I like this attribute.

Keith
 
Yes it's one step forward for symbolic addressing not having to think about actual addresses but two steps back in the other.
The thing about Mitsi is that in the globals you can have both symbolic address space without actual address or with it is that without you do not know it's actual address is goint to be until compiled & also even though you can find it in the IDE next change to the program will possibly re-assign the symbols to different physical address so all data being written to or read from say an HMI has to have a global tag with an actual address
 
I didn't scrutinize the details of your data to be sure, but I would suspect that you need to word swap the INTs before you pack them into the REAL.
 
Hm... I did not do that in Mitsi however, the two register values from the screenshot turned into a valid real number. as is, however, not checked that it is correct but if the words are reversed in my case i think it would come out as some riduculous number
 
This worked. I created a UDT. Defined the UDT as a UINT[10]
Then COP the INT into the UDT.


The 3rd word is 40500 converted back.


Thanks for pointing out that the bits are the same. I don't know why this has to be so hard sometimes. If the compactlogix

supported COP of UINT I would never had this problem. Its the first thing I tried and it throws a datatype error.





UDT.PNG

UDT2.PNG


udt3.PNG
 
Last edited:
Programming is 90% bookkeeping.

Maybe I am late, and there still may be a word ordering issue, but the primary problem is obvious in the image below.

  • The 12288, at Modicon address 40501 (actually just 501) and Logix array index [0], is an obvious duplicate that can be used to line up the Modicon data with the Logix array elements.
  • The 8192 a Modicon address 502, and the -32768 at Logix array index [1], are both integers with single bits true, which also suggests they line up
  • The numbers near 17000, at even Modicon addresses 504, 506, 508, suggest they are the high word of float values near 64.0, which is near the pressure of 61 that OP expected to see.
mb2PNG.PNG
 
Last edited:

Similar Topics

I apologize for the basic question but I have read the documentation and searched online and I'm still not getting it... I want to convert UINT...
Replies
4
Views
999
I have a UDT with multiple elements that all show on the display perfectly using direct reference. For example I have the following instance on a...
Replies
2
Views
1,458
Hello, I'm using Compact Logix L33 in RSLogix 5000. I'm trying to message over modbus register that is 16bit UINT. In Rslogix 5000 do I message...
Replies
3
Views
1,574
Hello, It is possible to change form INT to UINT a variable data type? For the moment, I receive the value -32766 (Local:6:I.Ch0Data) from...
Replies
4
Views
2,737
HI, I am trying to read a UINT 64 bit data(active energy parameter) from a PQA meter(WM5-96) over Modbus TCP into a GE PLC.I am able to read...
Replies
0
Views
1,576
Back
Top Bottom