Страница 2 из 5 ПерваяПервая 1234 ... ПоследняяПоследняя
Показано с 11 по 20 из 48

Тема: FIFO (очередь) ПЛК110-60 MS4D

  1. #11

    По умолчанию

    Цитата Сообщение от Vadik2881 Посмотреть сообщение
    .. но тут нужно какое-то много канальное сравнение и пока затык.
    Правда у меня планируется более продвинутый алгоритм с выбором количества одновременного обслуживания.
    Может ТЗ более внятное озвучить?

  2. #12

    По умолчанию

    Ух спасибо Вам много всего, буду разбираться.
    ТЗ такое:
    32 цифровых входа и 32 цифровых выхода. Это 32 загрузчика сырья, если физически. Но все они на одном насосе и не могут одновременно обслуживаться, поэтому очередь. Первый пришёл, обслужился, ушёл, следующий. И хаотично навалом они тоже не могут, нужна именно чётко организованная очередь, один за одним.
    Тут предлагали алгоритм "кто первый встал того и тапки" но это совсем не то!

    Почему считаете, что мой вариант не FIFO?! Принцип как раз такой. Мы сейчас о принципе, а не конкретном операторе FiFO32 из библиотеки OSCAT.
    Мой вариант чётко отрабатывает вроде... Но нужна опция дополнительная, это количество одновременного обслуживания - до 3 абонентов или хотя бы до двух. И вот с моим вариантом это походу нереально сделать или не разобрался.
    Сейчас пробую это реализовать на MS4d по цепочке: конвертор булевого в целое - оператор FIFO32 - конвертер целого в булевое.
    Последний раз редактировалось Vadik2881; 07.02.2025 в 13:48.

  3. #13
    Пользователь Аватар для capzap
    Регистрация
    25.02.2011
    Адрес
    Киров
    Сообщений
    10,468

    По умолчанию

    Цитата Сообщение от Vadik2881 Посмотреть сообщение
    Первый пришёл, обслужился, ушёл, следующий.
    а если пока работает первый подключился второй, чтож его не обслуживать когда первый закончил или насос не будет останавливаться пока кто то есть в очереди, вернее пока очередь не пуста
    Bad programmers worry about the code. Good programmers worry about data structures and their relationships

    среди успешных людей я не встречала нытиков
    Барбара Коркоран

  4. #14

    По умолчанию

    Т.е. если бы насос справлялся, то можно было бы заправлять все 32 загрузчика?
    А так как можно только N-загрузчика одновременно, то следующим становиться под загрузку тот, кто приехал раньше из всех ожидающих?

    Предлагаю такой вариант:
    Owen.png
    Код:
    function_block Queue
        
        var_input
            I1, I2, I3, I4, I5, I6, I7, I8, I9, I10, I11, I12, I13, I14, I15, I16 : bool;
            I17, I18, I19, I20, I21, I22, I23, I24, I25, I26, I27, I28, I29, I30, I31, I32 : bool;
            N : udint;  // Сколько можно загружать одновременно
        end_var
        
        var_output 
            Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, Q10, Q11, Q12, Q13, Q14, Q15, Q16 : bool;
            Q17, Q18, Q19, Q20, Q21, Q22, Q23, Q24, Q25, Q26, Q27, Q28, Q29, Q30, Q31, Q32 : bool;
        end_var
        
        var 
            tr1, tr2, tr3, tr4, tr5, tr6, tr7, tr8, tr9, tr10, tr11, tr12, tr13, tr14, tr15, tr16 : SYS.RTRIG;
            tr17, tr18, tr19, tr20, tr21, tr22, tr23, tr24, tr25, tr26, tr27, tr28, tr29, tr30, tr31, tr32 : SYS.RTRIG;
            
            ts1, ts2, ts3, ts4, ts5, ts6, ts7, ts8, ts9, ts10, ts11, ts12, ts13, ts14, ts15, ts16 : dt;
            ts17, ts18, ts19, ts20, ts21, ts22, ts23, ts24, ts25, ts26, ts27, ts28, ts29, ts30, ts31, ts32 : dt;
            
            LoadCount : udint;      // Текущее количество под загрузкой
            nQ : udint;             // Следующий в очереди и время его прибытия
            minTime : dt;           // .. и время его прибытия
        end_var
    
        // Фиксируем прибытие в очередь
        tr1(I:=I1); tr2(I:=I2); tr3(I:=I3); tr4(I:=I4); tr5(I:=I5); tr6(I:=I6); tr7(I:=I7); tr8(I:=I8); 
        tr9(I:=I9); tr10(I:=I10); tr11(I:=I11); tr12(I:=I12); tr13(I:=I13); tr14(I:=I14); tr15(I:=I15); tr16(I:=I16); 
        tr17(I:=I17); tr18(I:=I18); tr19(I:=I19); tr20(I:=I20); tr21(I:=I21); tr22(I:=I22); tr23(I:=I23); tr24(I:=I24); 
        tr25(I:=I25); tr26(I:=I27); tr27(I:=I27); tr28(I:=I28); tr29(I:=I29); tr30(I:=I30); tr31(I:=I31);  tr31(I:=I32);
    
        // Фиксируем время прибытия
        if tr1.Q then ts1 := get_date_time(); end_if
        if tr2.Q then ts2 := get_date_time(); end_if
        if tr3.Q then ts3 := get_date_time(); end_if
        if tr4.Q then ts4 := get_date_time(); end_if
        if tr5.Q then ts5 := get_date_time(); end_if
        if tr6.Q then ts6 := get_date_time(); end_if
        if tr7.Q then ts7 := get_date_time(); end_if
        if tr8.Q then ts8 := get_date_time(); end_if
        if tr9.Q then ts9 := get_date_time(); end_if
        if tr10.Q then ts10 := get_date_time(); end_if
        if tr11.Q then ts11 := get_date_time(); end_if
        if tr12.Q then ts12 := get_date_time(); end_if
        if tr13.Q then ts13 := get_date_time(); end_if
        if tr14.Q then ts14 := get_date_time(); end_if
        if tr15.Q then ts15 := get_date_time(); end_if
        if tr16.Q then ts16 := get_date_time(); end_if
        if tr17.Q then ts17 := get_date_time(); end_if
        if tr18.Q then ts18 := get_date_time(); end_if
        if tr19.Q then ts19 := get_date_time(); end_if
        if tr20.Q then ts20 := get_date_time(); end_if
        if tr21.Q then ts21 := get_date_time(); end_if
        if tr22.Q then ts22 := get_date_time(); end_if
        if tr23.Q then ts23 := get_date_time(); end_if
        if tr24.Q then ts24 := get_date_time(); end_if
        if tr25.Q then ts25 := get_date_time(); end_if
        if tr26.Q then ts26 := get_date_time(); end_if
        if tr27.Q then ts27 := get_date_time(); end_if
        if tr28.Q then ts28 := get_date_time(); end_if
        if tr29.Q then ts29 := get_date_time(); end_if
        if tr30.Q then ts30 := get_date_time(); end_if
        if tr31.Q then ts31 := get_date_time(); end_if
        if tr32.Q then ts32 := get_date_time(); end_if
    
        // Фиксируем выход из под загрузки
        if not I1 then Q1 := false; end_if
        if not I2 then Q2 := false; end_if
        if not I3 then Q3 := false; end_if
        if not I4 then Q4 := false; end_if
        if not I5 then Q5 := false; end_if
        if not I6 then Q6 := false; end_if
        if not I7 then Q7 := false; end_if
        if not I8 then Q8 := false; end_if
        if not I9 then Q9 := false; end_if
        if not I10 then Q10 := false; end_if
        if not I11 then Q11 := false; end_if
        if not I12 then Q12 := false; end_if
        if not I13 then Q13 := false; end_if
        if not I14 then Q14 := false; end_if
        if not I15 then Q15 := false; end_if
        if not I16 then Q16 := false; end_if
        if not I17 then Q17 := false; end_if
        if not I18 then Q18 := false; end_if
        if not I19 then Q19 := false; end_if
        if not I20 then Q20 := false; end_if
        if not I21 then Q21 := false; end_if
        if not I22 then Q22 := false; end_if
        if not I23 then Q23 := false; end_if
        if not I24 then Q24 := false; end_if
        if not I25 then Q25 := false; end_if
        if not I26 then Q26 := false; end_if
        if not I27 then Q27 := false; end_if
        if not I28 then Q28 := false; end_if
        if not I29 then Q29 := false; end_if
        if not I30 then Q30 := false; end_if
        if not I31 then Q31 := false; end_if
        if not I32 then Q32 := false; end_if
    
        // Подсчитаем сколько сейчас под загрузкой
        LoadCount := 0;
        if Q1 then LoadCount := LoadCount + 1; end_if
        if Q2 then LoadCount := LoadCount + 1; end_if
        if Q3 then LoadCount := LoadCount + 1; end_if
        if Q4 then LoadCount := LoadCount + 1; end_if
        if Q5 then LoadCount := LoadCount + 1; end_if
        if Q6 then LoadCount := LoadCount + 1; end_if
        if Q7 then LoadCount := LoadCount + 1; end_if
        if Q8 then LoadCount := LoadCount + 1; end_if
        if Q9 then LoadCount := LoadCount + 1; end_if
        if Q10 then LoadCount := LoadCount + 1; end_if
        if Q11 then LoadCount := LoadCount + 1; end_if
        if Q12 then LoadCount := LoadCount + 1; end_if
        if Q13 then LoadCount := LoadCount + 1; end_if
        if Q14 then LoadCount := LoadCount + 1; end_if
        if Q15 then LoadCount := LoadCount + 1; end_if
        if Q16 then LoadCount := LoadCount + 1; end_if
        if Q17 then LoadCount := LoadCount + 1; end_if
        if Q18 then LoadCount := LoadCount + 1; end_if
        if Q19 then LoadCount := LoadCount + 1; end_if
        if Q20 then LoadCount := LoadCount + 1; end_if
        if Q21 then LoadCount := LoadCount + 1; end_if
        if Q22 then LoadCount := LoadCount + 1; end_if
        if Q23 then LoadCount := LoadCount + 1; end_if
        if Q24 then LoadCount := LoadCount + 1; end_if
        if Q25 then LoadCount := LoadCount + 1; end_if
        if Q26 then LoadCount := LoadCount + 1; end_if
        if Q28 then LoadCount := LoadCount + 1; end_if
        if Q29 then LoadCount := LoadCount + 1; end_if
        if Q30 then LoadCount := LoadCount + 1; end_if
        if Q31 then LoadCount := LoadCount + 1; end_if
        if Q32 then LoadCount := LoadCount + 1; end_if
    
        // Если можно поставить под зашрузку еще кого-то, то ..
        if LoadCount < N then
            minTime := get_date_time(); nQ := 0;    // Пока нет кандидата
            // Но если стоишь в очереди и еще не загружаешься и с временем меньше чем у кандитата, то становишься первым кандидатом
            if I1 and not Q1 and dt_to_udint(ts1) < dt_to_udint(minTime) then minTime := ts1; nQ := 1; end_if
            if I2 and not Q2 and dt_to_udint(ts2) < dt_to_udint(minTime) then minTime := ts2; nQ := 2; end_if
            if I3 and not Q3 and dt_to_udint(ts3) < dt_to_udint(minTime) then minTime := ts3; nQ := 3; end_if
            if I4 and not Q4 and dt_to_udint(ts4) < dt_to_udint(minTime) then minTime := ts4; nQ := 4; end_if
            if I5 and not Q5 and dt_to_udint(ts5) < dt_to_udint(minTime) then minTime := ts5; nQ := 5; end_if
            if I6 and not Q6 and dt_to_udint(ts6) < dt_to_udint(minTime) then minTime := ts6; nQ := 6; end_if
            if I7 and not Q7 and dt_to_udint(ts7) < dt_to_udint(minTime) then minTime := ts7; nQ := 7; end_if
            if I8 and not Q8 and dt_to_udint(ts8) < dt_to_udint(minTime) then minTime := ts8; nQ := 8; end_if
            if I9 and not Q9 and dt_to_udint(ts9) < dt_to_udint(minTime) then minTime := ts9; nQ := 9; end_if
            if I10 and not Q10 and dt_to_udint(ts10) < dt_to_udint(minTime) then minTime := ts10; nQ := 10; end_if
            if I11 and not Q11 and dt_to_udint(ts11) < dt_to_udint(minTime) then minTime := ts11; nQ := 11; end_if
            if I12 and not Q12 and dt_to_udint(ts12) < dt_to_udint(minTime) then minTime := ts12; nQ := 12; end_if
            if I13 and not Q13 and dt_to_udint(ts13) < dt_to_udint(minTime) then minTime := ts13; nQ := 13; end_if
            if I14 and not Q14 and dt_to_udint(ts14) < dt_to_udint(minTime) then minTime := ts14; nQ := 14; end_if
            if I15 and not Q15 and dt_to_udint(ts15) < dt_to_udint(minTime) then minTime := ts15; nQ := 15; end_if
            if I16 and not Q16 and dt_to_udint(ts16) < dt_to_udint(minTime) then minTime := ts16; nQ := 16; end_if
            if I17 and not Q17 and dt_to_udint(ts17) < dt_to_udint(minTime) then minTime := ts17; nQ := 17; end_if
            if I18 and not Q18 and dt_to_udint(ts18) < dt_to_udint(minTime) then minTime := ts18; nQ := 18; end_if
            if I19 and not Q19 and dt_to_udint(ts19) < dt_to_udint(minTime) then minTime := ts19; nQ := 19; end_if
            if I20 and not Q20 and dt_to_udint(ts20) < dt_to_udint(minTime) then minTime := ts20; nQ := 20; end_if
            if I21 and not Q21 and dt_to_udint(ts21) < dt_to_udint(minTime) then minTime := ts21; nQ := 21; end_if
            if I22 and not Q22 and dt_to_udint(ts22) < dt_to_udint(minTime) then minTime := ts22; nQ := 22; end_if
            if I23 and not Q23 and dt_to_udint(ts23) < dt_to_udint(minTime) then minTime := ts23; nQ := 23; end_if
            if I24 and not Q24 and dt_to_udint(ts24) < dt_to_udint(minTime) then minTime := ts24; nQ := 24; end_if
            if I25 and not Q25 and dt_to_udint(ts25) < dt_to_udint(minTime) then minTime := ts25; nQ := 25; end_if
            if I26 and not Q26 and dt_to_udint(ts26) < dt_to_udint(minTime) then minTime := ts26; nQ := 26; end_if
            if I27 and not Q27 and dt_to_udint(ts27) < dt_to_udint(minTime) then minTime := ts27; nQ := 27; end_if
            if I28 and not Q28 and dt_to_udint(ts28) < dt_to_udint(minTime) then minTime := ts28; nQ := 28; end_if
            if I29 and not Q29 and dt_to_udint(ts29) < dt_to_udint(minTime) then minTime := ts29; nQ := 29; end_if
            if I30 and not Q30 and dt_to_udint(ts30) < dt_to_udint(minTime) then minTime := ts30; nQ := 30; end_if
            if I31 and not Q31 and dt_to_udint(ts31) < dt_to_udint(minTime) then minTime := ts31; nQ := 31; end_if
            if I32 and not Q32 and dt_to_udint(ts32) < dt_to_udint(minTime) then minTime := ts32; nQ := 32; end_if
            
            // Если найден подходящий кандидат, то включаем его под загрузку
            case nQ of
                1: Q1 := true;
                2: Q2 := true;
                3: Q3 := true;
                4: Q4 := true;
                5: Q5 := true;
                6: Q6 := true;
                7: Q7 := true;
                8: Q8 := true;
                9: Q9 := true;
                10: Q10 := true;
                11: Q11 := true;
                12: Q12 := true;
                13: Q13 := true;
                14: Q14 := true;
                15: Q15 := true;
                16: Q16 := true;
                17: Q17 := true;
                18: Q18 := true;
                19: Q19 := true;
                20: Q20 := true;
                21: Q21 := true;
                22: Q22 := true;
                23: Q23 := true;
                24: Q24 := true;
                25: Q25 := true;
                26: Q26 := true;
                27: Q27 := true;
                28: Q28 := true;
                29: Q29 := true;
                30: Q30 := true;
                31: Q31 := true;
                32: Q32 := true;
            end_case
            
        end_if
    
    end_function_block
    В вашем случае идет подсчет времени ожидания и, в принципе, вход с наибольшим накопленным временем тоже кандидат.
    Только потребуется схема выборки кандидатов под загрузку. В принципе это можно реализовать и без ST.

    FIFO здесь не подойдет, т.к. здесь есть возможность выйти из очереди не дождавшись загрузки.
    Последний раз редактировалось EFrol; 07.02.2025 в 15:45.

  5. #15
    Пользователь
    Регистрация
    27.11.2011
    Адрес
    Краснодар
    Сообщений
    12,325

    По умолчанию

    Vadik2881 з.ы. не смотрел, но цифра 32 это всего 6 битов. Вам кто-то мешает в одной 32-х битной переменной создать "массив" до 5-ти номеров одновременно?

    ой, вы тут не номерами оперируете я так понял, а битами даже. Хоть все 32-а устройства (бита) в одну очередь пихайте.
    Последний раз редактировалось melky; 07.02.2025 в 15:12.

  6. #16

    По умолчанию

    Не ну EFrol конечно крут, то что надо!!! Спасибо огромное. Действительно, здесь же возможен выход из очереди досрочный и FIFO не подходит.
    И самое главное не сильно сложно получилось.
    Последний раз редактировалось Vadik2881; 07.02.2025 в 16:38.

  7. #17
    Пользователь Аватар для capzap
    Регистрация
    25.02.2011
    Адрес
    Киров
    Сообщений
    10,468

    По умолчанию

    Цитата Сообщение от EFrol Посмотреть сообщение
    FIFO здесь не подойдет, т.к. здесь есть возможность выйти из очереди не дождавшись загрузки.
    Всегда можно пересобрать очередь, тут главное в основе использовать готовые блоки, а не придумывать что то свое, которое даже не представляется возможным как тестировать
    Bad programmers worry about the code. Good programmers worry about data structures and their relationships

    среди успешных людей я не встречала нытиков
    Барбара Коркоран

  8. #18

    По умолчанию

    Цитата Сообщение от Vadik2881 Посмотреть сообщение
    Ребята, ну вроде кое что удалось сделать. Сидел долго, даже ST пришлось немного освоить. Кстати крутая штука, но для сложных проектов...
    Гляньте проект. Очередь сделал как и хотел - на принципе измерения времени ожидания, т.е. первый проходит у кого оно больше. И достаточно не сложный алгоритм.
    Кому не лень, протестируйте пожалуйста на баги. Основной затык был в операторе сравнения на 3 и более входа. И получилось это только в ST!!!
    Я тут маленько допилил Ваш вариант.
    Вложения Вложения
    • Тип файла: owle Queue.owle (138.3 Кб, Просмотров: 3)

  9. #19

    По умолчанию

    Не ну нет слов. Работает. Спасибо EFrol!!!
    Единственное, я твой первый алгоритм пытаюсь в MS4d, пока со скрипом...
    Второй вариант видимо проще будет.
    Ответь в личном, пожалуйста.

  10. #20

    По умолчанию

    Макрос MAX можно переписать под FBD:
    Owen1.jpg
    где MaxVN:
    Owen2.jpg

Страница 2 из 5 ПерваяПервая 1234 ... ПоследняяПоследняя

Похожие темы

  1. Сокеты на ПЛК110 MS4D
    от Спорягин Кирилл в разделе ПЛК (среда MasterSCADA 4D)
    Ответов: 12
    Последнее сообщение: 20.01.2023, 16:06
  2. ПЛК110 MS4D и МЭ110-1М
    от win2014 в разделе ПЛК (среда MasterSCADA 4D)
    Ответов: 8
    Последнее сообщение: 18.12.2019, 15:10
  3. ПЛК110 MS4D + ПМ210
    от KrAssor в разделе ПЛК (среда MasterSCADA 4D)
    Ответов: 9
    Последнее сообщение: 31.05.2019, 13:33
  4. ПЛК110 MS4D + ПМ01
    от Спорягин Кирилл в разделе ПЛК (среда MasterSCADA 4D)
    Ответов: 2
    Последнее сообщение: 30.05.2019, 21:27
  5. Очередь Fifo для передачи на пк
    от gr_vl в разделе ПЛК1хх
    Ответов: 1
    Последнее сообщение: 24.12.2010, 22:54

Ваши права

  • Вы не можете создавать новые темы
  • Вы не можете отвечать в темах
  • Вы не можете прикреплять вложения
  • Вы не можете редактировать свои сообщения
  •