2026-01-26 14:51:28 +09:00

431 lines
18 KiB
C#

using Aurora;
using Aurora.Api;
using Aurora.View;
using AuroraCAS;
using AuroraCellTracker;
using AuroraIO;
using AuroraLaser;
using AuroraLaserScanner;
using AuroraLBAD;
using AuroraMotionBoard.Ajin;
using AuroraOCT;
using AuroraUIComponent.Dialog;
using System;
//using PropertyTools.Wpf;
using System.Collections.ObjectModel;
using System.Configuration;
using System.IO;
using System.Windows;
using System.Windows.Input;
using WeldingCommon.Utils;
namespace WeldingCommon.Views
{
public class UCTestDeviceViewModel : NotifyPropertyChangedBase
{
private readonly Logger Log = new Logger("UCTestDeviceViewModel");
private readonly IAuroraEnvironment _AuroraEnv;
private readonly CAS _CAS;
private readonly CellTracker _CellTracker;
private readonly IODevice _IODevice;
private readonly ILaserDevice _Laser;
private readonly Scanner _Scanner;
private readonly LBAD _LBAD;
private readonly AJINDevice _AJINDevice;
private readonly AJINMotor _AJINMotor;
private readonly OCT _OCT;
public ICommand CMD_VisibleChanged { get; }
public ICommand CMD_TestDevice_CAS { get; }
public ICommand CMD_TestDevice_CellTracker { get; }
public ICommand CMD_TestDevice_IODevice { get; }
public ICommand CMD_TestDevice_Laser { get; }
public ICommand CMD_TestDevice_Scanner { get; }
public ICommand CMD_TestDevice_LBAD { get; }
public ICommand CMD_TestDevice_AJINDevice { get; }
public ICommand CMD_TestDevice_OCT { get; }
private bool _CASEnabled = false;
public bool CASEnabled { get => _CASEnabled; set => SetProperty(ref _CASEnabled, value); }
private bool _CellTrackerEnabled = false;
public bool CellTrackerEnabled { get => _CellTrackerEnabled; set => SetProperty(ref _CellTrackerEnabled, value); }
private bool _IODeviceEnabled = false;
public bool IODeviceEnabled { get => _IODeviceEnabled; set => SetProperty(ref _IODeviceEnabled, value); }
private bool _LaserEnabled = false;
public bool LaserEnabled { get => _LaserEnabled; set => SetProperty(ref _LaserEnabled, value); }
private bool _ScannerEnabled = false;
public bool ScannerEnabled { get => _ScannerEnabled; set => SetProperty(ref _ScannerEnabled, value); }
private bool _LBADEnabled = false;
public bool LBADEnabled { get => _LBADEnabled; set => SetProperty(ref _LBADEnabled, value); }
private bool _AJINDeviceEnabled = false;
public bool AJINDeviceEnabled { get => _AJINDeviceEnabled; set => SetProperty(ref _AJINDeviceEnabled, value); }
private bool _OCTEnabled = false;
public bool OCTEnabled { get => _OCTEnabled; set => SetProperty(ref _OCTEnabled, value); }
public ObservableCollection<string> CASMethodList { get; set; } = new ObservableCollection<string>();
public ObservableCollection<string> CellTrackerMethodList { get; set; } = new ObservableCollection<string>();
public ObservableCollection<string> IODeviceMethodList { get; set; } = new ObservableCollection<string>();
public ObservableCollection<string> LaserMethodList { get; set; } = new ObservableCollection<string>();
public ObservableCollection<string> ScannerMethodList { get; set; } = new ObservableCollection<string>();
public ObservableCollection<string> LBADMethodList { get; set; } = new ObservableCollection<string>();
public ObservableCollection<string> AJINDeviceMethodList { get; set; } = new ObservableCollection<string>();
public ObservableCollection<string> OCTMethodList { get; set; } = new ObservableCollection<string>();
private string _Selected_CASMethod;
public string Selected_CASMethod { get => _Selected_CASMethod; set => SetProperty(ref _Selected_CASMethod, value); }
private string _Selected_CellTrackerMethod;
public string Selected_CellTrackerMethod { get => _Selected_CellTrackerMethod; set => SetProperty(ref _Selected_CellTrackerMethod, value); }
private string _Selected_IODeviceMethod;
public string Selected_IODeviceMethod { get => _Selected_IODeviceMethod; set => SetProperty(ref _Selected_IODeviceMethod, value); }
private string _Selected_LaserMethod;
public string Selected_LaserMethod { get => _Selected_LaserMethod; set => SetProperty(ref _Selected_LaserMethod, value); }
private string _Selected_ScannerMethod;
public string Selected_ScannerMethod { get => _Selected_ScannerMethod; set => SetProperty(ref _Selected_ScannerMethod, value); }
private string _Selected_LBADMethod;
public string Selected_LBADMethod { get => _Selected_LBADMethod; set => SetProperty(ref _Selected_LBADMethod, value); }
private string _Selected_AJINDeviceMethod;
public string Selected_AJINDeviceMethod { get => _Selected_AJINDeviceMethod; set => SetProperty(ref _Selected_AJINDeviceMethod, value); }
private string _Selected_OCTMethod;
public string Selected_OCTMethod { get => _Selected_OCTMethod; set => SetProperty(ref _Selected_OCTMethod, value); }
public UCTestDeviceViewModel(IAuroraEnvironment aurora)
{
_AuroraEnv = aurora;
//Device 있을때만 View에서 조작 가능하게 할 것.
_CAS = _AuroraEnv.DeviceManager[CommonDeviceIds.CAS] as CAS;
if (_CAS != null) {
CASEnabled = true;
}
_CellTracker = _AuroraEnv.DeviceManager[CommonDeviceIds.CellTracker] as CellTracker;
if (_CellTracker != null) {
CellTrackerEnabled = true;
}
_IODevice = _AuroraEnv.DeviceManager[CommonDeviceIds.IODevice] as IODevice;
if (_IODevice != null) {
IODeviceEnabled = true;
}
_Laser = _AuroraEnv.DeviceManager[CommonDeviceIds.Laser] as ILaserDevice;
if (_Laser != null) {
LaserEnabled = true;
}
_Scanner = _AuroraEnv.DeviceManager[CommonDeviceIds.Scanner] as Scanner;
if (_Scanner != null) {
ScannerEnabled = true;
}
_LBAD = _AuroraEnv.DeviceManager[CommonDeviceIds.LBAD] as LBAD;
if (_LBAD != null) {
LBADEnabled = true;
}
_AJINDevice = _AuroraEnv.DeviceManager[CommonDeviceIds.AJIN] as AJINDevice;
_AJINMotor = _AuroraEnv.DeviceManager[CommonDeviceIds.AJINStageMotorZ] as AJINMotor;
if (_AJINDevice != null && _AJINMotor != null) {
AJINDeviceEnabled = true;
}
_OCT = _AuroraEnv.DeviceManager[CommonDeviceIds.OCT] as OCT;
if (_OCT != null) {
OCTEnabled = true;
}
CMD_TestDevice_CAS = new DelegateCommand(PerformCmdTestDevice_CAS);
CMD_TestDevice_CellTracker = new DelegateCommand(PerformCmdTestDevice_CellTracker);
CMD_TestDevice_IODevice = new DelegateCommand(PerformCmdTestDevice_IODevice);
CMD_TestDevice_Laser = new DelegateCommand(PerformCmdTestDevice_Laser);
CMD_TestDevice_Scanner = new DelegateCommand(PerformCmdTestDevice_Scanner);
CMD_TestDevice_LBAD = new DelegateCommand(PerformCmdTestDevice_LBAD);
CMD_TestDevice_AJINDevice = new DelegateCommand(PerformCmdTestDevice_AJINDevice);
CMD_TestDevice_OCT = new DelegateCommand(PerformCmdTestDevice_OCT);
#region Make Method List
//CAS
CASMethodList.Add("GetCurrentWeight");
CASMethodList.Add("GetLowLimit");
CASMethodList.Add("GetHighLimit");
//CellTracker
CellTrackerMethodList.Add("ReceiveData");
CellTrackerMethodList.Add("GetCellInfoStrings");
CellTrackerMethodList.Add("SaveSendingData");
//IODevice
IODeviceMethodList.Add("WriteDoBit");
IODeviceMethodList.Add("ReadDiBit");
IODeviceMethodList.Add("ReadDoBit");
//Laser
LaserMethodList.Add("GetConnected");
LaserMethodList.Add("Open");
LaserMethodList.Add("PilotLaserOff");
LaserMethodList.Add("LaserOff");
LaserMethodList.Add("GetLaserReady");
LaserMethodList.Add("GetPilotLaserStatus");
LaserMethodList.Add("GetPilotLaserSetBitStatus");
//Scanner
ScannerMethodList.Add("StopExecution");
ScannerMethodList.Add("WriteDA");
ScannerMethodList.Add("SelectCorrectionTable");
ScannerMethodList.Add("Open");
ScannerMethodList.Add("GetTime");
ScannerMethodList.Add("GetBusyStatus");
ScannerMethodList.Add("GetXYPos");
ScannerMethodList.Add("GetLatestFile");
//LBAD
LBADMethodList.Add("SendCellData");
LBADMethodList.Add("GetResult");
LBADMethodList.Add("GetLaserPower");
LBADMethodList.Add("GetConnected");
LBADMethodList.Add("DisConnect");
LBADMethodList.Add("Open");
//AJIN Device : MotionBoard
AJINDeviceMethodList.Add("MoveABS");
AJINDeviceMethodList.Add("GetCurrentPosition");
AJINDeviceMethodList.Add("CheckInside");
AJINDeviceMethodList.Add("ReadInMotion");
//OCT
OCTMethodList.Add("AddWorkPieceID");
OCTMethodList.Add("SetProgram");
OCTMethodList.Add("GetRemoteControl");
OCTMethodList.Add("SetRemoteControl");
OCTMethodList.Add("EnterRemoteMode");
OCTMethodList.Add("SaveMetaData");
#endregion
}
private void PerformCmdTestDevice_CAS(object commandParameter)
{
switch ((string)commandParameter) {
case "GetCurrentWeight": {
_CAS.GetCurrentWeight();
}
break;
case "GetLowLimit": {
_CAS.GetLowLimit();
}
break;
case "GetHighLimit": {
_CAS.GetHighLimit();
}
break;
default:
break;
}
}
private void PerformCmdTestDevice_CellTracker(object commandParameter)
{
switch ((string)commandParameter) {
case "ReceiveData": {
_CellTracker.ReceiveData();
}
break;
case "GetCellInfoStrings": {
_CellTracker.GetCellInfoStrings();
}
break;
case "SaveSendingData": {
#warning 원래는 EDC에 CellData를 주고, EDC로부터 strItem과 strData를 받아 Save 하는 메소드
string strItem = "";
string strData = "";
string strPath = "";
ExcelManagementUnit.AppendStringInCSV(strPath, strItem, strData);
}
break;
}
}
private void PerformCmdTestDevice_IODevice(object commandParameter)
{
#warning Indx와 bit는 장비에 따라 수정해서 사용
int index = 1;
bool bit = true;
switch ((string)commandParameter) {
case "WriteDoBit": {
_IODevice._iOUnit.WriteDoBit(index, bit);
}
break;
case "ReadDiBit": {
_IODevice._iOUnit.ReadDiBit(index, ref bit);
}
break;
case "ReadDoBit": {
_IODevice._iOUnit.ReadDoBit(index, ref bit);
}
break;
}
}
private void PerformCmdTestDevice_Laser(object commandParameter)
{
switch ((string)commandParameter) {
case "GetConnected": {
_Laser.GetConnected();
}
break;
case "Open": {
_Laser.ActivateDevice();
}
break;
case "PilotLaserOff": {
_Laser.PilotLaserOff();
}
break;
case "LaserOff": {
_Laser.LaserOff();
}
break;
case "GetLaserReady": {
_Laser.GetLaserReady();
}
break;
case "GetPilotLaserStatus": {
_Laser.GetPilotLaserStatus();
}
break;
case "GetPilotLaserSetBitStatus": {
_Laser.GetPilotLaserSetBitStatus();
}
break;
}
}
private void PerformCmdTestDevice_Scanner(object commandParameter)
{
switch ((string)commandParameter) {
case "StopExecution": {
_Scanner.StopExecution();
}
break;
case "WriteDA": {
_Scanner.WriteDA(1, 0);
}
break;
case "SelectCorrectionTable": {
_Scanner.SelectCorrectionTable(1);
}
break;
case "Open": {
_Scanner.Open();
}
break;
case "GetTime": {
_Scanner.GetTime();
}
break;
case "GetBusyStatus": {
_Scanner.GetBusyStatus();
}
break;
case "GetXYPos": {
_Scanner.GetXYPos(out double x, out double y);
}
break;
case "GetLatestFile": {
string dirPath = ProjectUtil.GetDataLogSetting().GetDirPath_ScannerRecordLog_MetaData();
_Scanner.GetLatestFile(dirPath);
}
break;
}
}
private void PerformCmdTestDevice_LBAD(object commandParameter)
{
switch ((string)commandParameter) {
case "SendCellData": {
_LBAD.SendCellData();
}
break;
case "GetResult": {
_LBAD.GetResult(out short result);
}
break;
case "GetLaserPower": {
//_LBAD.GetLaserPower(out string SubPower, out string MainPower);
// 함수 삭제 됨.
}
break;
case "GetConnected": {
_LBAD.GetConnected();
}
break;
case "DisConnect": {
_LBAD.DisConnect();
}
break;
case "Open": {
_LBAD.Open(_LBAD.Config);
}
break;
}
}
private void PerformCmdTestDevice_AJINDevice(object commandParameter)
{
//Z축만 받아서 검증합니다.
int Axis = 0; // 0번 Z축
double Pos = 0;
switch ((string)commandParameter) {
case "MoveABS": {
_AJINDevice.MoveABS(Axis, Pos, _AJINMotor._Config.Speed, _AJINMotor._Config.Acceleration, _AJINMotor._Config.Deceleration);
}
break;
case "GetCurrentPosition": {
_AJINDevice.GetCurrentPosition(Axis);
}
break;
case "CheckInside": {
_AJINDevice.CheckInside(Pos, _AJINDevice.GetCurrentPosition(Axis));
}
break;
case "ReadInMotion": {
_AJINDevice.ReadInMotion(Axis);
}
break;
}
}
private void PerformCmdTestDevice_OCT(object commandParameter)
{
switch ((string)commandParameter) {
case "AddWorkPieceID": {
#warning ViewModel Recipe에서 직접 값을 가져오는 strID를 삽입하므로 값을 유추할수 없어 임의의 str을 넣었습니다. 사용에 유의바랍니다.
_OCT.AddWorkPieceID("1");
}
break;
case "SetProgram": {
_OCT.SetProgram(1);
}
break;
case "GetRemoteControl": {
_OCT.GetRemoteControl();
}
break;
case "SetRemoteControl": {
_OCT.SetRemoteControl(2);
}
break;
case "EnterRemoteMode": {
_OCT.EnterRemoteMode(30000);
}
break;
case "SaveMetaData": {
#warning 이 함수는 현재 사용되지 않는 private 메소드의 일부이며, 검증에 필요한 매개변수가 너무 많으므로 Pass합니다.
//_OCT.SaveMetaData();
}
break;
}
}
}
}