News:

  • May 01, 2026, 03:11:43 PM

Login with username, password and session length

Author Topic: Help with converting to MHR's to a Real  (Read 35278 times)

ryanastiefes

  • Sr. Member
  • ****
  • Posts: 72
Help with converting to MHR's to a Real
« on: September 18, 2012, 09:29:52 PM »
I writing to f42300 register in NI Lookout 6.6 (essentially this is just two registers 40023 and 40024) In Do More ladder I need to convert these two registers MHR23 and MHR24 to a Real. I have tried the MOVER and MOVE but did not get what i needed. Is this possible? Thank for any help.http://

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3806
    • Host Engineering
Re: Help with converting to MHR's to a Real
« Reply #1 on: September 18, 2012, 10:06:26 PM »
In this case, use the SUBSCRIB instruction.  Tell it you want to move MHR23 as a REAL into R0 (or some other R element).  Let me know if the WORDs need to be swapped or if the BYTEs need to be swapped.  The best way to determine that is to just enter "3.14" or some common float from your Master, then look at R0 (or whatever R register you ended up using) and see if you got the right value.

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3806
    • Host Engineering
Re: Help with converting to MHR's to a Real
« Reply #2 on: September 18, 2012, 10:09:39 PM »
If the REAL started on an even word address (i.e. a DWORD boundary), you could have used a CAST.  For example, say you had a REAL at MHR30/MHR31, then you COULD have just used MHR30:R (i.e. look at MHR30 as a DWORD REAL, not as its native 16 bit WORD).  However, since the DWORD was mis-aligned in WORD memory (i.e. it started on an "odd" word address), you have to use SUBSCRIB, which allows conversions of mis-aligned values, e.g. MHR23 as a DWORD REAL into R0.

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6154
  • Yes Pinky, Do-more will control the world!
Re: Help with converting to MHR's to a Real
« Reply #3 on: September 18, 2012, 10:15:17 PM »
Yep. A couple of possible ways:

1. If the two locations are DWORD aligned, you can access them in place by using the real cast operator ':R'. If you wrote to MHR30 and 31, you would use MHR30:R. Please note that only works if is on a DWORD boundary...and MHR23 is not aligned, it would need to be on an even number like MHR22:R or MHR24:R.

*or*

2. You can use the SUBSCRIB to convert and move unaligned data. See the attached picture.
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO

ryanastiefes

  • Sr. Member
  • ****
  • Posts: 72
Re: Help with converting to MHR's to a Real
« Reply #4 on: September 18, 2012, 11:32:54 PM »
Alright tried both methods, but both do not seem to work. Here is what i get. I am writing in 1.220 and getting a very large number

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6154
  • Yes Pinky, Do-more will control the world!
Re: Help with converting to MHR's to a Real
« Reply #5 on: September 18, 2012, 11:46:45 PM »
The cast you are showing will only work if you are writing to MHR24 and MHR25, but before you said you were writing to MHR23 and MHR24. If you are writing to MHR24 and MHR25, and the cast is still not working, then you are probably having some byte swapping issues...a common thing when working with Modbus.

The SUBSCRIB instruction has an option to reverse bytes. Try that.
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6154
  • Yes Pinky, Do-more will control the world!
Re: Help with converting to MHR's to a Real
« Reply #6 on: September 18, 2012, 11:56:00 PM »
As an example of how bad things can be when it isn't correct, I wrote a simple program that loads 1.22 into R0, writes the lower word into MHR23 and the upper word into MHR24 (to simulate your Modbus comms), then uses the proper SUBSCRIB option to convert and copy to R2, as well as incorrect options to copy to R2, R3, and R4. AS you can see from the data view, R1 is correct, and R2, R3, and R4 are a mess.
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6154
  • Yes Pinky, Do-more will control the world!
Re: Help with converting to MHR's to a Real
« Reply #7 on: September 19, 2012, 12:02:09 AM »
...and I just swapped the MHR23 and MHR24...high word in the first location and low word in the second...and I got your exact 2.733E-14 value. So...the easiest way will be to do two MOVE instructions. Assuming that you wrote to MHR23 and MHR24, using the following code:

MOVE MHR23 R0:W1
MOVE MHR24 R0:W0

Fun...
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO

ryanastiefes

  • Sr. Member
  • ****
  • Posts: 72
Re: Help with converting to MHR's to a Real
« Reply #8 on: September 19, 2012, 12:26:32 AM »
Perfect!!!! That did it. Thanks alot.

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3806
    • Host Engineering
Re: Help with converting to MHR's to a Real
« Reply #9 on: September 19, 2012, 06:54:23 AM »
...and I just swapped the MHR23 and MHR24...high word in the first location and low word in the second...and I got your exact 2.733E-14 value. So...the easiest way will be to do two MOVE instructions. Assuming that you wrote to MHR23 and MHR24, using the following code:

MOVE MHR23 R0:W1
MOVE MHR24 R0:W0

Fun...
Sounds like we need a Swap Word option on each publish/subscribe item, in addition to byte swap.