Rockwell - Convert Two INT to REAL

dalporto

Lifetime Supporting Member
Join Date
Jun 2021
Location
Montreal, QC
Posts
258
Hi all. Me again still learning Rockwell.


So I'll be polling an INT data array from a Modbus SE power meter with a L82 (with a Modbus ProSoft in between).


For the example, there is 112 registers of INT I'll be polling, let's call it TEST_ARRAY_INT[0...111].

[0] and [1] are in fact a REAL (Red phase current), so usually COP TEST_ARRAY_INT[0] GX_IA 2 would do the trick.


Problem here is that the INT's are reversed right from the Power Meter from whatever reason they had, and Reg High = Reg Low.

Using a Schneider PLC I just use a WORD_AS_REAL instruction and put the [0] on High side and the [1] on Low side, and that block has been used for years.


Now I don't know how to handle it on a Rockwell PLC without deconstructing and reconstructing the array. I tried with SWPB but it seems to only be able to swap the bytes inside 1 INT, not swap 2 words around from an array range.

Really, I don't know where to start, there are a lot of instructions I don't know here. Something with a Mask? BTD?

Thanks.
 
Hi all. Me again still learning Rockwell.


So I'll be polling an INT data array from a Modbus SE power meter with a L82 (with a Modbus ProSoft in between).


For the example, there is 112 registers of INT I'll be polling, let's call it TEST_ARRAY_INT[0...111].

[0] and [1] are in fact a REAL (Red phase current), so usually COP TEST_ARRAY_INT[0] GX_IA 2 would do the trick.


Problem here is that the INT's are reversed right from the Power Meter from whatever reason they had, and Reg High = Reg Low.

Using a Schneider PLC I just use a WORD_AS_REAL instruction and put the [0] on High side and the [1] on Low side, and that block has been used for years.


Now I don't know how to handle it on a Rockwell PLC without deconstructing and reconstructing the array. I tried with SWPB but it seems to only be able to swap the bytes inside 1 INT, not swap 2 words around from an array range.

Really, I don't know where to start, there are a lot of instructions I don't know here. Something with a Mask? BTD?

Thanks.

Just move the INTs to an array[2] in reverse order and COP that to your real.
 
This sounds like it calls for an ordinary FOR/NEXT loop in Structured Text. Use a "scratchpad" INT[2] and a REAL to hold the data as you index through the loop by steps of 2.

Off the top of my head without testing the syntax and outcome in a Logix controller:


Code:
For Index_Local1 := 0 to 110 by 2 do  // the source loop is an INT[112] of word-swapped packed Modbus REAL data.


    Index_Local2 := Index_Local + 1 ;   // the loop steps by 2, so we need another pointer for the second INT
    Index_Local3 := Index_Local | 2 ;   // the destination array is half the size of the source array so that pointer will increment by 1 each cycle of this loop.
   
    ScratchPad_Array[1] := Test_Array_INT[Index_Local1] ;  // swap the data word-by-word using a scratchpad INT[2] array
    ScratchPad_Array[0] := Test_Array_INT[Index_Local2] ;
   
    COP (ScratchPad_Array[0], ScratchPad_Real, 1) ;  // Copy (not MOV) the two INTs into a REAL to preserve the bit-by-bit values
    GX_IA[Index_Local3] := ScratchPad_Real ;   // Assign the resulting REAL value to an element of the destination REAL[56] array.


End_For ;
 
That looks promising, even tough I usually try not to put too much ST in the customer's code since the guys troubleshooting it won't understand at all. But in this case, this isn't something that they should be interested in so that could do the trick if I manage to make it work.

What is that symbol here before the 2? Never saw that in a code. Logix does not seem to appreciate it.

Index_Local3 := Index_Local | 2 ;



So, my understanding is that you're trying to shift all the array 1 integer down.

I'm going to Google a bit and try to make it work.
 
Ah, sorry, Rockwell Structured Text uses a forward slash for "divide", not a pipe symbol (shift-backslash).

You could do this with a FOR instruction to call a ladder logic routine too.
 
Code:
Index_Local2 := Index_Local + 1 ;   // the loop steps by 2, so we need another pointer for the second INT
Index_Local3 := Index_Local | 2 ;   // the destination array is half the size of the source array so that pointer will increment by 1 each cycle of this loop.

Shouldn't the two 'Index_Local' references be 'Index_Local1' ?
 
Bernie ! I was just thinking about you because I had a Parker ACR-9000 to work on and I remember you guys used classic AcroLoops. ACR-BASIC is very retro.

You're right of course. I was just firing up Studio 5000 to see if I could get the ladder logic code right.
 
You could also make the array 113 long, and move 110 to 112, 108 to 110, etc. and then start from 1 when you do the COPs to REALs
 
It takes three rungs in ladder logic. You need three Index values, a scratchpad INT[2], and a scratchpad REAL.
 

Attachments

  • DINT2REAL_screenshots.pdf
    429.4 KB · Views: 18

Similar Topics

I'm trying to convert an RS Logix 500 fille when I open the 500 file and try to "save as" a .slc file, it does not allow it. It says " SLC library...
Replies
7
Views
697
Hi All, I have several ACD files & L5X files, I would like to read the contents of these files, however I do not have Rockwell Studio 5000...
Replies
6
Views
2,319
Hello all, A group I am involved with is just completing converting a Siemens APACS control system over to an RSLogix PLC. The subject came up of...
Replies
1
Views
1,219
I have a RSlogix 500 I'm trying to convert to Rslogix 5000 and the utility wants a .slc file to work from. when I open the 500 file and try to...
Replies
1
Views
3,251
Hi, I have a Rockwell PLC progrma using L64 in the field, I need to convert to L62 in office for testing, but program is not responding while...
Replies
2
Views
1,512
Back
Top Bottom