ST SCL question (swap words)

userxyz

Member
Join Date
May 2002
Location
any
Posts
2,768
Anyone knows how to swap 2 words in a doubleword varible in SCL or ST ?

This is what I have:

Set_Pos:= REAL_TO_DINT(GRAPH_POS_SET * Scale)

Set_Pos is a DINT, the 2 words/integers in this doubleword should be swapped.

In STL it's possible by using a ROL_DW function and this for a shift of 16 places.

In ST or SCL, I have no idea...


I also need the CAW function in SCL: Swapping 2 byte's in a word
 
Last edited:
SCL & STL implementations for swapping words in a dword.

Code:
FUNCTION FC2: VOID
VAR_IN_OUT
    dwData:DWORD;
    END_VAR
VAR_TEMP
wTemp:WORD;
dwSwap:DWORD;
wSwap AT dwSwap: ARRAY[1..2] OF WORD;  
END_VAR
dwSwap:=dwData;
wTemp:=wSwap[1];
wSwap[1]:=wSwap[2];
wSwap[2]:=wTemp;
dwData:=dwSwap;
END_FUNCTION

FUNCTION FC 1 : VOID
TITLE =
VERSION : 0.1

VAR_IN_OUT
  dwData : DWORD ; 
END_VAR
BEGIN
NETWORK
TITLE =
      L     P##dwData; 
      LAR1  ; 
      L     W [AR1,P#0.0]; 
      L     W [AR1,P#2.0]; 
      T     W [AR1,P#0.0]; 
      TAK   ; 
      T     W [AR1,P#2.0]; 
END_FUNCTION
 

Similar Topics

Hello, When you want compare values of an array to a range of numbers is it a right way to do that? FUNCTION ADD VAR_IN_OUT A:ARRAY[1..50]...
Replies
5
Views
2,045
I just found a piece of code using an operator "+=" IF tag1 AND tag2 THEN tag3 += tag4; tag5 := tag5 + tag6; END_IF; I don't...
Replies
11
Views
4,579
I am having difficulty doing something i do in every other plc without a problem I have created an SCL AOI. I have an integer input to it. Lets...
Replies
3
Views
1,606
I am new to PLC programming. Is there a standard way to incorporate alarms / warnings / events such as the exceptions in C++ or Java where you can...
Replies
5
Views
1,934
Hi all in a SCL FB I've decalred some variables like this: VAR ShiftRegister:ARRAY [0..100] OF BOOL; ValvesOutputCMD: ARRAY...
Replies
1
Views
1,633
Back
Top Bottom