S7 300 database search

ohmslaw69

Member
Join Date
Mar 2015
Location
Indiana
Posts
3
Hi all,
I am working on a project where I am needing to apply recipe data to some analog outputs based on a fixture number. I have a DB with 30 fixture recipes starting at DB720.DBB0 (structures made up of a fixture name (array of 1-12 chars), new/old boolean (new =1) and 9 real numbers). The length of each fixture recipe is 50 bytes.
I need to search through the fixture numbers and compare that to the fixture number that was transmitted by an upstream machine (another array of chars 1-12) starting at DB702.DBB10.
When I find a match, I need to copy the recipe data from the database (DB720) to the work area (DB710.DBB0).
I am new to STL and Siemens, but have many years with ladder. After doing alot of research, I found how to make variable pointers that I can increment. However, my code doesn't seem to work correctly. I am getting an "area length error when reading" in the processor and my sort doesn't seem to work correctly. Can anyone assist?

I have an "Any" pointer called fixt_mov_loc defined in the temp area at 0.0

Network 50
// WHEN NEW PARTS LOADED, LATCH THAT STATUS UNTIL FIXTURE SEARCH IS COMPLETE

A "0_DEG_PART_LOADING_OK"
FP "0_DEG_PART_LOADED_PULS"
S "0_DEG_PART_LOADED_LTCH" //LATCH SIDE A LOADED STATUS


A "180_DEG_PART_LOADING_OK"
FP "180_DEG_PART_LOADED_PULS"
S "180_DEG_PART_LOADED_LTCH" //LATCH SIDE B LOADED STATUS


A "0_DEG_FIXT_FOUND"
FP "0_DEG_FIXT_FND_PLS"
R "0_DEG_PART_LOADED_LTCH" //CLEAR SIDE A LOADED STATUS

A "180_DEG_FIXT_FOUND"
FP "180_DEG_FIXT_FND_PLS"
R "180_DEG_PART_LOADED_LTCH" //CLEAR SIDE B LOADED STATUS


Network 51
// SEARCH FOR A (0 DEG) FIXTURE PARAMETERS IN DB ARRAY
// START AT POSITION 1 AND SEARCH TO 30

//SEARCH THROUGH ARRAYS TO FIND FIXTURE

A "0_DEG_PART_LOADED_LTCH"
FP "0_DEG_PART_LOADED_PULS2"
L L#0
T "FIXT_PRES_POINTER_A" //INITIALAZE INDEX VARIABLE

NFND: A "0_DEG_PART_LOADED_LTCH"
OPN "FIXT_PRESS_DATABASE" //OPEN FIXTURE DATABASE DATA BLOCK
L P#DBX 0.0 //LOAD POINTER WITH FIRST FIXTURE NUM LOCATION
LAR1 //LOAD ADDRESS REGISTER WITH START OF ARRAY
L "FIXT_PRES_POINTER_A" //'INDEX' IS INCREMENTED BY 50 AFTER EVERY UNSUCCESSFUL SEARCH
SLD 3 //CONVERT INDEX TO POINTER FORMAT
+AR1 //ADD INDEX TO POINTER START POINT
L DBD [AR1,P#0.0] //POINT CHARS 1-4
T DB721.DBD 0 //XFER CHARS 1-4
L DBD [AR1,P#4.0] //POINT AT CHARS 5-8
T DB721.DBD 4 //XFER CHARS 5-8
L DBD [AR1,P#8.0] //POINT AT CHARS 9-12
T DB721.DBD 8 //XFER CHARS 9-12

L DB721.DBD 0 //LOAD COMPARISON CHARS 1-4
L DB702.DBD 10 //LOAD PARI FIXT A CHARS 1-4
==D //COMPARE CHARACTERS 1 TO 4 OF A FIXTURE NUM
A(
L DB721.DBD 4 //LOAD COMPARISON CHARS 5-8
L DB702.DBD 14 //LOAD PARI FIXT A CHARS 5-8
==D //COMPARE CHARACTERS 5-8 OF FIXTURE NUM
)
A(
L DB721.DBD 8 //LOAD COMPARISON CHARS 9-12
L DB702.DBD 18 //LOAD PARI FIXT A CHARS 9-12
==D //COMPARE CHARACTERS 9-12 OF FIXTURE NUM
)
A "0_DEG_PART_LOADED_LTCH"
JC AFND //IF ALL 12 CHARACTERS MATCH, JUMP TO CONTINUE PROCESSING

//ALL 12 CHARACTERS DID NOT MATCH, INDEX POINTER BY 50 AND COMPARE NEXT PART NUM
A "0_DEG_PART_LOADED_LTCH"
L "FIXT_PRES_POINTER_A"
L L#1450
>=D //IF POINTER IS >= 1450 THEN AT END OF FIXTURE LIST
JC FALT //JUMP TO FIXTURE FAULT LOGIC

A "0_DEG_PART_LOADED_LTCH"
L "FIXT_PRES_POINTER_A" //LOAD POINTER TO ACC1
+ L#50 //ADD +50 (DOUBLE INT) TO POINTER TO INDEX TO NEXT FIXT NUM
T "FIXT_PRES_POINTER_A" // STORE INDEXED POINTER
JU NFND //LOOP TO SEARCH AGAIN


Network 52

AFND: A "0_DEG_PART_LOADED_LTCH"
L W#16#1002 // S7 pointer constant 10hex; Data type 02hex (= Byte)
T LW 0 // --> Byte 0 & 1 of ANY Pointer
L 50 //Length of data to be transfered in BYTES
T LW 2 // --> Byte2 &3 of ANY Pointer
L 720 // Set DB number to 0 (not applicable as Q are is used)
T LW 4 // --> Byte4 &5 of ANY Pointer
L "FIXT_PRES_POINTER_A" // Set Byte Number of Starting Byte
SLD 3 // Shift INT to make a pointer
OD DW#16#84000000 // Combine DB area and pointer
T LD 6 // --> Byte6 -9 of ANY Pointer
CALL "BLKMOV" // Copy 50 Bytes
SRCBLK :=#FIXT_MOV_LOC // Pointer to fixture found A in list
RET_VAL:="BLKMOV_ERROR" // Block move error
DSTBLK :=P#DB710.DBX0.0 BYTE 50 // Fixture A Pressure Location
= "0_DEG_FIXT_FOUND"
 
Once you have opened a DB (say OPN DB1), any further accesses to a fully qualified DB address (e.g. DB4.DBD88) will open DB4. For future reference, copy your blocks to a library and post the archived library. Attached is an empty library that you can retrieve if required.

Code:
NFND: A     "0_DEG_PART_LOADED_LTCH"
      OPN   "FIXT_PRESS_DATABASE"       //OPEN FIXTURE DATABASE DATA BLOCK
      L     P#DBX 0.0                   //LOAD POINTER WITH FIRST FIXTURE NUM LOCATION
      LAR1                              //LOAD ADDRESS REGISTER WITH START OF ARRAY
      L     "FIXT_PRES_POINTER_A"       //'INDEX' IS INCREMENTED BY 50 AFTER EVERY UNSUCCESSFUL SEARCH
      SLD   3                           //CONVERT INDEX TO POINTER FORMAT
      +AR1                              //ADD INDEX TO POINTER START POINT
      L     DBD [AR1,P#0.0]             //POINT CHARS 1-4
      T     DB721.DBD    0              //XFER CHARS 1-4
      L     DBD [AR1,P#4.0]             //[COLOR=Red]accesses db721, not the db using the opn[/COLOR]
 
Loads and transfers take place irrespective if the RLO, you need to use jump instuctions to jump around loads/transfers

Code:
      A     "0_DEG_PART_LOADED_LTCH"
      FP    "0_DEG_PART_LOADED_PULS2"
      L     L#0 [COLOR=Red]//always executed[/COLOR]
      T     "FIXT_PRES_POINTER_A" [COLOR=Red]//always executed[/COLOR]
 
So would you recommend using the OPN command after every transfer? Or just go about the whole thing differently? Maybe like I did in the second pointer/block move network?

Thanks again!
 
Loads and transfers take place irrespective if the RLO, you need to use jump instuctions to jump around loads/transfers

Code:
      A     "0_DEG_PART_LOADED_LTCH"
      FP    "0_DEG_PART_LOADED_PULS2"
      L     L#0 [COLOR=Red]//always executed[/COLOR]
      T     "FIXT_PRES_POINTER_A" [COLOR=Red]//always executed[/COLOR]


Yeah, I found that out on another section of code after I posted.
 
So would you recommend using the OPN command after every transfer?

No, before a load/transfer that relies on the correct DB being open where fully qualified DB access are involved.

Code:
      L     P#DBX 0.0                   //LOAD POINTER WITH FIRST FIXTURE NUM LOCATION
      LAR1                              //LOAD ADDRESS REGISTER WITH START OF ARRAY
      L     "FIXT_PRES_POINTER_A"       //'INDEX' IS INCREMENTED BY 50 AFTER EVERY UNSUCCESSFUL SEARCH
      SLD   3                           //CONVERT INDEX TO POINTER FORMAT
      +AR1                              //ADD INDEX TO POINTER START POINT
      [COLOR=Red]OPN   "FIXT_PRESS_DATABASE"       //OPEN FIXTURE DATABASE DATA BLOCK[/COLOR]
      L     DBD [AR1,P#0.0]             //POINT CHARS 1-4
      T     DB721.DBD    0              //XFER CHARS 1-4
      [COLOR=Red]OPN   "FIXT_PRESS_DATABASE"       //OPEN FIXTURE DATABASE DATA BLOCK[/COLOR]
      L     DBD [AR1,P#4.0]             //POINT AT CHARS 5-8
      T     DB721.DBD    4              //XFER CHARS 5-8
      [COLOR=Red]OPN   "FIXT_PRESS_DATABASE"       //OPEN FIXTURE DATABASE DATA BLOCK[/COLOR]
      L     DBD [AR1,P#8.0]             //POINT AT CHARS 9-12
      T     DB721.DBD    8              //XFER CHARS 9-12
 

Similar Topics

Hi all, I have a database from a Siemens S7-300 which I need to know the addresses for some data inside two particular data blocks. I tried...
Replies
1
Views
1,719
Hi Siemens guys! I am experiencing SF fault on our S7-300 (6ES7 315-2AH14-0AB0) CPU from time to time. I've checked the diagnostic buffer and...
Replies
13
Views
150
Have a system that has been running for over a year and all of a sudden getting a ExcessiveVelocityFault on one of the drives when the MSO command...
Replies
2
Views
142
Hello PLCS.Net Forum, First time posting. Let's assume I am a novice. BASIC PROBLEM: My servo/linear piston is no longer zeroed to the...
Replies
9
Views
212
hi... i have an issue in s7 300 plc, while we run the machine(in idle there is no fault) , plc cpu goes in SF mode, after restart the power cycle...
Replies
2
Views
116
Back
Top Bottom