Array searching and inserting data to first available space

Look at the File Search and Compare (FSC) Instruction.
You can have that instruction search your array for a 0 (or just about anything). It will return the fist location that it finds that meets your search criteria. You can then write something into that location.
 
Last edited:
This seems to work, although I am having some difficulty setting it up properly, everything says that I need to RES the FD or IN bits but when I write the CONTROL.IN bit in the RES instruction I get an ERROR, invalid data type. The only resetting in the RES instruction that doesn't cause an ERROR is just the CONTROL data type. How do I just reset the .DN or .IN bits?
 
If you reset the FSC instruction (by addressing a RES command to the Control tag of the FSC instruction), it will reset the .FD and .DN bits as a part of the reset.

You can also turn off the .FD and .IN bits with an OTU instruction, if you wish - an example of where you might do this is if your FSC finds a match, but you want it to continue searching the array for more matches. In that case you'd unlatch the .FD bit, and next time around it would continue from where it left off.
 
Last edited:
Try using the unlatch OTU instruction (U)? (RES) will clear out the .POS memory but wont reset the .IN bit.
If you want to post your code you can just make sure to zip it first.

EDIT: ASF is a faster than me :)
 
Ok, that makes sense. I would try the unlatch if I needed it to continue to search. What I'm trying to do is have it find the first available space in the array then MOV a 1 into it. After, RES the CONTROL tag for the next search. The problem I'm coming across is that it will fill the first two available places in the array but will then take 3 or 4 search attempts to fill in the next place. I'm wondering if it has to do with my ONS's. Also, I have it set to INCREMENTAL. Not sure if I should be using the ALL mode. I may attempt to upload the code.

Thanks guys
 
I attached two pictures of what I have. When I toggle either BMB(1 or 2)_eye I'd like for the FSC to find the first available place in the SPACE[52] array, up to 12 places, with a 0 then MOV a 1 to the space and so on when the next BMB(1 or 2)_eye is toggled.

FSC.jpg SPACE_ARRAY.PNG
 
I attached two pictures of what I have. When I toggle either BMB(1 or 2)_eye I'd like for the FSC to find the first available place in the SPACE[52] array, up to 12 places, with a 0 then MOV a 1 to the space and so on when the next BMB(1 or 2)_eye is toggled.

Looks ok to me.....

Any reason you are using a SINT array ?

Are you assuming it is more "efficient" because you only need to store 0 and 1 values ?

The controller has a 32-bit architecture, so works most efficiently with DINTs. I'll try to set up a test to see how much using SINT arrays knocks the performance.

Talking about efficiency, OTL SPACE[FIND_AVAILABLE_SPACE.POS].0 will be more efficient than the MOV 1, but is less transparent to a casual observer of the code. Properly documented should be OK.

I presume something else is "unloading" the 1's in the array.... Have you thought about what would need to happen if one of the cells was triggered and there ware no spaces available in the array ?
 
When I toggle either BMB(1 or 2)_eye I'd like for the FSC to find the first available place in the SPACE[52] array, up to 12 places, with a 0 then MOV a 1 to the space and so on when the next BMB(1 or 2)_eye is toggled.

If I understand your task then you need something like this. I have included an exported subroutine of the logic. This is uses indirect addressing with an equation to find and write to the correct locations. Good Luck with your project.

FSC FIND.jpg
 
This is not a true statement the (RES) instruction resets all bits of the instruction.

Yea I should have been more clear and said that the RES will not reset the .in bit by itself, it resets the whole control word.
 

Similar Topics

Good morning everyone, I'm working on a project where I am recording data from a machine by sending it message packets. Most of the time the data...
Replies
6
Views
2,130
I'm looking to see how I can search an array of DINTs to see how many occurrences of a certain value there are in the array. My thought was a FSC...
Replies
4
Views
1,342
I am using a UDT that has tool data. I need to query based on three values within an array of 43. ex. ToolData[43] DataType - udt_tool...
Replies
14
Views
4,997
Hi Guys, Is there an instruction suitable for searching an array of UDTs for lowest value? I can achive using a loop but figure theres an...
Replies
1
Views
2,551
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
Back
Top Bottom