Making a queue STL

VolTune

Member
Join Date
Dec 2018
Location
Antwerp
Posts
5
Hello everybody.

For a project, I need to make a queue that stores REAL's.
There needs to be the possibility to select a place and than move the selected place up or down, removing, etc.

I first made a simple version in FBD, but everything is written out long and it's not dynamic at all. (For example if the length of the queue needs to be bigger)

Queue is an array[1..10], this is how it was done for adding something.

If Queue[10] doesn't has a value and the signal to add value comes on then
move Queue[9] to Queue[10]
move Queue[8] to Queue[9]
move Queue[7] to Queue[8]
move Queue[6] to Queue[7]
move Queue[5] to Queue[6]
move Queue[4] to Queue[5]
move Queue[3] to Queue[4]
move Queue[2] to Queue[3]
move Queue[1] to Queue[2]
move New_value to Queue[1]

Now I should make this again but in STL (Step 7) and dynamic but I'm really struggling with the use of pointers.
I know you can put a variable into a pointer and calculate with it every loop.
As far as I can see, you first need to know how big the queue is minus 1 to aim for the ninth spot, but also needs to have the offset of a REAL (4 bytes) so u can move this value.

I don't see how i can write this out, hopefully someone can clear this out for me so i can get started and do the move up, down, etc. part on my own.

Thanks in advance!
 
Last edited:
There is plenty of useful information on Custom FIFO's and Stacks on the Siemens Automation forums.

https://support.industry.siemens.co...mming-fifo-and-lifo/177679?page=0&pageSize=10

You may need to increase/ decrease the internal arrays and data types- but certainly got the core logic you need to start.

Above is a nice STL Source you can use to get started...then once you understand more on the syntaxing; you can modify to suit your requirements.


Regards

Daniel.
 
Last edited:
Hello Daniel,

thanks for the quick response!

I'm going to try that source out, if i see it working i'm sure it will get me started.
Thank you for the example.

Regards.
 
Here's some tested example code based on the link above but uses an anypointer to allow different array sizes/locations to be passed in. (The code in the link is missing a SLD 3 for converting the byte address to an area address and will fail)
 
Hello!

Thank you very much for the example!
I want to try to make it in a more understandable way as I still don't really see how to do it.

I have been busy the whole day trying to make a working source, but somehow it doesn't work. Even research doesn't bring me much further.

I first need to clarify something. In my example above I misunderstood the concept FIFO as i tried a LIFO in FBD. Now I know I need to add new elements on the first free spot and not on the first place and move the rest of the data one further.

I wrote this code:

A # I_New_Element_Trigger // Input, New element in FIFO
FP # FP_I_New_Element_Trigger // TEMP, positive flank of input
JCN END

L # Count_Elements // INT in STAT, counting FIFO entries
T # Index // INT in STAT

L # Index
L 4 // Data in FIFO is always REAL value (4bytes)
*D
T # address // DINT in TEMP

OPN FIFO_Buffer // Opening the DB made for the queue with REAL's

L # I_FIFO_New_Element // var new REAL value for FIFO
T DBD [#address]

L # Counter_Elements
L 1
+I
T # Counter_Elements // Incrementing the counter with 1

NOP 0

END: BE

I thought this was the way to do it as there will always be looked at how many values there are in the FIFO so the new value can be added on the first free spot. Testing this gave me strange results, as the number i gave in only came through in the FIFO after 2 positive flanks and then started to change the number not desired.

Is it clear to see what I am doing wrong here because on this point I don't know how to get further. Thanks for all the feedback!

Regards
 
I copied and pasted your code into the Siemens editor.


If you wrote that code and executed it how come there are spaces between the # and your variables names?


Similarly, there are Count_Elements and Counter_Elements. Is this supposed to be one variable or two?



When I correct it and execute it, the correct number appears in the DB on the first rising edge edge (flank), but on the second rising edge the plc goes into STOP due to an alignment error.
If you have OB121 in your project/plc you should delete it so you will know that you have programming errors that you need to fix.


The rising edge storage bit needs to be a STAT not a TEMP as TEMP variables are not retained between calls (although for simple systems TEMP variables may be retained due to the the call stack not being overwritten)

code1.jpg
 
Thanks for the effort!

The spaces are there because it's not copied straight from the editor as I use another PC for that.

Same with count/counter_elements, it is 1 same variable that I mistyped when replying.

That's a good tip, OB121 was indeed present in my project. Also with the rising edge, now I know why I was having trouble with it.

Best regards.
 

Similar Topics

Hi, I have seen a few post with similar topics and I have tried contacting the authors however I have not had any luck so I am posting this new...
Replies
14
Views
1,011
Hi everyone I've created an FC that includes the blocks TCON, TDISCON, TSEND and TRCV. This block has to be as generic as possible across...
Replies
15
Views
1,515
Hi all, I have been working on a tool for my company that handles a specific task our company runs into often related to PLC's. This is a tool I...
Replies
15
Views
2,875
Hi, i need to make: 1- A PLC Program on Omron PLC CP2E-N using high speed counter E6C3-AG5B 360P/R 2M(Absolute) ,to Reject bottles on Conveyor...
Replies
4
Views
877
I was taught to go to Combined > Make Change > go to Offline > will prompt to save > Save > Exit out of program > will prompt to save again >...
Replies
0
Views
678
Back
Top Bottom