close
安裝下載

Basler pylon SDK x86 3.2.3.3215.exe

Basler pylon SDK x64 3.2.3.3215.exe


在Win7 x64 作業系統只能安裝x64版本, 無法安裝x86版本

開啟pylon IP Configuration Tool查詢關於Basler攝影機硬體相關資訊


控制台 -> 變更介面卡設定



滑鼠點選區域連線設定, 按右鍵<內容>


選擇<網際網路通訊協定第四版 TCP/IPv4>, 按下<內容>按鈕


設定與攝影機相同網段192.168.11.xxx, 其中xxx為1~253, 但不可以和攝影機設定成相同的網址192.168.11.13



開啟Pylon Viewer, 可以看到剛才偵測到的攝影機裝置 Basler raL2048-48gm


開啟檔案總管, 安裝路徑為 C:Program FilesBasler


進入Samples目錄夾, 選擇C語言次目錄, 開啟PylonCSamples

對應的User guide for C Programming為PylonCSDK


開啟PylonCSDK使用手冊


選擇[Link]->Input下拉選單, Object/Library輸入PylonC_MD_vc100.lib


Include路徑加入 $(PYLONC_ROOT)include

其中PYLONC_ROOT為系統環境變數


C:\\Program Files\\Basler\\pylon 3.2\\pylonc\\include

----------------------------------------------------------------------------------------------------

研究 SimpleGrab.c

/*

This sample illustrates how to use the PylonDeviceGrabSingleFrame() convenience
method for grabbing images in a loop. PylonDeviceGrabSingleFrame() grabs one
single frame in single frame mode.

Grabbing in single frame acquisition mode is the easiest way to grab images. Note: in single frame
mode the maximum frame rate of the camera can't be achieved. The full frame
rate can be achieved by setting the camera to the continuous frame acquisition
mode and by grabbing in overlapped mode, i.e., image acquisition is done in parallel
with image processing. This is illustrated in the OverlappedGrab sample program.

*/

#include <stdlib.h>
#include <stdio.h>
#include <malloc.h>

#include <pylonc/PylonC.h>

---------------------------------------------------------------------------------------------------



    /* Before using any pylon methods, the pylon runtime must be initialized. */
    PylonInitialize();                    // 初始化

    /* Enumerate all camera devices. You must call
    PylonEnumerateDevices() before creating a device! */
    res = PylonEnumerateDevices( &numDevices );
    CHECK(res);
    if ( 0 == numDevices )
    {
        fprintf( stderr, "No devices found!n" );
        /* Before exiting a program, PylonTerminate() should be called to release
           all pylon related resources. */
        PylonTerminate();   
        pressEnterToExit();
        exit(EXIT_FAILURE);
    }

    /* Get a handle for the first device found.  */
    res = PylonCreateDeviceByIndex( 0, &hDev );
    CHECK(res);

    /* Before using the device, it must be opened. Open it for configuring
    parameters and for grabbing images. */
    res = PylonDeviceOpen( hDev, PYLONC_ACCESS_MODE_CONTROL |   
                                                 PYLONC_ACCESS_MODE_STREAM );
    CHECK(res);
    /* Print out the name of the camera we are using. */
    {
        char buf[256];
        size_t siz = sizeof(buf);
        _Bool isReadable;

        isReadable = PylonDeviceFeatureIsReadable(hDev, "DeviceModelName");
        if ( isReadable )
        {
            res = PylonDeviceFeatureToString(hDev, "DeviceModelName", buf, &siz );
            CHECK(res);
            printf("Using camera %sn", buf);  // 印出裝置名稱
        }
    }


    /* Set the pixel format to Mono8, where gray values will be output as 8 bit values for each pixel. */
    /* ... Check first to see if the device supports the Mono8 format. */
    isAvail = PylonDeviceFeatureIsAvailable(hDev, "EnumEntry_PixelFormat_Mono8");
    if ( !isAvail )
    {
        /* Feature is not available. */
        fprintf(stderr, "Device doesn't support the Mono8 pixel format.");
        PylonTerminate();
        pressEnterToExit();
        exit (EXIT_FAILURE);
    }
   
    /* ... Set the pixel format to Mono8. */
    res = PylonDeviceFeatureFromString(hDev, "PixelFormat", "Mono8" );
    CHECK(res);

    /* Disable acquisition start trigger if available */
    isAvail = PylonDeviceFeatureIsAvailable( hDev, "EnumEntry_TriggerSelector_AcquisitionStart");
    if (isAvail)
    {
        res = PylonDeviceFeatureFromString( hDev, "TriggerSelector", "AcquisitionStart");
        CHECK(res);
        res = PylonDeviceFeatureFromString( hDev, "TriggerMode", "Off");
        CHECK(res);
    }
 
    /* Disable frame start trigger if available */
    isAvail = PylonDeviceFeatureIsAvailable( hDev, "EnumEntry_TriggerSelector_FrameStart");
    if (isAvail)
    {
        res = PylonDeviceFeatureFromString( hDev, "TriggerSelector", "FrameStart");
        CHECK(res);
        res = PylonDeviceFeatureFromString( hDev, "TriggerMode", "Off");
        CHECK(res);
    }

    /* For GigE cameras, we recommend increasing the packet size for better
       performance. If the network adapter supports jumbo frames, set the packet
       size to a value > 1500, e.g., to 8192. In this sample, we only set the packet size
       to 1500. */
    /* ... Check first to see if the GigE camera packet size parameter is supported
        and if it is writable. */
    isAvail = PylonDeviceFeatureIsWritable(hDev, "GevSCPSPacketSize");
    if ( isAvail )
    {
        /* ... The device supports the packet size feature. Set a value. */
        res = PylonDeviceSetIntegerFeature( hDev, "GevSCPSPacketSize", 1500 );
        CHECK(res);
    }

    /* Determine the required size of the grab buffer. */
    res = PylonDeviceGetIntegerFeatureInt32( hDev, "PayloadSize", &payloadSize );
    CHECK(res);
   
    /* Allocate memory for grabbing. */
    imgBuf = (unsigned char*) malloc( payloadSize );
    if ( NULL == imgBuf )
    {
        fprintf( stderr, "Out of memory.\n" );
        PylonTerminate();
        pressEnterToExit();
        exit(EXIT_FAILURE);
    }

    /* Grab some images in a loop. */
    for ( i = 0; i < numGrabs; ++i )
    {
        unsigned char min, max;
        PylonGrabResult_t grabResult;
        _Bool bufferReady;

        /* Grab one single frame from stream channel 0. The
        camera is set to single frame acquisition mode.
        Wait up to 500 ms for the image to be grabbed. */
        res = PylonDeviceGrabSingleFrame( hDev, 0, imgBuf, payloadSize,
            &grabResult, &bufferReady, 500 );
        if ( GENAPI_E_OK == res && !bufferReady )
        {
            /* Timeout occurred. */
            printf("Frame %d: timeout\n", i+1);
        }
        CHECK(res);

        /* Check to see if the image was grabbed successfully. */
        if ( grabResult.Status == Grabbed )
        {
            /* Success. Perform image processing. */
            getMinMax( imgBuf, grabResult.SizeX, grabResult.SizeY, &min, &max );
            printf("Grabbed frame #%2d. Min. gray value = %3u, Max. gray value = %3u\n", i+1, min, max);

            /* Display image */
            res = PylonImageWindowDisplayImageGrabResult(0, &grabResult);
            CHECK(res);
        }
        else if ( grabResult.Status == Failed )
        {
            fprintf( stderr,  "Frame %d wasn't grabbed successfully.  Error code = 0x%08X\n",
                i+1, grabResult.ErrorCode );
        }
    }

    /* Clean up. Close and release the pylon device. */

    res = PylonDeviceClose( hDev );
    CHECK(res);
    res = PylonDestroyDevice ( hDev );
    CHECK(res);

    /* Free memory for grabbing. */
    free( imgBuf );

    pressEnterToExit();

    /* Shut down the pylon runtime system. Don't call any pylon method after
       calling PylonTerminate(). */
    PylonTerminate();

    return EXIT_SUCCESS;
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 me1237guy 的頭像
    me1237guy

    天天向上

    me1237guy 發表在 痞客邦 留言(4) 人氣()