You are not registered yet. Please click here to register!


 
 
plc storereviewsdownloads
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
 
Try our online PLC Simulator- FREE.  Click here now to try it.

New Here? Please read this important info!!!


Go Back   PLCS.net - Interactive Q & A > PLCS.net - Interactive Q & A > LIVE PLC Questions And Answers

Reply
 
Thread Tools Display Modes
Old February 3rd, 2009, 04:13 AM   #1
userxyz
Member
United States

userxyz is offline
 
Join Date: May 2002
Location: any
Posts: 2,768
ST SCL question (swap words)

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 by userxyz; February 3rd, 2009 at 04:25 AM.
  Reply With Quote
Old February 3rd, 2009, 04:59 AM   #2
L D[AR2,P#0.0]
Lifetime Supporting Member
United Kingdom

L D[AR2,P#0.0] is offline
 
Join Date: Nov 2006
Location: UK
Posts: 6,193
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
  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Topics
Thread Thread Starter Forum Replies Last Post
SIMATIC SCL question Kelkoon LIVE PLC Questions And Answers 7 October 20th, 2010 11:35 AM
SCL Question sparkysliderz LIVE PLC Questions And Answers 4 May 22nd, 2006 04:17 AM
Comparing bits, bytes, words and double words in SCL? BoSChoW LIVE PLC Questions And Answers 14 May 6th, 2006 03:37 PM
NT2 ST terminal question Boyko LIVE PLC Questions And Answers 4 January 31st, 2006 02:38 PM
RTD swap to thermocouple, question russrmartin LIVE PLC Questions And Answers 11 October 23rd, 2002 11:27 PM


All times are GMT -5. The time now is 02:45 AM.


.