Tuesday, October 30, 2012

Cicode- SCADA


/*This function will draw a scale to the left of a Bar near the X Y location the calling Advanced Animation with the following command IF StrToInt(PageInfo(7))=0 THEN Scale1();END
Color = Color number of the Scale (see Help - Color Names and Numbers)
Div   = Number of Divisions to place on the Scale*/


FUNCTION
_DspBarScale(String sColor="Black",INT Div=5)

    INT     hAn;
    INT hPlot;
    INT X;
    INT Y;
    INT Top;
    INT Left;
    INT Bottom;
    INT Right;
    INT AN;
    INT I;
    INT PlotAn;

    AN=DspGetAnCur();                   !Get Calling An
    DspAnGetPos(AN, X, Y);                  !Get position of Calling An
    hAn=DspGetNearestAn(X, Y)
    WHILE (DspAnInfo(hAn, 0) <> "2") AND (I < 60) DO    !Check if bar found within 60 Pixels
        I=I+1;
        hAn=DspGetNearestAn(X+I, Y);            !Get handle of nearest An
    END
    IF DspAnInfo(hAn, 0)= "2" THEN              !Check if bar found
       
        DspGetAnExtent(hAn, Top, Left, Bottom, Right);      !Get boundary of Nearest An
        PlotAn = DspAnNewRel(hAn, -5, 0);               !Creat new An
        hPlot = PlotOpen(PlotAn, "Display", 1);
        PlotGrid(hPlot, 2, 0, Top-Bottom, 2, 0, 1, Transparent, 1, Transparent, 1, Dark_Grey, Transparent, 0);
        PlotScaleMarker(hPlot, 0, 0, Div, 1, sColor, 1);
        PlotClose(hPlot);
    ELSE
        prompt("@(Scale-can't find bar)");
    END
END

Cicode -SCADA

/*This function will save the Tag associations on an existing Super Genie, Close the window then assign the tags to a new window. This allows a Super Genie Popup to
call another popup and close the parent popup.*/ 


INT
FUNCTION
AssChainWinFree(STRING sPage, INT x, INT y, INT Mode)

    AssChain(-2, WinNumber(), 0);
    WinFree();
    IF WinNewAt(sPage, x, y, mode) = -1 THEN
        RETURN 269;
    ELSE
        RETURN 0;
    END
END

Cicode- CitectSCADA

/* This function will set the Window Title according to the tag name of the first variable  assigned on the page (ie ?INT 1?, ?Digital 1?)*/ 

FUNCTION
AssTitle(Int CharMask=0, String Prefix="", String Suffix="")

    WinTitle(Prefix + StrLeft(AssGetProperty(1, "TagName", 0),StrLength(AssGetProperty(1, "TagName", 0))-CharMask) + Suffix);
END


INT
FUNCTION
AssChainPopTrend(STRING sPage, STRING sTag1="", STRING sTag2="", STRING sTag3="",
     STRING sTag4="", STRING sTag5="", STRING sTag6="", STRING sTag7="", STRING sTag8="")

    AssChain(-2, WinNumber(), 0);
    RETURN TrendWin(sPage, 1, 1, 9, sTag1, sTag2, sTag3,sTag4,sTag5,sTag6,sTag7,sTag8);
END

FUNCTION
AssPopTrend(STRING sPage,STRING sTag1="",STRING sTag2="",STRING sTag3="",STRING sTag4="",STRING sTag5="",STRING sTag6="",STRING sTag7="",STRING sTag8="")
   
    INT x, y;
    REAL    ScaleX, ScaleY;

    DspGetMouse(x, y);

    ScaleX = StrToReal(PageInfo(16));
    ScaleY = StrToReal(PageInfo(17));
    x = x * ScaleX + StrToInt(PageInfo(14));
    y = y * ScaleY + StrToInt(PageInfo(15));

    IF x > WndInfo(0) - 150 THEN
        x = x - 150;
    ELSE
        x = x + 50;
    END
    IF y > WndInfo(1) - 150 THEN
        y = y - 150;
    ELSE
        y = y + 20;
    END

    x = x / ScaleX;
    y = y / ScaleY;

    AssVarTags(-2, 0, sTag1, sTag2, sTag3, sTag4, sTag5, sTag6, sTag7, sTag8);
    TrendWin(sPage, x, y, 9, sTag1, sTag2, sTag3,sTag4,sTag5,sTag6,sTag7,sTag8);
END

Saturday, October 27, 2012

Cicode-SCADA


/*These are simple functions used around the super genies to allow the user to do simple associations.*/


INT
FUNCTION
AssTag(INT nArg, STRING sTag, STRING sCluster = "")

    RETURN Ass(WinNumber(), nArg, sTag, 0, sCluster);
END

FUNCTION
AssVarTags(INT hWin, INT offset, STRING sTag1 = "", STRING sTag2 = "", STRING sTag3 = "",
 STRING sTag4 = "", STRING sTag5 = "", STRING sTag6 = "", STRING sTag7 = "", STRING sTag8 = "")

   
    Ass(hWin, offset + 1, sTag1, 0);
    Ass(hWin, offset + 2, sTag2, 0);
    Ass(hWin, offset + 3, sTag3, 0);
    Ass(hWin, offset + 4, sTag4, 0);
    Ass(hWin, offset + 5, sTag5, 0);
    Ass(hWin, offset + 6, sTag6, 0);
    Ass(hWin, offset + 7, sTag7, 0);
    Ass(hWin, offset + 8, sTag8, 0);
END

INT
FUNCTION
AssPage(STRING sPage, STRING sTag1 = "", STRING sTag2 = "", STRING sTag3 = "",
 STRING sTag4 = "", STRING sTag5 = "", STRING sTag6 = "", STRING sTag7 = "", STRING sTag8 = "")

    AssVarTags(WinNumber(), 0, sTag1, sTag2, sTag3, sTag4, sTag5, sTag6, sTag7, sTag8);

    RETURN _PageDisplay(sPage);
END

INT
FUNCTION
AssMetadataPage(STRING sPage, INT nAN = -2)

    AssMetadata(-2, nAN);

    RETURN _PageDisplay(sPage);
END


INT
FUNCTION
AssMetadataWin(STRING sPage, INT x = 0, INT y = 0, INT mode = 0, INT nAN = -2)

    AssMetadata(-2, nAN);

    IF WinNewAt(sPage, x, y, mode) = -1 THEN
        RETURN 269;
    ELSE
        RETURN 0;
    END
END


INT
FUNCTION
AssMetadataPopUp(STRING sPage, INT nAN = -2)

    INT     x, y;
    REAL    ScaleX, ScaleY;
    AssMetadata(-2, nAN);

    DspGetMouse(x, y);
    PageTransformCoords(WinNumber(), x, y, x, y, 0);
    ScaleX = StrToReal(PageInfo(16));
    ScaleY = StrToReal(PageInfo(17));
    x = x / ScaleX;
    y = y / ScaleY;
   
    IF WinNewAt(sPage, x, y, 1 + 8 + 32 + 256 + 512) = -1 THEN
        RETURN 269;
    ELSE
        RETURN 0;
    END
END


INT
FUNCTION
AssWin(STRING sPage, INT x = 0, INT y = 0, INT mode = 0, STRING sTag1 = "", STRING sTag2 = "", STRING sTag3 = "",
 STRING sTag4 = "", STRING sTag5 = "", STRING sTag6 = "", STRING sTag7 = "", STRING sTag8 = "")

    AssVarTags(-2, 0, sTag1, sTag2, sTag3, sTag4, sTag5, sTag6, sTag7, sTag8);

   
    IF WinNewAt(sPage, x, y, mode) = -1 THEN
        RETURN 269;
    ELSE
        RETURN 0;
    END
END


INT
FUNCTION
AssPopUp(STRING sPage, STRING sTag1 = "", STRING sTag2 = "", STRING sTag3 = "",
 STRING sTag4 = "", STRING sTag5 = "", STRING sTag6 = "", STRING sTag7 = "", STRING sTag8 = "")

    INT x, y;
    REAL    ScaleX, ScaleY;

    DspGetMouse(x, y);
    PageTransformCoords(WinNumber(), x, y, x, y, 0);
    ScaleX = StrToReal(PageInfo(16));
    ScaleY = StrToReal(PageInfo(17));
    x = x / ScaleX;
    y = y / ScaleY;
    RETURN AssWin(sPage, x, y, 1 + 8 + 32 + 256 + 512, sTag1, sTag2, sTag3, sTag4, sTag5, sTag6, sTag7, sTag8);
END


INT
FUNCTION
AssChainPage(STRING sPage)

    AssChain(WinNumber(), WinNumber(), 0);

    RETURN _PageDisplay(sPage);
END

INT
FUNCTION
AssChainWin(STRING sPage, INT x = 0, INT y = 0, INT mode = 0)

    AssChain(-2, WinNumber(), 0);

    IF WinNewAt(sPage, x, y, mode) = -1 THEN
        RETURN 269;
    ELSE
        RETURN 0;
    END
END

INT
FUNCTION
AssChainPopUp(STRING sPage)
    INT x, y;
    REAL    ScaleX, ScaleY;

    DspGetMouse(x, y);
    PageTransformCoords(WinNumber(), x, y, x, y, 0);
    ScaleX = StrToReal(PageInfo(16));
    ScaleY = StrToReal(PageInfo(17));
    x = x / ScaleX;
    y = y / ScaleY;
    RETURN AssChainWin(sPage, x, y, 1 + 8 + 32 + 256 + 512);
END