2026-01-26 18:56:53 +09:00

679 lines
24 KiB
C#

using Aurora.Api.Manager;
using Aurora.Api;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Aurora.View;
using Aurora;
using System.Collections.ObjectModel;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Threading;
using AuroraOCT.IPG;
namespace AuroraOCT.Views
{
internal class UCOCTManualMotionViewModel : NotifyPropertyChangedBase
{
Logger Log = new Logger("OCT");
#region Xaml Property
private ObservableCollection<ListItem> _ListItemSerialNumbers;
public ObservableCollection<ListItem> ListItemSerialNumbers { get => _ListItemSerialNumbers; set => SetProperty(ref _ListItemSerialNumbers, value); }
private ObservableCollection<ListItem> _ListItemLDDSerialNumbers;
public ObservableCollection<ListItem> ListItemLDDSerialNumbers { get => _ListItemLDDSerialNumbers; set => SetProperty(ref _ListItemLDDSerialNumbers, value); }
private string _strCellSerialNumber;
public string strCellSerialNumber { get => _strCellSerialNumber; set => SetProperty(ref _strCellSerialNumber, value); }
private string _strJobName;
public string strJobName { get => _strJobName; set => SetProperty(ref _strJobName, value); }
private string _strSequenceName;
public string strSequenceName { get => _strSequenceName; set => SetProperty(ref _strSequenceName, value); }
private string _strJobCMDResult;
public string strJobCMDResult { get => _strJobCMDResult; set => SetProperty(ref _strJobCMDResult, value); }
private string _strSequenceCMDResult;
public string strSequenceCMDResult { get => _strSequenceCMDResult; set => SetProperty(ref _strSequenceCMDResult, value); }
private string _strJob_KHD_Judge;
public string strJob_KHD_Judge { get => _strJob_KHD_Judge; set => SetProperty(ref _strJob_KHD_Judge, value); }
private string _strSequence_KHD_Judge;
public string strSequence_KHD_Judge { get => _strSequence_KHD_Judge; set => SetProperty(ref _strSequence_KHD_Judge, value); }
private string _strJob_KHD_AVG;
public string strJob_KHD_AVG { get => _strJob_KHD_AVG; set => SetProperty(ref _strJob_KHD_AVG, value); }
private string _strJob_KHD_MAX;
public string strJob_KHD_MAX { get => _strJob_KHD_MAX; set => SetProperty(ref _strJob_KHD_MAX, value); }
private string _strJob_KHD_MIN;
public string strJob_KHD_MIN { get => _strJob_KHD_MIN; set => SetProperty(ref _strJob_KHD_MIN, value); }
private string _strJob_KHD_LOWSUM;
public string strJob_KHD_LOWSUM { get => _strJob_KHD_LOWSUM; set => SetProperty(ref _strJob_KHD_LOWSUM, value); }
private string _strJob_KHD_HIGHSUM;
public string strJob_KHD_HIGHSUM { get => _strJob_KHD_HIGHSUM; set => SetProperty(ref _strJob_KHD_HIGHSUM, value); }
private string _strSequence_KHD_AVG;
public string strSequence_KHD_AVG { get => _strSequence_KHD_AVG; set => SetProperty(ref _strSequence_KHD_AVG, value); }
private string _strSequence_KHD_MAX;
public string strSequence_KHD_MAX { get => _strSequence_KHD_MAX; set => SetProperty(ref _strSequence_KHD_MAX, value); }
private string _strSequence_KHD_MIN;
public string strSequence_KHD_MIN { get => _strSequence_KHD_MIN; set => SetProperty(ref _strSequence_KHD_MIN, value); }
private string _strSequence_KHD_LOWSUM;
public string strSequence_KHD_LOWSUM { get => _strSequence_KHD_LOWSUM; set => SetProperty(ref _strSequence_KHD_LOWSUM, value); }
private string _strSequence_KHD_HIGHSUM;
public string strSequence_KHD_HIGHSUM { get => _strSequence_KHD_HIGHSUM; set => SetProperty(ref _strSequence_KHD_HIGHSUM, value); }
private string OCTState = "Initializing";
private bool _bRadioInitializing;
public bool bRadioInitializing { get => _bRadioInitializing; set => SetProperty(ref _bRadioInitializing, value); }
private bool _bRadioReady;
public bool bRadioReady { get => _bRadioReady; set => SetProperty(ref _bRadioReady, value); }
private bool _bRadioBusy;
public bool bRadioBusy { get => _bRadioBusy; set => SetProperty(ref _bRadioBusy, value); }
private bool _bRadioNoRespone;
public bool bRadioNoRespone { get => _bRadioNoRespone; set => SetProperty(ref _bRadioNoRespone, value); }
private bool _bRadioAcquiring;
public bool bRadioAcquiring { get => _bRadioAcquiring; set => SetProperty(ref _bRadioAcquiring, value); }
private bool _bRadioProcessing;
public bool bRadioProcessing { get => _bRadioProcessing; set => SetProperty(ref _bRadioProcessing, value); }
private bool _bRadioWaitingTrigger;
public bool bRadioWaitingTrigger { get => _bRadioWaitingTrigger; set => SetProperty(ref _bRadioWaitingTrigger, value); }
private bool _bRadioNotRemoteMode;
public bool bRadioNotRemoteMode { get => _bRadioNotRemoteMode; set => SetProperty(ref _bRadioNotRemoteMode, value); }
#endregion
#region Envent Command
public ICommand CMD_VisibleChanged { get; }
public ICommand CMD_ReloadSerialNumber { get; }
public ICommand CMD_ClearSerialNumber { get; }
public ICommand CMD_GetSerialNumberFromFile { get; }
public ICommand CMD_AddSerialNumber { get; }
public ICommand CMD_CheckSerialNumber { get; }
public ICommand CMD_RemoveSerialNumber { get; }
public ICommand CMD_Connect { get; }
public ICommand CMD_DisConnect { get; }
public ICommand CMD_StartSW { get; }
public ICommand CMD_SetSequenceFile { get; }
public ICommand CMD_RunSequence { get; }
public ICommand CMD_StopSequence { get; }
public ICommand CMD_ENTER_SEQUENCE { get; }
public ICommand CMD_EXIT_SEQUENCE { get; }
public ICommand CMD_GetLastSequenceResult { get; }
public ICommand CMD_GetLastJobResult { get; }
public ICommand CMD_OCTStateChanged { get; }
public ICommand CMD_RunJob { get; }
public ICommand CMD_StopJob { get; }
public ICommand CMD_ENTER_JOB { get; }
public ICommand CMD_EXIT_JOB { get; }
public ICommand CMD_JOB_GET_REMOTE_MODE { get; }
public ICommand CMD_JOB_GET_JUDGE { get; }
public ICommand CMD_JOB_GET_AVG { get; }
public ICommand CMD_JOB_GET_MAX { get; }
public ICommand CMD_JOB_GET_MIN { get; }
public ICommand CMD_JOB_GET_LOWSUM { get; }
public ICommand CMD_JOB_GET_HIGHSUM { get; }
public ICommand CMD_SEQUENCE_GET_REMOTE_MODE { get; }
public ICommand CMD_SEQUENCE_GET_JUDGE { get; }
public ICommand CMD_SEQUENCE_GET_AVG { get; }
public ICommand CMD_SEQUENCE_GET_MAX { get; }
public ICommand CMD_SEQUENCE_GET_MIN { get; }
public ICommand CMD_SEQUENCE_GET_LOWSUM { get; }
public ICommand CMD_SEQUENCE_GET_HIGHSUM { get; }
private readonly DispatcherTimer _CurrentStatusUpdateTimer;
#endregion
private readonly IDeviceManager _deviceManger;
private readonly OCT _OCT;
//private readonly OCTConfig _config;
public UCOCTManualMotionViewModel(IAuroraEnvironment aurora, string deviceId)
{
_deviceManger = aurora.DeviceManager;
_OCT = _deviceManger[deviceId] as OCT;
#region DelegateCommand
CMD_VisibleChanged = new DelegateCommand(VisibleChanged);
CMD_ReloadSerialNumber = new DelegateCommand(ReloadSerialNumber);
CMD_ClearSerialNumber = new DelegateCommand(ClearSerialNumber);
CMD_GetSerialNumberFromFile = new DelegateCommand(GetSerialNumberFromFile);
CMD_AddSerialNumber = new DelegateCommand(AddSerialNumber);
CMD_CheckSerialNumber = new DelegateCommand(CheckSerialNumber);
CMD_RemoveSerialNumber = new DelegateCommand(RemoveSerialNumber);
CMD_Connect = new DelegateCommand(Connect);
CMD_DisConnect = new DelegateCommand(DisConnect);
CMD_StartSW = new DelegateCommand(StartSW);
CMD_OCTStateChanged = new DelegateCommand(OCTStateChanged);
CMD_RunJob = new DelegateCommand(StartJob);
CMD_StopJob = new DelegateCommand(StopJob);
CMD_ENTER_JOB = new DelegateCommand(EnterJobMode);
CMD_EXIT_JOB = new DelegateCommand(ExitRemoteMode);
CMD_JOB_GET_REMOTE_MODE = new DelegateCommand(GetJobRemoteMode);
CMD_JOB_GET_JUDGE = new DelegateCommand(GetJobResult);
CMD_JOB_GET_AVG = new DelegateCommand(GetJobAvg);
CMD_JOB_GET_MAX = new DelegateCommand(GetJobMax);
CMD_JOB_GET_MIN = new DelegateCommand(GetJobMin);
CMD_JOB_GET_LOWSUM = new DelegateCommand(GetJobLowSum);
CMD_JOB_GET_HIGHSUM = new DelegateCommand(GetJobHighSum);
CMD_RunSequence = new DelegateCommand(StartSequence);
CMD_StopSequence = new DelegateCommand(StopSequence);
CMD_ENTER_SEQUENCE = new DelegateCommand(EnterSequenceMode);
CMD_EXIT_SEQUENCE = new DelegateCommand(ExitRemoteMode);
CMD_SEQUENCE_GET_REMOTE_MODE = new DelegateCommand(GetSequenceRemoteMode);
CMD_SEQUENCE_GET_JUDGE = new DelegateCommand(GetSequenceResult);
CMD_SEQUENCE_GET_AVG = new DelegateCommand(GetSequenceAvg);
CMD_SEQUENCE_GET_MAX = new DelegateCommand(GetSequenceMax);
CMD_SEQUENCE_GET_MIN = new DelegateCommand(GetSequenceMin);
CMD_SEQUENCE_GET_LOWSUM = new DelegateCommand(GetSequenceLowSum);
CMD_SEQUENCE_GET_HIGHSUM = new DelegateCommand(GetSequenceHighSum);
#endregion
InitializeUIProperties();
_CurrentStatusUpdateTimer = new DispatcherTimer();
_CurrentStatusUpdateTimer.Tick += OnMonitoring;
_CurrentStatusUpdateTimer.Interval = TimeSpan.FromMilliseconds(200);
}
private void InitializeUIProperties()
{
}
private void OnMonitoring(object sender, EventArgs e)
{
GetOCTState();
OCTStateChange();
}
#region Event Functions
private void VisibleChanged(object obj)
{
bool visible = (bool)obj;
if (visible) {
_CurrentStatusUpdateTimer?.Start();
} else {
_CurrentStatusUpdateTimer?.Stop();
}
}
private void ReloadSerialNumber(object obj)
{
if (_OCT.IsSimul) {
return;
}
if (_OCT != null) {
if (_OCT.Config.Type == eOCTType.IPG_LDD700) {
}
// _OCT..functions
}
}
private void ClearSerialNumber(object obj)
{
if (_OCT.IsSimul) {
return;
}
if (_OCT != null) {
// _OCT..functions
}
}
private void GetSerialNumberFromFile(object obj)
{
if (_OCT.IsSimul) {
return;
}
if (_OCT != null) {
//var oct = _OCT._OCT as LDD700;
_ListItemLDDSerialNumbers.Clear();
foreach (var item in ListItemSerialNumbers) {
string strRet;
//if (oct.get_serial_number(item.Name, out strRet) == (int)eLDDErr.ACK) {
if (_OCT.get_serial_number(item.Name, out strRet) == (int)eLDDErr.ACK) {
ListItem listItem = new ListItem { Name = strRet };
_ListItemLDDSerialNumbers.Add(listItem);
}
}
// _OCT..functions
}
}
public void AddSerialNumber(object obj)
{
if (_OCT.IsSimul) {
return;
}
if (strCellSerialNumber == null || strCellSerialNumber.Length < 1) {
MessageUtil.CreateAndShowMessageDialog("Fail", "SerialNumber is empty");
return;
}
if (_OCT != null) {
//var oct = _OCT._OCT as LDD700;
//oct.AddWorkPieceID(strCellSerialNumber);
_OCT.AddWorkPieceID(strCellSerialNumber);
}
}
public void CheckSerialNumber(object obj)
{
if (_OCT.IsSimul) {
return;
}
if (strCellSerialNumber == null || strCellSerialNumber.Length < 1) {
MessageUtil.CreateAndShowMessageDialog("Fail", "SerialNumber is empty");
return;
}
if (_OCT != null) {
//var oct = _OCT._OCT as LDD700;
//if (oct.CheckWorkPieceID(strCellSerialNumber) == 0) {
if (_OCT.CheckWorkPieceID(strCellSerialNumber) == 0) {
MessageUtil.CreateAndShowMessageDialog("Success", string.Format("{0} SerialNumber is registered", strCellSerialNumber));
} else {
MessageUtil.CreateAndShowMessageDialog("Fail", string.Format("{0} SerialNumber is not registered", strCellSerialNumber));
}
}
}
private void RemoveSerialNumber(object obj)
{
if (_OCT.IsSimul) {
return;
}
if (_OCT != null) {
// _OCT..functions
}
}
private void Connect(object obj)
{
if (_OCT.IsSimul) {
return;
}
if (_OCT != null) {
//var oct = _OCT._OCT as LDD700;
//oct.Open(_OCT.Config);
_OCT.Open(_OCT.Config);
//if (_OCT._OCT.GetConnected()) {
if (_OCT.GetConnected()) {
MessageUtil.CreateAndShowMessageDialog("Success", "OCT is Connected.");
} else {
MessageUtil.CreateAndShowMessageDialog("Fail", "OCT is not Connected.");
}
}
}
private void DisConnect(object obj)
{
if (_OCT.IsSimul) {
return;
}
if (_OCT != null) {
//var oct = _OCT._OCT as LDD700;
//oct.DisConnect();
_OCT.DisConnect();
}
}
private void StartSW(object obj)
{
if (_OCT.IsSimul) {
return;
}
if (_OCT != null) {
//var oct = _OCT._OCT as LDD700;
//oct.start_software();
_OCT.start_software();
//if (_OCT._OCT.GetConnected()) {
if (_OCT.GetConnected()) {
MessageUtil.CreateAndShowMessageDialog("Success", "OCT is Connected.");
} else {
MessageUtil.CreateAndShowMessageDialog("Fail", "OCT is not Connected.");
}
}
}
private void StopJob(object obj)
{
if (_OCT.IsSimul) {
return;
}
if (_OCT != null) {
//var oct = _OCT._OCT as LDD700;
//if (oct.stop() == 0) {
if (_OCT.stop() == 0) {
MessageUtil.CreateAndShowMessageDialog("Success", "Job Stopped.");
} else {
MessageUtil.CreateAndShowMessageDialog("Fail", "Job Stop is Failed.");
}
}
}
private void StopSequence(object obj)
{
if (_OCT.IsSimul) {
return;
}
if (_OCT != null) {
//var oct = _OCT._OCT as LDD700;
//if (oct.stop() == 0) {
if (_OCT.stop() == 0) {
MessageUtil.CreateAndShowMessageDialog("Success", "Sequence Stopped.");
} else {
MessageUtil.CreateAndShowMessageDialog("Fail", "Sequence Stop is Failed.");
}
}
}
#endregion
public class ListItem
{
public string Name { get; set; }
public override string ToString()
{
return Name;
}
}
private void OCTStateChanged(object obj)
{
OCTState = (string)obj;
}
private void EnterJobMode(object obj)
{
if (_OCT.IsSimul) {
return;
}
if (_OCT != null) {
_OCT.SetRemoteControl(1);
if (_OCT.EnterRemoteMode(20000) == 0) {
}
}
}
private void EnterSequenceMode(object obj)
{
if (_OCT.IsSimul) {
return;
}
if (_OCT != null) {
_OCT.SetRemoteControl(2);
if (_OCT.EnterRemoteMode(20000) == 0) {
}
}
}
private void ExitRemoteMode(object obj)
{
if (_OCT.IsSimul) {
return;
}
if (_OCT != null) {
if (_OCT.ExitRemoteMode() == 0) {
}
}
}
private void StartJob(object obj)
{
if (_OCT.IsSimul) {
return;
}
if (_OCT != null) {
if (strJobName == null || strJobName.Length < 1) {
MessageUtil.CreateAndShowMessageDialog("Fail", "Job Name is empty");
return;
}
int JobNum = (int)Int32.Parse(strJobName);
if (_OCT.SetProgram(JobNum) == 0) {
}
}
}
private void StartSequence(object obj)
{
if (_OCT.IsSimul) {
return;
}
if (_OCT != null) {
if (strSequenceName == null || strSequenceName.Length < 1) {
MessageUtil.CreateAndShowMessageDialog("Fail", "Sequence Name is empty");
return;
}
int SeqNum = (int)Int32.Parse(strSequenceName);
if (_OCT.SetProgram(SeqNum) == 0) {
}
}
}
private void GetSequenceRemoteMode(object obj)
{
if (_OCT.IsSimul) {
return;
}
strSequenceCMDResult = "";
int nRet = 0;
if (_OCT != null) {
nRet = _OCT.GetRemoteControl();
}
if (nRet == 0) {
strSequenceCMDResult = "OFF";
} else if (nRet == 1) {
strSequenceCMDResult = "Remote Job Mode";
} else if (nRet == 2) {
strSequenceCMDResult = "Remote Sequence Mode";
} else {
strSequenceCMDResult = "";
}
}
private void GetJobRemoteMode(object obj)
{
if (_OCT.IsSimul) {
return;
}
strJobCMDResult = "123123";
int nRet = 0;
if (_OCT != null) {
nRet = _OCT.GetRemoteControl();
}
if (nRet == 0) {
strJobCMDResult = "OFF";
} else if (nRet == 1) {
strJobCMDResult = "Remote Job Mode";
} else if (nRet == 2) {
strJobCMDResult = "Remote Sequence Mode";
} else {
strJobCMDResult = "";
}
}
private void GetJobResult(object obj)
{
strJob_KHD_Judge = "";
if (_OCT.IsSimul) {
return;
}
if (_OCT != null) {
strJob_KHD_Judge = _OCT.GetJobResult();
}
}
private void GetSequenceResult(object obj)
{
strSequence_KHD_Judge = "";
if (_OCT.IsSimul) {
return;
}
if (_OCT != null) {
strSequence_KHD_Judge = _OCT.GetJobResult();
}
}
private void GetJobAvg(object obj)
{
strJob_KHD_AVG = "";
if (_OCT.IsSimul) {
return;
}
if (_OCT != null) {
strJob_KHD_AVG = _OCT.GetKHD_AVG();
}
}
private void GetSequenceAvg(object obj)
{
strSequence_KHD_AVG = "";
if (_OCT.IsSimul) {
return;
}
if (_OCT != null) {
strSequence_KHD_AVG = _OCT.GetKHD_AVG();
}
}
private void GetJobMax(object obj)
{
strJob_KHD_MAX = "";
if (_OCT.IsSimul) {
return;
}
if (_OCT != null) {
strJob_KHD_MAX = _OCT.GetKHD_MAX();
}
}
private void GetSequenceMax(object obj)
{
strSequence_KHD_MAX = "";
if (_OCT.IsSimul) {
return;
}
if (_OCT != null) {
strSequence_KHD_MAX = _OCT.GetKHD_MAX();
}
}
private void GetJobMin(object obj)
{
strJob_KHD_MIN = "";
if (_OCT.IsSimul) {
return;
}
if (_OCT != null) {
strJob_KHD_MIN = _OCT.GetKHD_MIN();
}
}
private void GetSequenceMin(object obj)
{
strSequence_KHD_MIN = "";
if (_OCT.IsSimul) {
return;
}
if (_OCT != null) {
strSequence_KHD_MIN = _OCT.GetKHD_MIN();
}
}
private void GetJobLowSum(object obj)
{
strJob_KHD_LOWSUM = "";
if (_OCT.IsSimul) {
return;
}
if (_OCT != null) {
strJob_KHD_LOWSUM = _OCT.GetKHD_LowSum();
}
}
private void GetSequenceLowSum(object obj)
{
strSequence_KHD_LOWSUM = "";
if (_OCT.IsSimul) {
return;
}
if (_OCT != null) {
strSequence_KHD_LOWSUM = _OCT.GetKHD_LowSum();
}
}
private void GetJobHighSum(object obj)
{
strJob_KHD_HIGHSUM = "";
if (_OCT.IsSimul) {
return;
}
if (_OCT != null) {
strJob_KHD_HIGHSUM = _OCT.GetKHD_HighSum();
}
}
private void GetSequenceHighSum(object obj)
{
strSequence_KHD_HIGHSUM = "";
if (_OCT.IsSimul) {
return;
}
if (_OCT != null) {
strSequence_KHD_HIGHSUM = _OCT.GetKHD_HighSum();
}
}
private void OCTStateChange()
{
// 이 함수가 호출되어야 OCTState 변수를 바꾸고 나서 UI 에 적용된다.
bRadioInitializing = OCTState == "Initializing" ? true : false;
bRadioReady = OCTState == "Ready for Command" ? true : false;
bRadioBusy = OCTState == "Busy" ? true : false;
bRadioNoRespone = OCTState == "No Response" ? true : false;
bRadioAcquiring = OCTState == "Acquiring" ? true : false;
bRadioProcessing = OCTState == "Processing" ? true : false;
bRadioWaitingTrigger = OCTState == "Waiting for Trigger" ? true : false;
bRadioNotRemoteMode = OCTState == "Not in Remote Mode" ? true : false;
}
private void GetOCTState()
{
if (_OCT.IsSimul) {
OCTState = "No Response";
return;
}
if (_OCT != null) {
//var oct = _OCT._OCT as LDD700;
string strResult;
//if (oct.get_system_state(out strResult) != -1) {
if (_OCT.get_system_state(out strResult) != -1) {
OCTState = strResult;
} else {
OCTState = "No Response";
}
}
}
}
}