101 lines
3.3 KiB
C#
101 lines
3.3 KiB
C#
/*
|
|
* Copyright (c) 2025 LG Electronics Inc.
|
|
* SPDX-License-Identifier: LicenseRef-LGE-Proprietary
|
|
*/
|
|
using Aurora.Api;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using Euresys.EGrabber;
|
|
using Hermes;
|
|
using VisionCommon;
|
|
using System.Reactive.Linq;
|
|
|
|
namespace MilCamera {
|
|
/// <summary>
|
|
/// Euresys 그래버 매니저
|
|
/// </summary>
|
|
public class EuresysGrabberManager {
|
|
private static Logger _Logger = new Logger(typeof(EuresysGrabberManager).Name);
|
|
private static readonly object _Lock = new object();
|
|
private static IDisposable _EventDisposable;
|
|
|
|
/// <summary>
|
|
/// cti 파일 경로
|
|
/// </summary>
|
|
public static string CtiPath { get; set; }
|
|
|
|
/// <summary>
|
|
/// EGenTL 객체
|
|
/// </summary>
|
|
public static EGenTL EGenTL { get; set; }
|
|
|
|
/// <summary>
|
|
/// EGrabberDiscovery 객체
|
|
/// </summary>
|
|
public static EGrabberDiscovery EGrabberDiscovery { get; set; }
|
|
|
|
/// <summary>
|
|
/// cti 파일로 그래버 생성 및 연결
|
|
/// </summary>
|
|
/// <param name="ctiPath">cti 파일 경로</param>
|
|
/// <returns>성공 유무</returns>
|
|
public static int Create(string ctiPath) {
|
|
try {
|
|
if (EGenTL == null) {
|
|
EGenTL = new EGenTL(ctiPath);
|
|
}
|
|
if (EGrabberDiscovery == null) {
|
|
EGrabberDiscovery = new EGrabberDiscovery(EGenTL);
|
|
_Logger.FuncI("Discovering grabbers...");
|
|
EGrabberDiscovery.Discover(); // 1~5초 시간 소요
|
|
_Logger.FuncI("Discovering completed.");
|
|
}
|
|
SetObservable();
|
|
_Logger.FuncI("EuresysGrabberManager was created successfully.");
|
|
|
|
return E1.OK;
|
|
}
|
|
catch (Exception e) {
|
|
_Logger.FuncE(e.Message);
|
|
}
|
|
return E1.GENERIC;
|
|
}
|
|
|
|
private static void SetObservable() {
|
|
if (_EventDisposable == null) {
|
|
// SYS_SHUTDOWN은 EquipmentSetup에서 OnShutDown을 위한 것이므로 여기서 사용 불가
|
|
_EventDisposable = Observable.Merge(
|
|
VisionEnv.AuroraEnv.EventObservable.AsObservable(AuroraSysEvent.SYS_SHUTDOWN)).Subscribe(_ => Dispose());
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 그래버 생성 여부 체크
|
|
/// </summary>
|
|
/// <returns>그래버 생성 여부</returns>
|
|
public static bool IsCreated() {
|
|
if (EGenTL != null &&
|
|
EGrabberDiscovery != null &&
|
|
_EventDisposable != null) {
|
|
return true;
|
|
}
|
|
else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 리소스 정리
|
|
/// EGenTL과 EGrabberDiscovery는 모든 카메라 공용이므로 카메라 1대만 Dispose할 때, 이 함수를 호출하지 않도록 주의.
|
|
/// 즉, 프로그램 종료시에만 해주면 됨.
|
|
/// </summary>
|
|
public static void Dispose() {
|
|
_EventDisposable?.Dispose();
|
|
_EventDisposable = null;
|
|
EGrabberDiscovery?.Dispose();
|
|
EGrabberDiscovery = null;
|
|
EGenTL?.Dispose();
|
|
EGenTL = null;
|
|
}
|
|
}
|
|
} |