2026-03-30 17:09:29 +09:00

155 lines
4.8 KiB
C#

using Aurora.Api;
using AuroraCellTracker.DaekhonCoporation;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AuroraDeviceCommon.Utils;
using Hermes;
using System.Windows;
namespace AuroraCellTracker
{
public enum eCellTrackerType
{
Daekhon,
}
public enum eMode
{
Queue,
Callback
}
public class CellTracker : Device
{
Logger _Logger = new Logger("CellTracker");
ICellTracker _CellTracker;
public CellTrackerConfig _CellTrackerConfig { get; set; }
private ICellTracker[] _MultiCellTrackerObj = new ICellTracker[4];
public ICellTracker[] MultiCellTrackerObj {
get { return _MultiCellTrackerObj; }
set { _MultiCellTrackerObj = value; }
}
protected bool _isSimulBySetting; // 시스템 세팅의 simul flag 저장. Activate 시, Config 의 시뮬 flag 와 조합하여 최종 결정
public CellTracker(string deviceId, eCellTrackerType cellTrackerType, bool isSimul = false)
{
DeviceId = deviceId;
CommType = CommunicationType.Etc;
Type = DeviceType.Etc;
_isSimulBySetting = isSimul;
// 주의: 생성자에서 config 값을 가져오기 번거로우니 아래와 같이 처리
// 생성자에서는 시스템 세팅의 Simul 정보만 사용 (시리얼포트의 IsSimul 까지 처리됨)
// 상위단(여기)에서 DoActivate 시, simul flag 를 최종 결정
// 방침: 시뮬은 상위단에서 처리하는 구조 (내부 _PowerMeter 사용안함 (= 시리얼포트 사용안함))
switch (cellTrackerType) {
case eCellTrackerType.Daekhon:
_CellTracker = new CellTrackerDaekhon();
break;
default:
_Logger.E("Error: CellTracker Type is not available.");
return;
}
_CellTracker.SetCellInfo(string.Empty, string.Empty);
}
protected override int DoActivate(IDeviceConfig config)
{
_CellTrackerConfig = config as CellTrackerConfig;
IsSimul = _isSimulBySetting || _CellTrackerConfig.IsDeviceSimul;
if (IsSimul) {
return E1.OK;
}
// 예외처리 필요, 연결안됬을때 에러코드 받고 이런게 없는듯..
if (string.IsNullOrEmpty(_CellTrackerConfig.CellTrackerDllDirectory)) {
_Logger.E(string.Format("Dll Directory is Empty"));
return E1.ARGUMENT;
}
Application.Current.Dispatcher.InvokeAsync(() => {
_CellTracker.Initialize(_CellTrackerConfig.CellTrackerMode, _CellTrackerConfig.CellTrackerDllDirectory);
_CellTracker.SetIdComponent(_CellTrackerConfig.CellIdStartNo, _CellTrackerConfig.CellIdLength, _CellTrackerConfig.LotIdStartNo, _CellTrackerConfig.LotIdLength);
});
return E1.OK;
}
protected override int DoDeactivate()
{
if (!IsSimul) {
Application.Current.Dispatcher.InvokeAsync(() => {
_CellTracker?.Close();
});
}
return E1.OK;
}
private void Initialize(IDeviceConfig config)
{
if (_CellTracker == null) {
return;
}
_CellTrackerConfig = config as CellTrackerConfig;
IsSimul = _isSimulBySetting || _CellTrackerConfig.IsDeviceSimul;
if (IsSimul) {
return;
}
// 예외처리 필요, 연결안됬을때 에러코드 받고 이런게 없는듯..
if (string.IsNullOrEmpty(_CellTrackerConfig.CellTrackerDllDirectory)) {
_Logger.E(string.Format("Dll Directory is Empty"));
return;
}
_CellTracker.Initialize(_CellTrackerConfig.CellTrackerMode, _CellTrackerConfig.CellTrackerDllDirectory);
}
public CellInfoStr GetCellInfoStrings()
{
if (!IsActivated) {
return null;
}
return _CellTracker.GetCellInfoStrings();
}
public void ReceiveData()
{
if (!IsActivated) {
return;
}
_CellTracker.ReceiveData();
}
public void SendEcsData(string strCellID, string strPath, string strData)
{
if (!IsActivated) {
return;
}
_CellTracker.SendEcsData(strCellID, strPath, strData);
}
public void SetIPConfig()
{
if (!IsActivated) {
return;
}
_CellTracker.SetIPConfig();
}
}
}