Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

implement in ST

rsanz
2012-07-02
2012-07-06
  • rsanz - 2012-07-02

    Hi,

    I want to implement that program written in C with CoDeSys written in ST language. I don't know how to do "EQ_SDI_TEMP_SONDA[i].m_TempNOK".

    The program:

    /******
    OBJECT ATTRIBUTES
    /

    struct EQ_SDI_TEMP_SONDA_ATT EQ_SDI_TEMP_SONDA[c_EQ_SDI_TEMP_SONDA_MAX_OBJ];

    /*****
    METHODS
    /
    /
    ------------------------------------------------------------
    ---- EQ_SDI_TEMP_SONDA_SetInput ----------------------------------*

    void EQ_SDI_TEMP_SONDA_SetInput(CS_UNSIGNED8 i,
    CS_UNSIGNED16 In1, / Entrada temperatura SDI. /
    CS_BOOLEAN1 In1Ok, / Validez de la entrada. /
    CS_UNSIGNED16 In2 / Entrada temperatura PLC. /
    ) {

    /---- Local Variables --------------/

    /---- Comprobacion de index --------------/
    PLC_CheckIndex(EQ_SDI_TEMP_SONDA_SetInput, i, c_EQ_SDI_TEMP_SONDA_MAX_OBJ);

    /---- Timers -----------------------/

    /---- Code -------------------------/

    if (In1Ok)  {
    
    
        if (In1 == In2) {
            EQ_SDI_TEMP_SONDA[i].m_TempNOK = 0;
    
        } else {
            EQ_SDI_TEMP_SONDA[i].m_TempNOK = 1;
        }
    
    /* ------------------------------------------
    
    } else {
    
        EQ_SDI_TEMP_SONDA[i].m_TempNOK = 0;
    }
    

    /---- Former values -------------------------/

    }

    /------------------------------------------------------------
    ------- EQ_SDI_TEMP_SONDA_GetValue ------------------------------

    CS_BOOLEAN1 EQ_SDI_TEMP_SONDA_GetValue(CS_UNSIGNED8 i) { / Devuelve el valor. /

    return(EQ_SDI_TEMP_SONDA[i].m_TempNOK);
    

    }

     
  • TimvH

    TimvH - 2012-07-02

    First you have to create a structure:
    In CoDeSys you have to add to the application a "DUT: Data Unit Type". Give it a name and select Structure.
    Now you can add the (standard) variables which are part of this structure.

    In your POU you can add a new variable of the structure which you have created. e.g.:

    aStruct: ARRAY[0..constant] OF myStructure;
    

    In this case myStructure is the name of your new type.
    aStruct is the instance of this struct.

    In CoDeSys you can use the variable: aStruct[index].standardVar

     
  • rsanz - 2012-07-06

    I make this but isn't correct.

    TYPE
    EQ_SDI_TEMP_SONDA_ATT:
    STRUCT
    m_TempNOK : BOOL;
    EQ_SDI_TEMP_SONDA : ARARAY[0..5] OF EQ_SDI_TEMP_SONDA_ATT;
    END_STRUCT;

    END_TYPE

     
  • TimvH

    TimvH - 2012-07-06

    You have to put the instance of the structure (EQ_SDI_TEMP_SONDA : ARARAY[0..5] OF EQ_SDI_TEMP_SONDA_ATT;) in the POU or Global Variable List. Not in the Structure itself.

     

Log in to post a comment.