I helped me self after days i have this:
Summary:
When the delivery stations at the ore-receiving train stations are full, no trains should arrive, even if the main storage is empty.
Explanation of what the facility is:
A facility to split and sort core ore (bottom left in the picture) and transport it to the mass storage for ores (bottom right in the picture). There are also train stations connected at the top and, not visible here, large cargo ships that also deliver ores on the top left.
If the ore processing facility overproduces certain ores, it stops and blocks the entire production, which is why a completely full storage of a single ore needs to be prevented! This ore is then destroyed (not shown in the picture).
To avoid wasting ores from natural ore fields, I needed the following circuit:
01 First, check how much ore of each raw material is in the main storage.
02 Trains and ships should only deliver in case of emergency when there is insufficient ore processing, and the main storage has fallen below 250.000 of that ore.
03 The delivery box must be empty enough for an incoming train to unload its entire load! (The delivery box can contain different ores at the same time).
After much thought, testing, and experimentation, I have been able to achieve this with the following circuit.
On the left, the input box is asked by a mathematical comparator if it is fuller than 9.000.
This number is composed as follows:
(500 slots from the box * 50 #stack size of ore) = 25.000
(8 wagons * 40 stacks per wagon * 50 #stack size of ore) = 16.000)
25.000 - 16.000 = 9.000
If there are more than 9.000, then output a red signal with a value of 1.
This signal then goes into a second mathematical comparator.
If a red signal with 1 arrives, this number is multiplied by 5.000.000 (this number must be higher than the number with which you want to allow LTN to deliver the resource – in my case, I could also say 250.000, but I prefer millions to make it more universally applicable when copying – so I always make sure it's always too much for LTN and say LTN clearly NO, NO TRAIN!
Then I output the ore as the output signal that could arrive.
Unfortunately, you need to set up a separate mathematical comparator for each commodity that arrives by train at this station (in my case, two below each other).
I added the last mathematical comparator only to prevent feedback with the main storage.
(You don't need this if you place the individual storages separately at different stations. For space reasons, I have all 25 different ores with the same green cable wired together at my place (nickel, tin, aluminum, titanium...), so I need this feedback protection).
I hope the two hours I invested in the pictures, text, and translation will help or inspire someone.
(Download or if you are at the site from ibb rightclick and picture in seperate tab - first than you can zoomed in with strg + mousewheel)