gxi_hako

Crates.iogxi_hako
lib.rsgxi_hako
version0.2.0
sourcesrc
created_at2024-04-26 20:37:16.963347
updated_at2024-07-15 08:11:05.184114
descriptionA rust camera interface based on Daheng-Image's GxIAPI(Galaxy Camera SDK)
homepage
repositoryhttps://github.com/zoneherobrine/gxi_hako
max_upload_size
id1221790
size6,853,982
HakoChest (ZoneHerobrine)

documentation

https://docs.rs/gxi_hako

README

crates.io version badge Documentation GitHub workflow status Minimum Stable Rust Version


alt text

Deprecated

这个库基本上已经停止维护了,或者说已经被整合进了新的库之中,新的库是GXCI,它包含大恒相机SDK本地相机部分的全部原生实现,并且提供了对应的HAL封装,可以在githubcrates上查看

This project is deprecated, or it has been integrated into a new project, the new project is GXCI, it's ingithub and crates, which has FULL RAW IMPLEMENTATION of the local camera part of Daheng Imaging SDK, and it provides HAL functions.

Introduction

gxi_hako是一款用Rust基于GxIAPI的库进行大恒工业相机的接口开发;

目前已实现本地相机的所有接口,enums还没有完全迁移过来,并在utils内便写了一些工具类函数,方便使用

gxi_hako is developing the interface of Daheng Industrial Camera using Rust based on GxIAPI library;

At present, all interfaces for the local camera have been implemented, and the enums have not been completely migrated. Some utility functions have been written in utils to facilitate use.

Overview

The sdk-dev-doc is contained in ./doc/sdk,here I only provide the English version of the sdk-dev-doc, and the Chinese version is not provided here(Because the 10MB limitation of crates.io).

You can also get the sdk-dev-doc from the SDK of Daheng Imaging you have installed.

Quick Start

Following code is same as the list_devices_info.rs in the examples directory:


use std::mem::size_of;
use gxi_hako::{
    gx::{
        gx_interface::*, 
        gx_struct::*,
    },
    utils::{
        debug::print_device_info,
        builder::GXDeviceBaseInfoBuilder,
    },
};

fn main() {
    unsafe {
        // You can change the library path as you need
        let gx = GXInstance::new("C:\\Program Files\\Daheng Imaging\\GalaxySDK\\APIDll\\Win64\\GxIAPI.dll").expect("Failed to load library");
        gx.gx_init_lib().expect("Failed to initialize library");

        let mut device_num = 0;
        gx.gx_update_device_list(&mut device_num, 1000)
            .expect("Failed to update device list");

        if device_num > 0 {

            let mut base_info: Vec<GX_DEVICE_BASE_INFO> = (0..device_num).map(|_| {
                GXDeviceBaseInfoBuilder::new().build()
            }).collect();
            
            // or you can use the following code to initialize the vector without using the builder

            // let mut base_info = vec![
            //     GX_DEVICE_BASE_INFO {
            //         szVendorName: [0; GX_INFO_LENGTH_32_BYTE],
            //         szModelName: [0; GX_INFO_LENGTH_32_BYTE],
            //         szSN: [0; GX_INFO_LENGTH_32_BYTE],
            //         szDisplayName: [0; GX_INFO_LENGTH_128_BYTE],
            //         szDeviceID: [0; GX_INFO_LENGTH_64_BYTE],
            //         szUserID: [0; GX_INFO_LENGTH_64_BYTE],
            //         accessStatus: GX_ACCESS_STATUS_CMD::Unknown,
            //         deviceClass: GX_DEVICE_CLASS::Unknown,
            //         reserved: [0; 300],
            //     };
            //     device_num as usize
            // ];

            let mut size = (device_num as usize) * size_of::<GX_DEVICE_BASE_INFO>();
            let status = gx
                .gx_get_all_device_base_info(base_info.as_mut_ptr(), &mut size)
                .expect("Failed to get all device base info");

            if status == 0 {
                // Assuming 0 is GX_STATUS_SUCCESS
                println!(
                    "Device base info retrieved successfully. Number of devices: {}",
                    device_num
                );
                for device in &base_info {
                    print_device_info(&device);
                }

            } else {
                println!("Failed to retrieve device base info, status: {}", status);
            }
        } else {
            println!("No Devices found.");
        }

        gx.gx_close_lib().expect("Failed to close library");
        println!("Library closed.")
    }
}

Usage

You can see the GXInstance part(where impl the GXInterface trait with rust-doc) in gx_interface doc , the link is here

Example

Here 5 examples are provided, which are:

  • list_devices_info.rs: list all the devices' information
  • open_device_by_index.rs: open the device by index
  • open_device_by_sn.rs: open the device by serial number
  • get_image.rs: get the image from the camera
  • callback_capture.rs: register the callback function to capture the image realtimely

You can run the example by the following command:

cargo run --example list_devices_info

Dependencies

OpenCV Environment

The OpenCV lib here is only used to easily provide a GUI to show the image, so you can ignore this part if you don't want to show the image.

Install LLVM and OpenCV 4.9.0

In Windows 10/11, I would like using choco as the following command to install LLVM and OpenCV 4.9.0:

choco install llvm opencv

Following are the websites:

Add the path environment variable

You can add the following path to the path environment variable:

  • opencv bin path ...\opencv\build\bin
  • opencv x64 bin path ...\opencv\build\x64\vc16\bin
  • choco bin path C:\ProgramData\chocolatey\bin
  • LLVM bin path C:\Program Files\LLVM\bin

Here is an example:

D:\ProgramUnsigned\Embedded\opencv\build\bin 
D:\ProgramUnsigned\Embedded\opencv\build\x64\vc16\bin
C:\ProgramData\chocolatey\bin
C:\Program Files\LLVM\bin

Add opencv environment variable(System Variable)

OPENCV_INCLUDE_PATHS ...\opencv\build\include OPENCV_LINK_LIBS opencv_world490 OPENCV_LINK_PATHS ...\opencv\build\x64\vc16\lib

here is an example:

OPENCV_INCLUDE_PATHS D:\ProgramUnsigned\Embedded\opencv\build\include
OPENCV_LINK_LIBS opencv_world490
OPENCV_LINK_PATHS D:\ProgramUnsigned\Embedded\opencv\build\x64\vc16\lib

Copy opencv_world490.dll to the target directory (if needed)

Sometimes, you need to copy the opencv_world490.dll to the target directory, which is the same as the exe file.

GxIAPI Environment

You also need to install the GxIAPI SDK, which can be downloaded from the official website.

Just install the SDK for your platform.

Camera Environment

You need to connect the camera to your computer, and make sure the camera is powered on.

Then all the environment is ready.

Camera Support

  • USB3.0 Camera

    • Mer Camera (Mono8, Mono10)
  • Gige Camera

Platform Support

Now, is Windows only.

Licensing

Licensed under the MIT License.

Contributing

Uhmmm... placeholder

Acknowledgments

pLaShOlDeR~

Todolist

  • Get-Set 函数补全
  • 本地相机函数补全
  • 项目重构,等有闲的时候重构
  • 基本的example
  • 发布crate,重构完就发布
  • 更多的examples
  • 更多的doc说明
  • async/await的支持,引入tokio
  • 补全网络相机(Gige)相关的函数
  • 补全FeatureID的枚举
  • Linux平台支持
  • 更多相机类型

DLL implemented status

  • 302 0 0001C020 GXCloseDevice
  • 101 1 0001BBC0 GXCloseLib
  • 700 2 0001E9E0 GXExportConfigFile
  • 707 3 0001EA50 GXExportConfigFileW ?在开发文档里面没介绍这个函数
  • 602 4 0001E920 GXFlushEvent
  • 505 5 0001E6E0 GXFlushQueue
  • 201 6 0001BDE0 GXGetAllDeviceBaseInfo
  • 414 7 0001D5F0 GXGetBool
  • 419 8 0001E080 GXGetBuffer
  • 418 9 0001DF50 GXGetBufferLength
  • 205 A 0001BE80 GXGetDeviceIPInfo
  • 423 B 0001C0B0 GXGetDevicePersistentIpAddress
  • 411 C 0001D3C0 GXGetEnum
  • 410 D 0001CF50 GXGetEnumDescription
  • 409 E 0001CE20 GXGetEnumEntryNums
  • 506 F 0001E970 GXGetEventNumInQueue
  • 422 10 0001C1E0 GXGetFeatureName
  • 408 11 0001CCF0 GXGetFloat
  • 406 12 0001C960 GXGetFloatRange
  • 504 13 0001E670 GXGetImage
  • 404 14 0001C730 GXGetInt
  • 403 15 0001C590 GXGetIntRange
  • 204 16 0001BC40 GXGetLastError
  • 709 17 0001F370 GXGetOptimalPacketSize (Windows Only)
  • 416 18 0001DAA0 GXGetString
  • 415 19 0001D820 GXGetStringLength
  • 425 1A 0001D970 GXGetStringMaxLength
  • 705 1B 0001EEF0 GXGigEForceIp
  • 704 1C 0001ECC0 GXGigEIpConfiguration
  • 706 1D 0001F170 GXGigEResetDevice
  • 701 1E 0001EAC0 GXImportConfigFile
  • 708 1F 0001EB40 GXImportConfigFileW ?在开发文档里面没介绍这个函数
  • 100 20 0001BB70 GXInitLib
  • 400 21 0001C260 GXIsImplemented
  • 401 22 0001C370 GXIsReadable
  • 402 23 0001C480 GXIsWritable
  • 301 24 0001BFB0 GXOpenDevice
  • 300 25 0001BF10 GXOpenDeviceByIndex
  • 702 26 0001EBC0 GXReadRemoteDevicePort
  • 710 27 0001F3E0 GXReadRemoteDevicePortStacked
  • 500 28 0001E5B0 GXRegisterCaptureCallback
  • 600 29 0001E730 GXRegisterDeviceOfflineCallback
  • 603 2A 0001E820 GXRegisterFeatureCallback
  • 421 2B 0001E480 GXSendCommand
  • 507 2C 0001F100 GXSetAcqusitionBufferNumber
  • 413 2D 0001D720 GXSetBool
  • 420 2E 0001E350 GXSetBuffer
  • 424 2F 0001C160 GXSetDevicePersistentIpAddress
  • 412 30 0001D4F0 GXSetEnum
  • 407 31 0001CBE0 GXSetFloat
  • 405 32 0001C860 GXSetInt
  • 417 33 0001DDC0 GXSetString
  • 501 34 0001E620 GXUnregisterCaptureCallback
  • 601 35 0001E7B0 GXUnregisterDeviceOfflineCallback
  • 604 36 0001E8B0 GXUnregisterFeatureCallback
  • 206 37 0001BD70 GXUpdateAllDeviceList
  • 200 38 0001BD00 GXUpdateDeviceList
  • 703 39 0001EC40 GXWriteRemoteDevicePort
  • 711 3A 0001F450 GXWriteRemoteDevicePortStacked (Windows Only)
Commit count: 41

cargo fmt