Process Analyst: define start time in Cicode

I want to set Time Picker value in process analyst in citect scada using cicode.

I try with this function TrnSetTime without sucess.

Thank you per advance.

Parents
  • Hi fassiri,

    To set the time span in the Process Analyst you need to use its automation model.

    1. On your Process Analyst Page, given your PA an Object Name (e.g. CPA) . Properties > Access > Identification.
    2. Write a cicode function to set the time span of a pen using "IPen.PutHorizontalAxisTimeSpan" (search in help for example)

    You will note the example has a parameter "OBJECT hPen". The PA uses an object oriented automation model, so you need to traverse the hierarchy to get to the pen. PA > Panes > Pane > Pens > Pen.

    I've typed up some code below, which shows the general method.

    Note: I typed this in directly to the forum, and have not compiled and tested it.

    The function will set all the pens in the first pane of your process analyst to have the span hardcoded in the function.
    You can call the function from a standard Citect button if you want to test. Set a breakpoint in it, and use the Cicode Debugger to step through the code.

    FUNCTION MyPA_SetSpan()

    OBJECT oProcessAnalyst;
    OBJECT oPanes;
    OBJECT oPane;
    OBJECT oPens;
    OBJECT oPen;
    INT nPenCount;
    INT nPenIndex;
    REAL startDate;
    REAL endDate;

    startDate = StrToDate("10/6/19") + StrToTime("9:00:00");
    endDate = StrToDate("14/6/19") + StrToTime("10:00:00");
    startDate = TimeToOLEDate(startDate, 0); // Convert to UTC
    endDate = TimeToOLEDate(endDate, 0); // Convert to UTC

    oProcessAnalyst = ObjectByName("CPA");
    oPanes = _ObjectGetProperty(oProcessAnalyst, "Panes")
    IF ObjectIsValid(oPanes) THEN
    oPane = _ObjectCallMethod(oPanes, "get_Item", 1); // get Pane 1
    IF ObjectIsValid(oPane) THEN
    oPens = _ObjectGetProperty(oPane, "Pens");
    IF ObjectIsValid(oPens) THEN
    nPenCount = _ObjectGetProperty(oPens, "Count");
    FOR nPenIndex = 0 TO nPenCount - 1 DO
    oPen = _ObjectCallMethod(oPens, "get_Item", (nPenIndex + 1));
    _ObjectcallMethod(oPen, "PutHorizontalAxisTimeSpan", startDate, 0, endDate, 0);
    END
    END
    END
    END

    END

Reply
  • Hi fassiri,

    To set the time span in the Process Analyst you need to use its automation model.

    1. On your Process Analyst Page, given your PA an Object Name (e.g. CPA) . Properties > Access > Identification.
    2. Write a cicode function to set the time span of a pen using "IPen.PutHorizontalAxisTimeSpan" (search in help for example)

    You will note the example has a parameter "OBJECT hPen". The PA uses an object oriented automation model, so you need to traverse the hierarchy to get to the pen. PA > Panes > Pane > Pens > Pen.

    I've typed up some code below, which shows the general method.

    Note: I typed this in directly to the forum, and have not compiled and tested it.

    The function will set all the pens in the first pane of your process analyst to have the span hardcoded in the function.
    You can call the function from a standard Citect button if you want to test. Set a breakpoint in it, and use the Cicode Debugger to step through the code.

    FUNCTION MyPA_SetSpan()

    OBJECT oProcessAnalyst;
    OBJECT oPanes;
    OBJECT oPane;
    OBJECT oPens;
    OBJECT oPen;
    INT nPenCount;
    INT nPenIndex;
    REAL startDate;
    REAL endDate;

    startDate = StrToDate("10/6/19") + StrToTime("9:00:00");
    endDate = StrToDate("14/6/19") + StrToTime("10:00:00");
    startDate = TimeToOLEDate(startDate, 0); // Convert to UTC
    endDate = TimeToOLEDate(endDate, 0); // Convert to UTC

    oProcessAnalyst = ObjectByName("CPA");
    oPanes = _ObjectGetProperty(oProcessAnalyst, "Panes")
    IF ObjectIsValid(oPanes) THEN
    oPane = _ObjectCallMethod(oPanes, "get_Item", 1); // get Pane 1
    IF ObjectIsValid(oPane) THEN
    oPens = _ObjectGetProperty(oPane, "Pens");
    IF ObjectIsValid(oPens) THEN
    nPenCount = _ObjectGetProperty(oPens, "Count");
    FOR nPenIndex = 0 TO nPenCount - 1 DO
    oPen = _ObjectCallMethod(oPens, "get_Item", (nPenIndex + 1));
    _ObjectcallMethod(oPen, "PutHorizontalAxisTimeSpan", startDate, 0, endDate, 0);
    END
    END
    END
    END

    END

Children
No Data