希望根据运行时间和行程来运行19台电机


FOR #index := 0 TO 9 DO
// Increase working time count if the pump is active
IF #PumpActiveSignal[#index] = true THEN
IF #M_Clockbit1s = true THEN // memory clock that switches on every second
IF #LoopOnce[#index] = false THEN // execute this on a positive edge of the memoryclockbit
#WorkingTimes[#index]."Time" := #WorkingTimes[#index]."Time" + 1; // increase the working time
#LoopOnce[#index] := true;
END_IF;
ELSE
#LoopOnce[#index] := false;
END_IF;
END_IF;
END_FOR;
// move working times to list that needs to be ordered
FOR #k := 0 TO 9 DO
#OrdenedList[#k] := #WorkingTimes[#k]."Time";
END_FOR;
// Order working times, lowest to highest
FOR #i := 0 TO 9 DO
FOR #j := #i + 1 TO 9 DO
IF #OrdenedList[#i] > #OrdenedList[#j] THEN
#temp1 := #OrdenedList[#i];
#OrdenedList[#i] := #OrdenedList[#j];
#OrdenedList[#j] := #temp1;
END_IF;
END_FOR;
END_FOR;
IF #CHNGOVER = 1 THEN
// assign priority number according to working times
FOR #l := 0 TO 9 DO
#WorkingTimes[#l].PriorityNo := -1;
END_FOR;
FOR #m := 0 TO 9 DO
FOR #l := 0 TO 9 DO
IF #OrdenedList[#m] = #WorkingTimes[#l]."Time" AND #WorkingTimes[#l].PriorityNo = -1 THEN
#WorkingTimes[#l].PriorityNo := #m;
EXIT;
END_IF;
END_FOR;
END_FOR;
END_IF;

///有了这个逻辑,我试图在tia门户中为一个项目制作逻辑。逻辑中的要求如下:**根据较少的运行时间进行切换。**在2小时的时间周期后,将发生一个变化,使运行时间较短的电机首先启动。**而且我想在逻辑中添加跳闸状态,这样由于上述逻辑,跳闸电机不应该进入运行逻辑。

从所附的代码中,我真的无法理解你试图用#WorkingTimes[#l].PriorityNo和我不知道在其他逻辑中是如何评估它的。

但是。。。以下是一些要点:

  • 您应该使用更结构化的方法。例如,我会为泵制作一系列结构(具有构件"活动"、"跳闸"、"工作时间"…(
  • 没有必要在每个PLC周期评估所有内容。这需要时间!对于泵的应用,在大多数情况下,1秒的时间段是可以的
  • 在我看来,最好以这样的方式构建任务,以便我们将来可以重用一些数据

这里是我的代码版本:(:

IF #M_Clockbit1s AND NOT #M_EdgeDetect THEN // execute this on a positive edge of     the memoryclockbit
// Increase working time count if the pump is active
FOR #index := 0 TO 9 DO
IF #Pumps[#index].Active THEN 
#Pumps[#index].WorkingTimes +=1; // increase the working time 
END_IF;
END_FOR;
// next - it would be good to know how many alailable pumps we have (not tripped) and write them to the start order array
//
#AvailPump := 0;
//
FOR #k := 0 TO 9 DO
IF NOT #Pumps[#k].Tripped THEN
#PumpOrder[#AvailPump] := #k;
#AvailPump +=1;
END_IF;
END_FOR;
// I like to have the things so. -1 means no pump available for this array element. Not used right now, but might be needed someday :)
//
IF #AvailPump < 9 THEN
FOR #m := #AvailPump + 1 TO 9 DO
#PumpOrder[#m] := -1;
END_FOR;
END_IF;
// now we can sort our array to determine which pump has to be started next time.
//
IF #AvailPump > 0 THEN
FOR #i := 0 TO #AvailPump DO
FOR #j := #i + 1 TO #AvailPump DO
IF  #Pumps[#PumpOrder[#i]].WorkingTimes >  #Pumps[#PumpOrder[#j]].WorkingTimes THEN
#temp1 := #PumpOrder[#i];
#PumpOrder[#i] := #PumpOrder[#j];
#PumpOrder[#j] := #temp1;
END_IF;
END_FOR;
END_FOR;
END_IF;
// now in PumpOrder[0] you have the pump number with the least running time, in PumpOrder[1] the pump number with the second least and so on...
//
// here the closing end_if - so we evaluate the data every second and not every cycle
END_IF;
#M_EdgeDetect := #M_Clockbit1s;

最新更新