Indirect addressing problem

omreko

Member
Join Date
Feb 2009
Location
dubai
Posts
3
i want to have an FB that reads three integer values as input x ,y and z for example then set the bit DBx.DBXy.z
đź““
 
so, where is the problem?

If I don't remember bad, you should declare x, y and z as word instead of Integer. It seams the same but siemens have this type of things...

It will result like:

DB[variableX].DBX[variableY].[variableZ]
 
Last edited:
so, where is the problem?

If I don't remember bad, you should declare x, y and z as word instead of Integer. It seams the same but siemens have this type of things...

It will result like:

DB[variableX].DBX[variableY].[variableZ]

Don't believe that would work.

Maybe something like

Code:
L #variableY
SLW3
L #variableZ
AW
T #TempWord

CALL DB[#variableX]

SET
= DBX[#TempWord]
I would do limit checking on all data too, like variableZ must be within the range of 0 to 7.
 
Source code for a function as follows:
Code:
FUNCTION FC 1 : VOID
TITLE =S DBx.DBXy.z
VERSION : 0.1

VAR_INPUT
  x : INT ; 
  y : INT ; 
  z : INT ; 
END_VAR
VAR_TEMP
  idb : INT ; 
END_VAR
BEGIN
NETWORK
TITLE =
      L     #x; 
      T     #idb; 
      OPN   DB [#idb]; 
      L     #y; 
      SLD   3; 
      L     #z; 
      +D    ; 
      LAR1  ; 
      SET   ; 
      S     DBX [AR1,P#0.0]; 
END_FUNCTION
 
Indirect adressing

Please find here a tested function that fulfill your requirements :

FUNCTION FC 1 : VOID
TITLE =
VERSION : 0.1


VAR_INPUT
DB_Nr : INT ;
Bit_Posit : INT ;
Word_Posit : INT ;
END_VAR
VAR_TEMP
TMP_DATA_PNT : DWORD ; //Circular Buffer Data Pointer (PTR format)
TMP_DB_Nr : INT ;
END_VAR
BEGIN
NETWORK
TITLE =

L #DB_Nr;
T #TMP_DB_Nr;
OPN DB [#TMP_DB_Nr];
L #Word_Posit;
SLD 3;
T #TMP_DATA_PNT;
L #Bit_Posit;
OD ;
T #TMP_DATA_PNT;
OPN DB [#TMP_DB_Nr];
SET ;
S DBX [#TMP_DATA_PNT];




END_FUNCTION
 
Last edited:

Similar Topics

Hi all, I need to move in the same DB 32 bytes from DBB00-DBB31 to DBB32-DBB64, so I have tried to write a simple code using the indirect...
Replies
3
Views
2,191
Hi guys, Disappeared few weeks for writing code, I'm back with a problem. There is a repeating work for different group of signals, so I decide...
Replies
18
Views
15,130
Howdy folks, I am an Allen Bradley guy currently living in an Emerson world. Working with Rx3i on PacSystems Machine Edition v. 9.6? i think...
Replies
3
Views
620
Hello, I'm very new to programming with absolutely zero schooling in this field and pretty hands off training in my new role, it's been fun...
Replies
4
Views
668
Hello Friends, I am trying to index M Bits, however GX Works2 is not allowing it with following message. https://ibb.co/zPcqj6M...
Replies
3
Views
1,379
Back
Top Bottom