Sunday, November 4, 2012

Cicode- SCADA


/* This function will set the passed variable high then place it low 2 seconds later.*/

FUNCTION GoPulse(STRING sTAGNAME, STRING sCLUSTER = "")
    INT     tagNameLength = StrLength(sTAGNAME);
    INT     tagHasDot       = -1;
    STRING sAssString      = "";
    STRING sOriginalTag    = "";
    INT     nError          = 0;
   
    IF (tagNameLength > 0) THEN
        // Ensure we don't do work with an empty reference
        IF StrGetChar(sTAGNAME, 0) = StrToChar("?") THEN
            // Strip the ? characters from the start and end of the super genie ass number
            sAssString = StrLeft(sTAGNAME, tagNameLength - 1);
            sAssString = StrRight(sAssString, tagNameLength - 2);
           
            sOriginalTag = sTAGNAME;
            ErrSet(1);
            sTAGNAME = AssGetProperty(sAssString, "FullName");
            nError = IsError();
            ErrSet(0);
           
            tagNameLength = StrLength(sTAGNAME);
        END

        IF (tagNameLength > 0) THEN
            // Do this check again in case the AssGetProperty() did not work   
            tagHasDot = StrSearch(0, sTAGNAME, ".");
            IF (tagHasDot >= 1) THEN
                // This tag has a Cluster reference so null any passed cluster reference
                // Assume ".tag" is not part of this logic
                sCLUSTER = "";
            END

            nError = TagWrite(sTAGNAME,1,0,TRUE,sCLUSTER); // Synchronous write
            IF (nError = 0) THEN
                Sleep(2);
                TagWrite(sTAGNAME,0,0,TRUE,sCLUSTER);      // Synchronous write
            ELSE
                // Problem in Tag write
                ErrSetHw(2, nError, 0);
                ErrLog("Error using system cicode Pulser(*) function: Tag '" + sTAGNAME + "', Cicode error " + IntToStr(nError));
            END
        ELSE
       
            // This code path means the AssGetProperty() has failed to establish the tag
            IF (nError = 0) THEN
               // Tests showed that an invalid genie tag was returning no error so correct it to something
               nError = 424;        // Tag not found
            END
            ErrSetHw(2, nError, 0);
            ErrLog("Error using system cicode Pulser(*) function: Genie Item '" + sOriginalTag + "', Cicode error " + IntToStr(nError));

        END
       
    ELSE
   
        // Passed tag name is blank
        ErrSetHw(2, 289, 0);    // Set Name does not exist error
        ErrLog("Error using system cicode Pulser(*) function: Tagname blank, Cicode error " + IntToStr(289));

    END
END







No comments:

Post a Comment

Note: Only a member of this blog may post a comment.