You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
3.4 KiB
97 lines
3.4 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using leak_test_project.Infrastructure;
|
|
using leak_test_project.Models;
|
|
using leak_test_project.Utils;
|
|
|
|
namespace leak_test_project.Services
|
|
{
|
|
/// <summary>
|
|
/// 시리얼 통신을 기반으로 동작하는 신규 4253 DIO 보드 구현체.
|
|
/// 기존 RealDioBoard(Legacy)와 교체 가능함.
|
|
/// </summary>
|
|
public class Board4253DioBoard : IDioBoard
|
|
{
|
|
private readonly Board4253Service _service;
|
|
private readonly List<DioPoint> _inputs = new List<DioPoint>();
|
|
private readonly List<DioPoint> _outputs = new List<DioPoint>();
|
|
private bool _isDisposed = false;
|
|
|
|
#pragma warning disable 0067
|
|
public event EventHandler<DioEventArgs> InputChanged;
|
|
#pragma warning restore 0067
|
|
|
|
public event EventHandler<string> ErrorOccurred;
|
|
|
|
public Board4253DioBoard(Board4253Service service)
|
|
{
|
|
_service = service;
|
|
_service.ErrorOccurred += (s, msg) => ErrorOccurred?.Invoke(this, msg);
|
|
InitializePoints();
|
|
}
|
|
|
|
private void InitializePoints()
|
|
{
|
|
// 실제 보드 구성에 맞게 입출력 포인트 정의 (DioConfigParser 기반 혹은 하드코딩)
|
|
// 일단 기존 프로젝트 구성과 호환되도록 빈 리스트 혹은 기본값 설정
|
|
var config = DioConfigParser.LoadDefault();
|
|
_inputs.AddRange(config.InputPoints);
|
|
_outputs.AddRange(config.OutputPoints);
|
|
}
|
|
|
|
public bool Initialize()
|
|
{
|
|
// 시리얼 연결 시도
|
|
try {
|
|
if (!_service.Connect())
|
|
{
|
|
ErrorOccurred?.Invoke(this, $"4253 Board: Failed to open serial port.");
|
|
return false;
|
|
}
|
|
|
|
// 보드 상태 확인
|
|
var statusTask = Task.Run(() => _service.CheckStatusAsync());
|
|
if (!statusTask.Wait(5000))
|
|
{
|
|
ErrorOccurred?.Invoke(this, "4253 Board: Initialization Timeout (CheckStatus).");
|
|
return false;
|
|
}
|
|
|
|
return statusTask.Result;
|
|
} catch (Exception ex) {
|
|
ErrorOccurred?.Invoke(this, $"4253 Board: Initialization Error - {ex.Message}");
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public bool ReadInput(string pointName)
|
|
{
|
|
// 신규 보드의 입력 읽기 프로토콜이 필요한 부분 (현재 ReadId 등만 구현됨)
|
|
// 구현 계획에는 ID 읽기와 상태 확인만 있었으므로,
|
|
// 실제 DIO 기능을 위해선 추가적인 시리얼 명령이 필요할 수 있음.
|
|
// 일단 true/false 로직 구현
|
|
return false;
|
|
}
|
|
|
|
public void WriteOutput(string pointName, bool value)
|
|
{
|
|
// 보드 출력 제어 명령 전송 (예시 프로토콜 필요)
|
|
// _service.SendCommandAsync(...) 호출 형태가 될 것임.
|
|
}
|
|
|
|
public List<DioPoint> GetInputPoints() => _inputs;
|
|
public List<DioPoint> GetOutputPoints() => _outputs;
|
|
|
|
public void Dispose()
|
|
{
|
|
if (!_isDisposed)
|
|
{
|
|
_isDisposed = true;
|
|
_service.Disconnect();
|
|
_service.Dispose();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|