150 lines
6.0 KiB
C#
150 lines
6.0 KiB
C#
using Aurora;
|
|
using Aurora.View;
|
|
using AuroraIO;
|
|
using System;
|
|
using System.Windows.Input;
|
|
using System.Windows.Threading;
|
|
using static AuroraIO.Vendor.PAIX.PAIXIO;
|
|
|
|
namespace WeldingCommon.Views
|
|
{
|
|
public class UCInformationPanelViewModel : NotifyPropertyChangedBase
|
|
{
|
|
protected IODevice _IO;
|
|
|
|
public ICommand CMD_MaintKeyLock { get; set; }
|
|
public ICommand CMD_DoorRelease { get; set; }
|
|
|
|
private string _MaintKeyButton;
|
|
public string MaintKeyButton { get => _MaintKeyButton; set => SetProperty(ref _MaintKeyButton, value); }
|
|
|
|
private string _DoorReleaseButton;
|
|
public string DoorReleaseButton { get => _DoorReleaseButton; set => SetProperty(ref _DoorReleaseButton, value); }
|
|
|
|
private readonly DispatcherTimer _MonitorTimer;
|
|
|
|
public UCInformationPanelViewModel(IAuroraEnvironment aurora, string DeviceId)
|
|
{
|
|
CMD_MaintKeyLock = new DelegateCommand(PerformCmdMaintKeyLock);
|
|
CMD_DoorRelease = new DelegateCommand(PerformCmdDoorRelease);
|
|
|
|
_IO = aurora.DeviceManager[DeviceId] as IODevice;
|
|
|
|
_MonitorTimer = new DispatcherTimer();
|
|
_MonitorTimer.Tick += OnMonitoring;
|
|
_MonitorTimer.Interval = TimeSpan.FromMilliseconds(500);
|
|
|
|
_MonitorTimer.Start();
|
|
}
|
|
|
|
private void OnMonitoring(object sender, EventArgs e)
|
|
{
|
|
if (!_IO.IsActivated) {
|
|
return;
|
|
}
|
|
try {
|
|
bool bMaint = _IO._iOUnit.ReadDoBit((Convert.ToInt32(ePDOAddress.ModeKeySolOn)));
|
|
if (bMaint) {
|
|
MaintKeyButton = "MaintKey Release";
|
|
} else {
|
|
MaintKeyButton = "MaintKey Lock";
|
|
}
|
|
|
|
bool bDoor = _IO._iOUnit.ReadDoBit((Convert.ToInt32(ePDOAddress.SafetyDoorRelease)));
|
|
if (bDoor) {
|
|
DoorReleaseButton = "Door Lock";
|
|
} else {
|
|
DoorReleaseButton = "Door Release";
|
|
}
|
|
|
|
bool DoorOpen = _IO._iOUnit.ReadDiBit((Convert.ToInt32(ePDIAddress.DoorLockOpen1)))
|
|
|| _IO._iOUnit.ReadDiBit((Convert.ToInt32(ePDIAddress.DoorLockOpen2)))
|
|
|| _IO._iOUnit.ReadDiBit((Convert.ToInt32(ePDIAddress.DoorLockOpen3)))
|
|
|| _IO._iOUnit.ReadDiBit((Convert.ToInt32(ePDIAddress.DoorLockOpen4)));
|
|
|
|
if (DoorOpen) {
|
|
_IO._iOUnit.WriteDoBit((Convert.ToInt32(ePDOAddress.ModeKeySolOn)), false);
|
|
}
|
|
|
|
bool bAuto = _IO._iOUnit.ReadDiBit((Convert.ToInt32(ePDIAddress.ModeKeyAuto)));
|
|
if (bAuto) {
|
|
_IO._iOUnit.WriteDoBit((Convert.ToInt32(ePDOAddress.SafetyDoorRelease)), true);
|
|
}
|
|
} catch (Exception ex) {
|
|
//MessageBox.Show(ex.Message);
|
|
}
|
|
}
|
|
|
|
public void PerformCmdMaintKeyLock(object obj)
|
|
{
|
|
bool bResult = false;
|
|
|
|
bResult = _IO._iOUnit.ReadDoBit((Convert.ToInt32(ePDOAddress.ModeKeySolOn)));
|
|
if (bResult) { //해제 -> 잠금
|
|
bool DoorOpen = _IO._iOUnit.ReadDiBit((Convert.ToInt32(ePDIAddress.DoorLockOpen1)))
|
|
|| _IO._iOUnit.ReadDiBit((Convert.ToInt32(ePDIAddress.DoorLockOpen2)))
|
|
|| _IO._iOUnit.ReadDiBit((Convert.ToInt32(ePDIAddress.DoorLockOpen3)))
|
|
|| _IO._iOUnit.ReadDiBit((Convert.ToInt32(ePDIAddress.DoorLockOpen4)));
|
|
|
|
if (DoorOpen) {
|
|
return;
|
|
} else {
|
|
_IO._iOUnit.WriteDoBit((Convert.ToInt32(ePDOAddress.ModeKeySolOn)), false);
|
|
//MaintKeyButton = "MaintKey Lock";
|
|
}
|
|
} else { // 잠금 - > 해제
|
|
bool DoorOpen = _IO._iOUnit.ReadDiBit((Convert.ToInt32(ePDIAddress.DoorLockOpen1)))
|
|
|| _IO._iOUnit.ReadDiBit((Convert.ToInt32(ePDIAddress.DoorLockOpen2)))
|
|
|| _IO._iOUnit.ReadDiBit((Convert.ToInt32(ePDIAddress.DoorLockOpen3)))
|
|
|| _IO._iOUnit.ReadDiBit((Convert.ToInt32(ePDIAddress.DoorLockOpen4)));
|
|
|
|
if (DoorOpen) {
|
|
return;
|
|
} else {
|
|
_IO._iOUnit.WriteDoBit((Convert.ToInt32(ePDOAddress.ModeKeySolOn)), true);
|
|
//MaintKeyButton = "MaintKey Release";
|
|
}
|
|
}
|
|
}
|
|
|
|
public void PerformCmdDoorRelease(object obj)
|
|
{
|
|
bool bResult = false;
|
|
bool bIsMaint = false;
|
|
bool bIsAuto = false;
|
|
bResult = _IO._iOUnit.ReadDoBit((Convert.ToInt32(ePDOAddress.ModeKeySolOn)));
|
|
|
|
//if (bResult)
|
|
//{
|
|
bIsAuto = _IO._iOUnit.ReadDiBit((Convert.ToInt32(ePDIAddress.ModeKeyAuto)));
|
|
bIsMaint = _IO._iOUnit.ReadDiBit((Convert.ToInt32(ePDIAddress.ModeKeyMaint)));
|
|
if (bIsAuto) {
|
|
return;
|
|
} else if (bIsMaint) {
|
|
bool DoorOpen = _IO._iOUnit.ReadDiBit((Convert.ToInt32(ePDIAddress.DoorLockOpen1)))
|
|
|| _IO._iOUnit.ReadDiBit((Convert.ToInt32(ePDIAddress.DoorLockOpen2)))
|
|
|| _IO._iOUnit.ReadDiBit((Convert.ToInt32(ePDIAddress.DoorLockOpen3)))
|
|
|| _IO._iOUnit.ReadDiBit((Convert.ToInt32(ePDIAddress.DoorLockOpen4)));
|
|
|
|
if (DoorOpen) {
|
|
return;
|
|
} else {
|
|
bResult = _IO._iOUnit.ReadDoBit((Convert.ToInt32(ePDOAddress.SafetyDoorRelease)));
|
|
if (bResult) {
|
|
_IO._iOUnit.WriteDoBit((Convert.ToInt32(ePDOAddress.SafetyDoorRelease)), false);
|
|
//DoorReleaseButton = "Door Release";
|
|
} else {
|
|
_IO._iOUnit.WriteDoBit((Convert.ToInt32(ePDOAddress.SafetyDoorRelease)), true);
|
|
//DoorReleaseButton = "Door Lock";
|
|
}
|
|
}
|
|
|
|
} else {
|
|
return;
|
|
}
|
|
//}
|
|
|
|
}
|
|
}
|
|
}
|