[r1]: / XYChartProgrammingMode.project  Maximize  Restore  History

Download this file

257 lines (215 with data), 2.7 MB

-------------------------------------------------------------------------------
VisuSync
-------------------------------------------------------------------------------

                   Counter that runs in parallel with the "Visu" cycle


PROGRAM VisuSync

VAR_INPUT
    udiCycleCounter: UDINT;
END_VAR
udiCycleCounter := udiCycleCounter +1;

VAR
    ix: INT;
END_VAR
// Clean up the arrays
FOR ix := 1 TO 100 BY 1 DO
    Prog.DataX1[ix]  := 0.0 ;
    Prog.DataY1[ix]  := 0.0 ;
END_FOR
   
// Set deualt data   
Prog.DataX1[1] := -10.0 ;
Prog.DataX1[2] := 20.0 ;
Prog.DataX1[3] := 30.0 ;
Prog.DataX1[4] := 40.0 ;
Prog.DataX1[5] := 50.0 ;  
Prog.DataX1[6] := 60.0 ;  
Prog.DataX1[7] := 70.0 ;  
Prog.DataX1[8] := 80.0 ;  
Prog.DataX1[9] := 90.0 ;  
Prog.DataX1[10] := 100.0 ;  

Prog.DataY1[1] := 10.0 ;
Prog.DataY1[2] := 20.0 ;
Prog.DataY1[3] := 10.0 ;
Prog.DataY1[4] := 30.0 ;
Prog.DataY1[5] := 10.0 ;
Prog.DataY1[6] := 40.0 ;
Prog.DataY1[7] := 10.0 ;
Prog.DataY1[8] := 50.0 ;
Prog.DataY1[9] := 10.0 ;
Prog.DataY1[10] := 60.0 ;




-------------------------------------------------------------------------------
Prog
-------------------------------------------------------------------------------


PROGRAM Prog

VAR_INPUT
    xyChart: VisuStructXYChart;
    AxisX: VisuStructXYChartAxis;
    AxisY1: VisuStructXYChartAxis;
    Curve1: VisuStructXYChartCurve;
    DataX1: ARRAY [..] OF ;
    DataY1: ARRAY [..] OF ;
    iCurve1ProgType: INT;
    xProgCurve1: BOOL;
    xProgOff: BOOL;
    xProgSave: BOOL;
    xProgUndoS: BOOL;
    xProgUndo: BOOL;
    xSetOrigCurve: BOOL;
    sProgClient: string;
    xProgMode: BOOL;
    xChangePending: BOOL;
    udiCycleCounter: UDINT;
END_VAR

VAR
    xInitDone: BOOL;
    SVxyChart: VisuStructXYChart;
    SVAxisX: VisuStructXYChartAxis;
    SVAxisY1: VisuStructXYChartAxis;
    SVCurve1: VisuStructXYChartCurve;
    xDoIt: BOOL;
    xDelayProgCurve1: BOOL;
    xDelayProgOff: BOOL;
    xDelayProgSave: BOOL;
    rTrigProgCurve1: R_TRIG;
    rTrigProgOff: R_TRIG;
    rTrigOrig: R_TRIG;
    rTrigUndoS: R_TRIG;
    rTrigUndo: R_TRIG;
    rTrigSave: R_TRIG;
END_VAR
(**********************************************************************************************
   The scope of this application is to show how to use XYChart element in programming mode.
   It simply shows a predefine curve that the user can modify or completely make from scratch.
***********************************************************************************************)


//------------------------------------------------------------------
// During the first entry we do some initial activities
IF NOT xInitDone THEN
   IF ABS(VisuSync.udiCycleCounter - udiCycleCounter) > 2 THEN    // Valid when "Visu" is running
      // We save the initial element configuration for further uses
      SVxyChart := xyChart;
      SVAxisX   := AxisX;
      SVAxisY1  := AxisY1;
      SVCurve1  := Curve1;

      // We limit the use of the array
      Curve1.diIndexMin := 1 ;        
      Curve1.diIndexMax := 10 ;
      
      FctSetDefaultDataCurve();  // Set default data for curves   
      
      xInitDone := TRUE;         // done
   ELSE
      RETURN ;                   // We will do nothing if we don't' have the correct data          
	END_IF
END_IF


//------------------------------------------------------------------
// We start the programming on curve 
rTrigProgCurve1(CLK:=xProgCurve1, Q=>xDoIt);
IF xDoIt THEN
   xProgCurve1 := FALSE;
   rTrigProgCurve1(CLK:=xProgCurve1, Q=>xDoIt);
   IF xyChart.xProgMode = FALSE THEN                              // If it's not already in programming mode
      xyChart.wsFocus := SVCurve1.wsCvName;                       // We need to inform the element, what's the curve that has the focus 
      IF iCurve1ProgType = 0 THEN
         xyChart.eProg := VisuEnumXYChartProgType.MODIFY;         // We inform the element to enter in programming mode for exixting curve modification
      ELSE   
         xyChart.eProg := VisuEnumXYChartProgType.NEW_CURVE;      // We inform the element to enter in programming mode for a new curve modify
      END_IF
      udiCycleCounter  := VisuSync.udiCycleCounter;               // We save the actual cycle counter 
      xDelayProgCurve1 := TRUE;
   END_IF
END_IF

// We wait some cycles before to act in programming mode,
// to give to the element the time to activate the programming mode
IF xDelayProgCurve1 THEN
   IF xyChart.xProgMode THEN                                            // Command has been executed
      xDelayProgCurve1       := FALSE;
      Curve1.ePointStyle     := VisuEnumXYChartPointStyle.DOT;          // We set the visualization of the line using also dot  
      xyChart.eFocusDisplay  := VisuEnumXYChartFocusType.FOC_REV_COL;   // We show the axis that has the focus, with reverse colors on numbers
      xyChart.diCursorColorM := VisuElemXYChart.COLOR.Red;              // We change the color of the cursor
	ELSE
      IF ABS(VisuSync.udiCycleCounter - udiCycleCounter) > 100 THEN
         xDelayProgCurve1 := FALSE;                                     // Something went wrong 
      END_IF
   END_IF
END_IF


//------------------------------------------------------------------
// We stop the programming
rTrigProgOff(CLK:=xProgOff, Q=>xDoIt);
IF xDoIt THEN
   xProgOff := FALSE;
   rTrigProgOff(CLK:=xProgOff, Q=>xDoIt);
   xyChart.eProg   := VisuEnumXYChartProgType.NO;    // We inform the element to stop the programming mode for a new curve modify 
   udiCycleCounter := VisuSync.udiCycleCounter;      // We save the actual cycle counter 
   xDelayProgOff   := TRUE;
END_IF

// We wait some cycles before to exit from programming mode,
// to give to the element the time to update the visualization
IF xDelayProgOff THEN
   IF NOT xyChart.xProgMode THEN                                  // Command has been executed
      xDelayProgOff          := FALSE;
      Curve1.ePointStyle     := SVCurve1.ePointStyle;             // We change it to the original one
      xyChart.wsFocus        := SVCurve1.wsCvName;                // We set the focus as default on curve1 
      xyChart.eFocusDisplay  := SVxyChart.eFocusDisplay;          // We change it to the original one
      xyChart.diCursorColorM := SVxyChart.diCursorColorM;         // We change it to the original one    
	ELSE
      IF ABS(VisuSync.udiCycleCounter - udiCycleCounter) > 100 THEN
         xDelayProgOff := FALSE;                                  // Something went wrong 
      END_IF
   END_IF
END_IF


//------------------------------------------------------------------
// We save the curve 
rTrigSave(CLK:=xProgSave, Q=>xDoIt);
IF xDoIt THEN
   xProgSave := FALSE;
   rTrigSave(CLK:=xProgSave, Q=>xDoIt);
   xyChart.eCommand := VisuEnumXYChartCommands.PRG_SAVE;          // We inform the element to save the curvestop the programming mode for a new curve modify
   udiCycleCounter := VisuSync.udiCycleCounter;                   // We save the actual cycle counter 
   xDelayProgSave := TRUE;
END_IF

// We wait some cycles,
// to give to the element the time to save all the data
IF xDelayProgSave THEN
   IF xyChart.eCommand = VisuEnumXYChartCommands.NO THEN   // Command has been executed
      xDelayProgSave := FALSE;
      xProgOff := TRUE;                                    // We will do the same operations like programming off 
	ELSE
      IF ABS(VisuSync.udiCycleCounter - udiCycleCounter) > 100 THEN
         xDelayProgSave := FALSE;                          // Something went wrong 
      END_IF
   END_IF
END_IF


//------------------------------------------------------------------
// Undo single point 
rTrigUndoS(CLK:=xProgUndoS, Q=>xDoIt);
IF xDoIt THEN
   xProgUndoS := FALSE;
   rTrigUndoS(CLK:=xProgUndoS, Q=>xDoIt);
   xyChart.eCommand := VisuEnumXYChartCommands.PRG_UNDO;
END_IF


//------------------------------------------------------------------
// Undo all 
rTrigUndo(CLK:=xProgUndo, Q=>xDoIt);
IF xDoIt THEN
   xProgUndo := FALSE;
   rTrigUndo(CLK:=xProgUndo, Q=>xDoIt);
   xyChart.eCommand := VisuEnumXYChartCommands.PRG_UNDO_ALL;
END_IF


//------------------------------------------------------------------
// Set original curve 
rTrigOrig(CLK:=xSetOrigCurve, Q=>xDoIt);
IF xDoIt THEN
   xSetOrigCurve := FALSE;
   rTrigOrig(CLK:=xSetOrigCurve, Q=>xDoIt);

   // We set all the data as the original   
   xyChart := SVxyChart;
   AxisX   := SVAxisX;
   AxisY1  := SVAxisY1;
   Curve1  := SVCurve1;

   // We limit the use of the array
   Curve1.diIndexMin := 1 ;        
   Curve1.diIndexMax := 10 ;
   
   FctSetDefaultDataCurve();  // Set default data for curves   
END_IF


//------------------------------------------------------------------
// On line situation 
sProgClient := VisuElemXYChart.VisuFctGetClientName(xyChart.eClientProg);     // On which client programming is active
xProgMode := xyChart.xProgMode;                                               // Element is in programming mode
xChangePending := xyChart.xChangePending;                                     // Change is pending