Beispiel #1
0
//------------------------------------------------------------------------------
static tOplkError linkProcessImageRange(UINT objIndexStart_p, UINT objIndexEnd_p,
                                        UINT offsetPI_p, BOOL fOutputPI_p,
                                        tObdSize entrySize_p, UINT subindexCountPerIndex_p)
{
    tOplkError      ret = kErrorOk;
    UINT            errorIndex = 0;
    UINT            varEntries;

    for (; objIndexStart_p <= objIndexEnd_p; objIndexStart_p++,
                                             offsetPI_p += entrySize_p * subindexCountPerIndex_p)
    {
        varEntries = subindexCountPerIndex_p;
        ret = oplk_linkProcessImageObject(objIndexStart_p, 1, offsetPI_p,
                                          fOutputPI_p, entrySize_p, &varEntries);
        if (((ret == kErrorOk) && (varEntries < subindexCountPerIndex_p)) ||
            (ret == kErrorApiPISizeExceeded))
        {
            errorIndex = 0;
            break;
        }

        if (ret != kErrorOk)
        {
            errorIndex = objIndexStart_p;
            break;
        }
    }

    return errorIndex;
}
//------------------------------------------------------------------------------
static tOplkError initProcessImage(void)
{
    tOplkError      ret = kErrorOk;
    UINT            varEntries;
    tObdSize        obdSize;

    /* Allocate process image */
    PRINTF("Initializing process image...\n");
    PRINTF("Size of input process image: %d\n", (UINT32)sizeof(PI_IN));
    PRINTF("Size of output process image: %d\n", (UINT32)sizeof (PI_OUT));
    ret = oplk_allocProcessImage(sizeof(PI_IN), sizeof(PI_OUT));
    if (ret != kErrorOk)
    {
        return ret;
    }

    pProcessImageIn_l = oplk_getProcessImageIn();
    pProcessImageOut_l = oplk_getProcessImageOut();

    /* link process variables used by CN to object dictionary */
    PRINTF("Linking process image vars:\n");

    obdSize = sizeof(pProcessImageIn_l->digitalIn[0]);
    varEntries = 4;
    ret = oplk_linkProcessImageObject(0x6000, 0x01, offsetof(PI_IN, digitalIn),
                                      FALSE, obdSize, &varEntries);
    if (ret != kErrorOk)
    {
        PRINTF("linking process vars ... error %04x\n\"%s\"\n\n", ret, debugstr_getRetValStr(ret));
        return ret;
    }

    obdSize = sizeof(pProcessImageOut_l->digitalOut[0]);
    varEntries = 4;
    ret = oplk_linkProcessImageObject(0x6200, 0x01, offsetof(PI_OUT, digitalOut),
                                      TRUE, obdSize, &varEntries);
    if (ret != kErrorOk)
    {
        PRINTF("linking process vars ... error %04x\n\"%s\"\n\n", ret, debugstr_getRetValStr(ret));
        return ret;
    }

    PRINTF("Linking process vars... ok\n\n");

    return kErrorOk;
}