首页 > 解决方案 > 如何正确设置高电压触发抓取?

问题描述

我想在高电平电压上设置触发抓取。目前,所有输入电压都按预期到达采集器。触发设置如下:

 //set triggering source 
 MdigControl(digitizer, M_GRAB_TRIGGER_SOURCE,M_AUX_IO0); 
 //enable triggering 
 MdigControl(digitizer,M_GRAB_TRIGGER_STATE, M_ENABLE); 
 //use high voltage to trigger
 MdigControl(digitizer, M_GRAB_TRIGGER_ACTIVATION, M_LEVEL_HIGH);

两个事件是这样连接的:

MdigHookFunction(digitizer, M_GRAB_FRAME_START, onStart, &hookData);
MdigHookFunction(digitizer, M_GRAB_FRAME_END, onEnd, &hookData);

如果事件被触发,onStart() 将简单地打印出“Start”,onEnd() 的行为类似。抓取逻辑如下所示:

MdigProcess(digitizer, &grabBufs[0][0], BUFFERING_SIZE_MAX * NUM_OF_GRAB_BUF,
    M_START, M_DEFAULT, ProcessingFunction, &UserHookData);

MosGetch();

/* Stop the processing. */
MdigProcess(digitizer, &grabBufs[0][0], BUFFERING_SIZE_MAX,
    M_STOP, M_DEFAULT, ProcessingFunction, &UserHookData);

问题是在触发信号来或去之后,onStart()/onEnd()/ProcessingFunction() 都没有给出任何输出消息。

你能告诉它让它正常工作吗?

我的完整代码:

#include <mil.h>    
#include <memory>
#include <iostream>
#include <string>

//onpaged memory
#define BOARD_NAME     M_SYSTEM_SOLIOS
/* Number of images in the buffering grab queue.
 Generally, increasing this number gives better real-time grab.
 */
#define NUM_OF_GRAB_BUF    1
#define BUFFERING_SIZE_MAX 1 //BUFFERING_SIZE_MAX * H

const std::string &IMAGE_DIR = "image_dir";
const std::string &MACHINE_SN = "machine_sn";

/* User's processing function prototype. */
MIL_INT MFTYPE onStart(MIL_INT HookType, MIL_ID HookId, void *HookDataPtr);
MIL_INT MFTYPE onEnd(MIL_INT HookType, MIL_ID HookId, void *HookDataPtr);
MIL_INT MFTYPE processFunc(MIL_INT hookType, MIL_ID hookId, void *hookDataPtr);

/* User's processing function hook data structure. */
typedef struct {
        MIL_INT processedCount;
        MIL_ID display;
} HookDataStruct;

/* Main function. */
/* ---------------*/
int main(int argc, char **argv) {
    MIL_ID app;
    MIL_ID system;
    MIL_ID display;
    MIL_ID digitizer = 0;
    MIL_ID dispBuf;
    MIL_ID grabBufs[NUM_OF_GRAB_BUF][BUFFERING_SIZE_MAX];
    MIL_ID bigBuf[NUM_OF_GRAB_BUF];
    //MIL_ID parentID;
    MIL_INT sizeX;
    MIL_INT sizeY;
    MIL_INT bandSize;
    MIL_INT grabChildBufs = 0;
    MIL_INT grabBufsIdx = 0;
    MIL_INT ProcessFrameCount = 0;
    MIL_DOUBLE ProcessFrameRate = 0;
    HookDataStruct hookData;

    /* Allocate defaults. */
    MappAllocDefault(M_DEFAULT, &app, &system, &display, &digitizer, M_NULL);

    MdigHookFunction(digitizer, M_GRAB_FRAME_START, onStart, &hookData);
    MdigHookFunction(digitizer, M_GRAB_FRAME_END, onEnd, &hookData);

    //set triggering source
    MdigControl(digitizer, M_GRAB_TRIGGER_SOURCE, M_AUX_IO0);
    //enable triggering
    MdigControl(digitizer, M_GRAB_TRIGGER_STATE, M_ENABLE);
    //use high voltage to trigger
    MdigControl(digitizer, M_GRAB_TRIGGER_ACTIVATION, M_LEVEL_HIGH);

    sizeX = MdigInquire(digitizer, M_SIZE_X, M_NULL);
    sizeY = MdigInquire(digitizer, M_SIZE_Y, M_NULL);
    bandSize = MdigInquire(digitizer, M_SIZE_BAND, M_NULL);

    MdigControl(digitizer, M_GRAB_TRIGGER_SOFTWARE, 1);

    MbufAllocColor(system, bandSize, sizeX, sizeY * (BUFFERING_SIZE_MAX),
    MdigInquire(digitizer, M_TYPE, M_NULL), M_IMAGE + M_GRAB + M_DISP, &dispBuf);

    MbufClear(dispBuf, 0xFF);

    MdispSelect(display, dispBuf);

    /* Allocate the grab buffers and clear them. */
    for (grabBufsIdx = 0; grabBufsIdx < NUM_OF_GRAB_BUF; grabBufsIdx++) {
        MbufAllocColor(system, bandSize, sizeX, sizeY * (BUFFERING_SIZE_MAX),
        MdigInquire(digitizer, M_TYPE, M_NULL), M_IMAGE + M_GRAB, &bigBuf[grabBufsIdx]);
        MbufClear(bigBuf[grabBufsIdx], 0xFF);

        for (grabChildBufs = 0; grabChildBufs < BUFFERING_SIZE_MAX; grabChildBufs++) {
            MbufChild2d(bigBuf[grabBufsIdx], 0, sizeY * grabChildBufs, sizeX, sizeY, &grabBufs[grabBufsIdx][grabChildBufs]);
        }
    }
    /* Initialize the User's processing function data structure. */
    hookData.processedCount = 0;
    hookData.display = dispBuf;

    /* Print a message. */
    MosPrintf(MIL_TEXT("\nMULTIPLE BUFFERED PROCESSING.\n"));
    MosPrintf(MIL_TEXT("-----------------------------\n\n"));
    MosPrintf(MIL_TEXT("Press <Enter> to start.\n\n"));
    MosGetch();

    /* Print a message and wait for a key after a minimum number of frames. */
    MosPrintf(MIL_TEXT("Press <Enter> to stop.\n\n"));

    MdigProcess(digitizer, &grabBufs[0][0], BUFFERING_SIZE_MAX * NUM_OF_GRAB_BUF, M_START, M_DEFAULT, processFunc, &hookData);

    /* NOTE: Now the main() is free to do other tasks while the processing is executing. */
    /* --------------------------------------------------------------------------------- */

    MosGetch();

    /* Stop the processing. */
    MdigProcess(digitizer, &grabBufs[0][0], BUFFERING_SIZE_MAX, M_STOP, M_DEFAULT, processFunc, &hookData);

    /* Print statistics. */
    MdigInquire(digitizer, M_PROCESS_FRAME_COUNT, &ProcessFrameCount);
    MdigInquire(digitizer, M_PROCESS_FRAME_RATE, &ProcessFrameRate);
    MosPrintf(MIL_TEXT("\n\n%ld frames grabbed at %.1f frames/sec (%.1f ms/frame).\n"), ProcessFrameCount, ProcessFrameRate, 1000.0 / ProcessFrameRate);
    MosPrintf(MIL_TEXT("Press <Enter> to end.\n\n"));
    MosGetch();

    /* Free the grab buffers. */
    for (grabBufsIdx = 0; grabBufsIdx < NUM_OF_GRAB_BUF; grabBufsIdx++) {
        for (grabChildBufs = 0; grabChildBufs < BUFFERING_SIZE_MAX; grabChildBufs++) {
            MbufFree(grabBufs[grabBufsIdx][grabChildBufs]);
        }
        MbufFree(bigBuf[grabBufsIdx]);
    }

    /* Release defaults. */
    MappFreeDefault(app, system, display, digitizer, dispBuf);

    return 0;
}


MIL_INT MFTYPE onEnd(MIL_INT HookType, MIL_ID HookId, void *HookDataPtr) {
    std::cout << "End" << std::endl;
    return 0;
}

MIL_INT MFTYPE onStart(MIL_INT HookType, MIL_ID HookId, void *HookDataPtr) {
    std::cout << "Start" << std::endl;
    return 0;
}

MIL_INT MFTYPE processFunc(MIL_INT hookType, MIL_ID hookId, void *hookDataPtr) {
    
    std::cout << "Processing" << std::endl;

    return 0;
}

标签: c++matrox

解决方案


推荐阅读