Не уверен, что правильно понял задание. Предлагаю свою версию решения, если Вы сможете разобраться и перенести в CDS.
Queue.jpg
Код:
function_block Queue
var_input
i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13, i14, i15, i16 : bool; // true - нужна загрузка, false - уже не нужна
end_var
var_output
Q : udint; // Номер бункера под загрузкой, 0 - очередь пуста
end_var
var
In, Fix : udint; // Номер встающего в очередь c фиксацией
Dim : array [1..16] of udint; // Очередь в виде массива
Free : udint; // Свободное место
end_var
// Ставим в очередь запросившего загрузку
In := 0;
if i1 and not Fix.0 then In := 1; Fix.0 := true;
elsif i2 and not Fix.1 then In := 2; Fix.1 := true;
elsif i3 and not Fix.2 then In := 3; Fix.2 := true;
elsif i4 and not Fix.3 then In := 4; Fix.3 := true;
elsif i5 and not Fix.4 then In := 5; Fix.4 := true;
elsif i6 and not Fix.5 then In := 6; Fix.5 := true;
elsif i7 and not Fix.6 then In := 7; Fix.6 := true;
elsif i8 and not Fix.7 then In := 8; Fix.7 := true;
elsif i9 and not Fix.8 then In := 9; Fix.8 := true;
elsif i10 and not Fix.9 then In := 10; Fix.9 := true;
elsif i11 and not Fix.10 then In := 11; Fix.10 := true;
elsif i12 and not Fix.11 then In := 12; Fix.11 := true;
elsif i13 and not Fix.12 then In := 13; Fix.12 := true;
elsif i14 and not Fix.13 then In := 14; Fix.13 := true;
elsif i15 and not Fix.14 then In := 15; Fix.14 := true;
elsif i16 and not Fix.15 then In := 16; Fix.15 := true;
end_if
if In > 0 then // Есть очередной желающий
// Ищем свободное место в очереди и ставим его в очередь
for Free := 1 to 16 do
if Dim[Free] = 0 then
Dim[Free] := In; exit;
end_if
end_for
end_if
// Выбрасываем из очереди, если загрузка уже не требуется
In := 0;
if not i1 and Fix.0 then In := 1; Fix.0 := false;
elsif not i2 and Fix.1 then In := 2; Fix.1 := false;
elsif not i3 and Fix.2 then In := 3; Fix.2 := false;
elsif not i4 and Fix.3 then In := 4; Fix.3 := false;
elsif not i5 and Fix.4 then In := 5; Fix.4 := false;
elsif not i6 and Fix.5 then In := 6; Fix.5 := false;
elsif not i7 and Fix.6 then In := 7; Fix.6 := false;
elsif not i8 and Fix.7 then In := 8; Fix.7 := false;
elsif not i9 and Fix.8 then In := 9; Fix.8 := false;
elsif not i10 and Fix.9 then In := 10; Fix.9 := false;
elsif not i11 and Fix.10 then In := 11; Fix.10 := false;
elsif not i12 and Fix.11 then In := 12; Fix.11 := false;
elsif not i13 and Fix.12 then In := 13; Fix.12 := false;
elsif not i14 and Fix.13 then In := 14; Fix.13 := false;
elsif not i15 and Fix.14 then In := 15; Fix.14 := false;
elsif not i16 and Fix.15 then In := 16; Fix.15 := false;
end_if
if In > 0 then // Есть вышедший из очереди
// Ищем его место в очереди
for Free := 1 to 16 do
if Dim[Free] = In then exit; end_if
end_for
// Сдвигаем оставшуюся очередь
while Free < 16 do
Dim[Free] := Dim[Free + 1]; Free := Free + 1;
end_while
Dim[Free] := 0; // Последнее место в очереди освобождается точно
end_if
Q := Dim[1]; // Первый в очереди стоит под загрузкой
end_function_block