MilleVisionNotes

This site focuses on practical examples of controlling Basler industrial cameras
using the pylon SDK and C#, based on real-world development experience.

タグ: pylon

  • How to Manually Control Exposure Time Using the Basler pylon SDK (C# / .NET 8)


    How to Manually Control Exposure Time Using the Basler pylon SDK (C# / .NET 8)

    Have you ever felt that your industrial camera images look too dark, too bright, or fluctuate unexpectedly?
    Automatic exposure (auto-exposure) can be useful, but in many machine-vision or inspection systems, consistent lighting is essential, and automatic adjustments can cause instability.

    With the Basler pylon SDK, you can switch exposure control to manual mode and specify an exact exposure time (in microseconds), enabling stable and predictable imaging.

    This article explains how to set, read, and validate exposure time manually using C# and the pylon SDK.


    ✔ Environment

    ItemDetails
    CameraBasler acA2500-14gm
    SDKBasler pylon Camera Software Suite
    LangC# / .NET 8.0 (Windows)

    💡 Background: GenICam and Camera Parameters

    Parameters such as ExposureTimeAbs used in this article follow GenICam (Generic Interface for Cameras) — an industry standard used by Basler, FLIR, IDS, JAI, and many other industrial camera manufacturers.

    With GenICam SFNC (Standard Features Naming Convention), you can access:

    • Exposure
    • Gain
    • ROI / image size
    • Trigger settings
    • Acquisition modes

    all using a common parameter model.

    👉 GenICam SFNC specification:
    https://www.emva.org/standards-technology/genicam/

    This article focuses on practical usage, but knowing that pylon follows GenICam helps when switching between camera brands.


    🔧 Setting Exposure Time Manually

    Below is an extension to the BaslerCameraSample class from the previous article.

    Method: Set Exposure Time (manual mode)


    Helper Functions

    Set auto-exposure mode (Off / Once / Continuous)

    Set an enum parameter

    Set a floating-point parameter (e.g., ExposureTimeAbs)


    🔍 Reading the Current Exposure Time

    Use GetValue() to read exposure parameters from the camera.


    💡 About ExposureAuto Modes

    ValueBehavior
    OffManual exposure (used in this article)
    OnceAdjusts exposure once, then fixes it
    ContinuousContinuously adjusts to maintain brightness

    📷 Example: Change Exposure and Capture Images

    The test below captures images at 5 ms, 20 ms, and 50 ms.


    📊 Exposure Comparison


    5 ms (darker) 20 ms (balanced) 50 ms (brighter)
    5ms 20ms 50ms

    🧭 Common Issues & Troubleshooting

    IssueCause / Solution
    Exposure does not changeExposureAuto is still On
    Value outside valid rangeExposure too long or too short for the camera model
    Image too dark/brightLighting or gain settings are insufficient
    Exposure fluctuatesExternal lighting or auto exposure still enabled

    📝 Summary

    • Set ExposureAuto = Off to enable manual exposure control
    • Exposure time is specified in microseconds (μs)
    • pylon SDK accesses all parameters through Camera.Parameters[...], following GenICam SFNC

    🔜 Coming Up Next

    Exposure alone may not give enough brightness range depending on your lighting environment.
    The next article will cover manual gain control using the pylon SDK.

  • How to Capture a Single Image from Basler ace Camera using pylon SDK in C#


    How to Capture a Single Image from Basler ace Camera using pylon SDK in C#

    Basler industrial cameras can be controlled easily using the pylon Camera Software Suite.
    In this article, I’ll show you how to connect to a camera, grab a single frame, convert it to a BitmapSource, and save it as a .bmp file—all using C# and .NET 8.

    When I first started working with Basler cameras in a .NET environment, I found very few practical code examples.
    This guide is based on tested code from my own applications.

    This article covers:

    • Connecting to a camera
    • Capturing one frame (Snap)
    • Converting to BitmapSource (WPF-friendly)
    • Saving the image as .bmp

    ⚠️ Important Notice

    This article demonstrates how to develop custom applications using the Basler pylon Camera Software Suite SDK.

    • The content here is based on my own testing and implementation
    • It is not endorsed by Basler AG
    • The SDK itself is not redistributed here (no DLLs, headers, etc.)

    To use the SDK, download it directly from Basler’s official website:

    🔗 pylon SDK download
    https://www.baslerweb.com/en/products/software/basler-pylon-camera-software-suite/

    Make sure to review the EULA, especially if using the SDK in commercial or high-risk environments:
    https://www.baslerweb.com/en/service/eula/

    The sample code in this article is provided strictly for learning and reference. Use it at your own responsibility.


    ✔ Environment

    ItemDetails
    SDKBasler pylon Camera Software Suite
    LanguageC# (.NET 8.0 — Windows)
    CameraBasler acA2500-14gm
    OSWindows 10 / 11

    1. Connecting to the Camera

    First, create a simple wrapper class for managing the connection.
    You can connect to the first available camera or use a specified camera name (as shown in Basler pylon Viewer).


    2. Capturing a Single Image

    The simplest way to grab one frame is by calling GrabOne() through the Stream Grabber.


    3. Converting to BitmapSource (for WPF)

    IGrabResult cannot be displayed directly in WPF.
    We convert it to a BitmapSource using PixelDataConverter.

    Supports:

    • RGB8packed
    • BGR8packed
    • Mono8 (default fallback)

    4. Saving the Image as .bmp

    A simple helper method using BmpBitmapEncoder:


    5. Example Test Code

    You can easily test the entire pipeline (grab → convert → save) using the following:


    ✔ Output Example

    The captured image will be saved as:SaveBitmapTest.bmp

    Example output:

    (Image from the original article)


    ✨ Conclusion

    Although official documentation covers the basics, hands-on .NET examples for pylon are still relatively rare.
    Fortunately, pylon’s .NET API is clean and integrates smoothly with Windows desktop applications such as WPF.