using ar1

Join Date
May 2010
Location
ct
Posts
4
Hi,
I have a small problem, where I am trying to do following:
trying to run a script where it will check for matching input byte number (done in Vat table), and compare it with specific place in DB (expl. DB300.DBD108). If it deasn't find the matching number it will add 30 bytes to last address in DB300 (last address DB300.DBD100) and then compare the byte number from Vat table again, and so on, untill it reaches DB300.DBD318. If it finds matching number then it will copy next 30 bytes from that point in DB300, and place them in DINO with offset of 8 bytes. Here is what I have so far, but for some reason plc exceeds cycle time and goes into stop mode. Can someone give me any pointers to what I might be doing wrong? Thanks
Pointer_Destination and Pointer_Source are ANY pointers
// load the number of FP we are looking for
L #FP_No_Char_1
T LB 4
L #FP_No_Char_2
T LB 5
L #FP_No_Char_3
T LB 6
L #FP_Sc_Char_1
T LB 7
//open DB300
OPN DB300
// start at byte 108
L 108
SLD 3
LAR1
// loop to find matching FP
top: A(
L DID 4
L D [AR1,P#0.0]
)
==D
JC S001
A(
L 318
SLD 3
TAR1
)
==D
JC END
L 30
SLD 3
LAR1
+D
LOOP top
TAR1
L #offset_A
S001: L P##Pointer_Source
LAR1
L W#16#1002 //10h for ANY type pointer, 02h for data type BYTE
T LW [AR1,P#0.0] //Transfer to the first part of the ANY Parameter
L 30
T LW [AR1,P#2.0]
L 300 //Load the Data Block number
T LW [AR1,P#4.0]
L P##offset_A //Load the address of the first byte
T LD [AR1,P#6.0]
L B#16#84 //84h is the DB memory area type
T LB [AR1,P#6.0]

L 8
SLD 3
T #Dest_Byte_Offset
// load AR1 into destination db
L P##Pointer_Destination
LAR1
L W#16#1002
T LW [AR1,P#0.0]
// length of copying range in bytes
L 30
T LW [AR1,P#2.0]
// db no.
L DINO
T LW [AR1,P#4.0]
// byte no. of start for db
L #Dest_Byte_Offset
T LD [AR1,P#6.0]
L B#16#84
T LB [AR1,P#6.0]
////////////////////////////////////////////////////////////////
// BLKMOV
CALL "BLKMOV"
SRCBLK :=#Pointer_Source
RET_VAL:=#SFC20_RET_VAL
DSTBLK :=#Pointer_Destination

END: SLD 0
 
Your loop top is infinite loop.

Loops work this way:
Code:
     L 10 //load loop count to accumulator
top: T loopCount //transfer accu1 to variable loopCount
     
     execute some code

     L loopCount
     LOOP top //decrement accu1 by one, if not zero, jump to top
In your case if either of

Code:
L DID 4
L D [AR1,P#0.0]
) 
==D 
JC S001
A( 
L 318
SLD 3
TAR1 
) 
==D 
JC END
These conditions will not be true, it will not brake out from loop. Your code seems strange in other ways too, dont have time to check it more now.
 
Last edited:
You are storing the characters to compare in LB4,5,6,7
This is the local data of the block. You are comparing the chars with DID4, this is the instance data of the block, a completely different area. The comparison should be done with LD4, not DID4

Here's an example FB containing the correct processing:

Code:
FUNCTION_BLOCK FB 5
TITLE =
VERSION : 0.1


VAR_INPUT
  FP_No_Char_1 : CHAR ;    
  FP_No_Char_2 : CHAR ;    
  FP_No_Char_3 : CHAR ;    
  FP_sc_Char_1 : CHAR ;    
END_VAR
VAR
  Padding : ARRAY  [1 .. 4 ] OF BYTE ;    
  ichars : ARRAY  [1 .. 30 ] OF CHAR ;    
END_VAR
VAR_TEMP
  offset_a : DWORD ;    
  Pointer_Source : ANY ;    
  Pointer_Destination : ANY ;    
  dest_Byte_Offset : DWORD ;    
  SFC20_RET_val : INT ;    
  dwCharComparison : DWORD ;    
END_VAR
BEGIN
NETWORK
TITLE =

//copy comparison chars to local dword
      LAR1  P##dwCharComparison; 
      L     #FP_No_Char_1; 
      T     B [AR1,P#0.0]; 
      L     #FP_No_Char_2; 
      T     B [AR1,P#1.0]; 
      L     #FP_No_Char_3; 
      T     B [AR1,P#2.0]; 
      L     #FP_sc_Char_1; 
      T     B [AR1,P#3.0]; 
//open DB300
      OPN   DB   300; 
// start at byte 108
      LAR1  P#DBX 108.0; 
// loop to find matching FP
top:  L     #dwCharComparison; 
      L     D [AR1,P#0.0]; 
      ==D   ; 
      JC    S001; //match found
      L     P#DBX 318.0; 
      TAR1  ; 
      ==D   ; //end of search ?
      JC    END; 
      +AR1  P#30.0; //index to next search area
      JU    top; 
//match found AR1 point to address
S001: TAR1  #offset_a; 
      LAR1  P##Pointer_Source; 
      L     W#16#1002; //10h for ANY type pointer, 02h for data type BYTE
      T     W [AR1,P#0.0]; //Transfer to the first part of the ANY Parameter
      L     30; 
      T     W [AR1,P#2.0]; 
      L     DBNO; //Load the Data Block number
      T     W [AR1,P#4.0]; 
      L     #offset_a; //Load the address of the first byte
      T     D [AR1,P#6.0]; 
// load AR1 into destination db
      LAR1  P##Pointer_Destination; 
      L     W#16#1002; 
      T     W [AR1,P#0.0]; 
// length of copying range in bytes
      L     30; 
      T     W [AR1,P#2.0]; 
// db no.
      L     DINO; 
      T     W [AR1,P#4.0]; 
// byte no. of start for db
      L     P#DBX 8.0; 
      T     D [AR1,P#6.0]; 
////////////////////////////////////////////////////////////////
// BLKMOV
      CALL "BLKMOV" (
           SRCBLK                   := #Pointer_Source,
           RET_VAL                  := #SFC20_RET_val,
           DSTBLK                   := #Pointer_Destination);

END:  NOP   0; 
END_FUNCTION_BLOCK
 
Last edited:

Similar Topics

I am looking for some advice on this FC I just wrote. I have trace numbers that are constantly moved and want to verify that they match. They are...
Replies
7
Views
5,080
Hello everyone, I'm working on a project that involves controlling an array of nozzles within a CNC environment, where the nozzles travel along a...
Replies
5
Views
118
Hi, I was noticing that Profibus connectors have 2 ports on them that can house 2 separate cables. Can I use 2 cables with Profibus signals...
Replies
4
Views
124
Hi, Seeking consultation on an implementation matter, and have a question about Modicon Compact 984 communication through RS485: Three Modicon...
Replies
3
Views
84
Dear all, I don't know why setup of password became challenging and weird. After setting up the password and try to upload the ladder from the plc...
Replies
3
Views
91
Back
Top Bottom