201 lines
6.8 KiB
C#
201 lines
6.8 KiB
C#
using Aurora;
|
|
using Aurora.Api;
|
|
using System.Reactive.Linq;
|
|
using Aurora.View;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Windows.Input;
|
|
using AuroraACS;
|
|
using System.Collections.ObjectModel;
|
|
using System.ComponentModel;
|
|
using System.Windows.Data;
|
|
using System.Windows;
|
|
|
|
namespace FlexAttach.Devices
|
|
{
|
|
public class FlexAcsIOViewModel : NotifyPropertyChangedBase
|
|
{
|
|
FlexAcsDIO _acsIO;
|
|
FlexAcsDIO.Config _config;
|
|
IAuroraEnvironment _auroraEnv;
|
|
|
|
public FlexAcsIOViewModel(Device dev, IAuroraEnvironment env)
|
|
{
|
|
_acsIO = (FlexAcsDIO)dev;
|
|
_config = (FlexAcsDIO.Config)env.DeviceManager.GetDeviceConfig(dev.DeviceId);
|
|
_auroraEnv = env;
|
|
|
|
BitInputs = DIN.GetAllInfo();
|
|
BitOutputs = DOUT.GetAllInfo();
|
|
BitInputView = new CollectionViewSource() { Source = BitInputs }.View;
|
|
BitOutputView = new CollectionViewSource() { Source = BitOutputs }.View;
|
|
|
|
//_dispenser.EventActivated += _dispenser_EventActivated;
|
|
var act = env.EventObservable.AsObservable(AuroraSysEvent.SYS_DEVICE_ACTIVATED)
|
|
.Subscribe(msg => Activated(true, _acsIO.IsActivated));
|
|
|
|
//IOMonitor.GetInstance().IO_Observable.Where(x => x.IsChanged.Length != 0).SubscribeOnDispatcher().Subscribe(UpdateValues);
|
|
//IOMonitor.GetInstance().IOOut_Observable.Where(x => x.IsOutChanged.Length != 0).SubscribeOnDispatcher().Subscribe(UpdateOutValues);
|
|
}
|
|
|
|
private DelegateCommand cMD_VisibleChanged;
|
|
|
|
public ICommand CMD_VisibleChanged {
|
|
get {
|
|
if (cMD_VisibleChanged == null) {
|
|
cMD_VisibleChanged = new DelegateCommand(PerformCMD_VisibleChanged);
|
|
}
|
|
|
|
return cMD_VisibleChanged;
|
|
}
|
|
}
|
|
|
|
private void PerformCMD_VisibleChanged(object isVisible)
|
|
{
|
|
if ((bool)isVisible) {
|
|
UpdateAllValues();
|
|
} else {
|
|
|
|
}
|
|
}
|
|
|
|
//private DelegateCommand cMD_ViewLoaded;
|
|
//private DelegateCommand cMD_ViewUnloaded;
|
|
//public ICommand CMD_ViewLoaded { get { if (cMD_ViewLoaded == null) { cMD_ViewLoaded = new DelegateCommand(PerformCMD_ViewLoaded); } return cMD_ViewLoaded; } }
|
|
//public ICommand CMD_ViewUnloaded { get { if (cMD_ViewUnloaded == null) { cMD_ViewUnloaded = new DelegateCommand(PerformCMD_ViewUnloaded); } return cMD_ViewUnloaded; } }
|
|
|
|
//private void PerformCMD_ViewLoaded(object commandParameter)
|
|
//{
|
|
// UpdateAllValues();
|
|
//}
|
|
|
|
//private void PerformCMD_ViewUnloaded(object commandParameter)
|
|
//{
|
|
//}
|
|
|
|
private void UpdateValues(IOItem ioitem)
|
|
{
|
|
//int idx = 0;
|
|
//foreach (AddrInfo info in BitInputs) {
|
|
// idx = (info.Node << 4) + info.Bit;
|
|
// if (ioitem.IsChanged[idx])
|
|
// info.Value = ioitem.ChangedVaslues[idx];
|
|
//}
|
|
}
|
|
|
|
private void UpdateOutValues(IOOutItem ioitem)
|
|
{
|
|
//int idx = 0;
|
|
//foreach (AddrInfo info in BitOutputs) {
|
|
// idx = (info.Node << 4) + info.Bit;
|
|
// if (ioitem.IsOutChanged[idx])
|
|
// info.Value = ioitem.ChangedOutVaslues[idx];
|
|
//}
|
|
}
|
|
|
|
private void Activated(bool act, bool isOk)
|
|
{
|
|
if (act == true) {
|
|
if (isOk == false) { // fail
|
|
return;
|
|
}
|
|
UpdateAllValues();
|
|
} else {
|
|
//_timer?.Dispose();
|
|
//_timer = null;
|
|
}
|
|
}
|
|
|
|
private void UpdateAllValues()
|
|
{
|
|
foreach (AddrInfo item in BitInputs) {
|
|
item.Value = _acsIO.GetInput(item.Addr);
|
|
}
|
|
foreach (AddrInfo item in BitOutputs) {
|
|
item.Value = _acsIO.GetOutput(item.Addr);
|
|
}
|
|
}
|
|
|
|
private List<AddrInfo> bitInputs = new List<AddrInfo>();
|
|
|
|
public List<AddrInfo> BitInputs { get => bitInputs; set => SetProperty(ref bitInputs, value); }
|
|
|
|
private List<AddrInfo> bitOutputs = new List<AddrInfo>();
|
|
|
|
public List<AddrInfo> BitOutputs { get => bitOutputs; set => SetProperty(ref bitOutputs, value); }
|
|
|
|
public ICollectionView BitInputView { get; private set; }
|
|
public ICollectionView BitOutputView { get; private set; }
|
|
|
|
private AddrInfo selOut;
|
|
public AddrInfo SelOut { get => selOut; set => SetProperty(ref selOut, value); }
|
|
|
|
private AddrInfo selin;
|
|
public AddrInfo SelIn { get => selin; set => SetProperty(ref selin, value); }
|
|
|
|
private int addr;
|
|
public int Addr { get => addr; set => SetProperty(ref addr, value); }
|
|
private int val;
|
|
public int Value { get => val; set => SetProperty(ref val, value); }
|
|
|
|
private DelegateCommand cmdGetValue;
|
|
private DelegateCommand cmdSetValue;
|
|
public ICommand CmdGetValue {
|
|
get {
|
|
if (cmdGetValue == null) {
|
|
cmdGetValue = new DelegateCommand(PerformCmdGetValue);
|
|
}
|
|
|
|
return cmdGetValue;
|
|
}
|
|
}
|
|
public ICommand CmdSetValue {
|
|
get {
|
|
if (cmdSetValue == null) {
|
|
cmdSetValue = new DelegateCommand(PerformCmdSetValue);
|
|
}
|
|
|
|
return cmdSetValue;
|
|
}
|
|
}
|
|
private void PerformCmdGetValue(object commandParameter)
|
|
{
|
|
Value = _acsIO.GetOutput(Addr);
|
|
}
|
|
|
|
private void PerformCmdSetValue(object commandParameter)
|
|
{
|
|
if(!_acsIO.SetOutput(SelOut.Addr, SelOut.Value)) {
|
|
SelOut.Value ^= 1; // 실패 시 원복
|
|
}
|
|
|
|
}
|
|
|
|
private string inSearch;
|
|
public string InSearch { get => inSearch; set { SetProperty(ref inSearch, value); SetInFilter(value); } }
|
|
|
|
private void SetInFilter(string value)
|
|
{
|
|
string temp = value.ToUpper();
|
|
BitInputView.Filter = new Predicate<object>(item => ((AddrInfo)item).Name.ToUpper().Contains(temp));
|
|
}
|
|
|
|
private string outSearch;
|
|
public string OutSearch { get => outSearch; set { SetProperty(ref outSearch, value); SetOutFilter(value); } }
|
|
|
|
private void SetOutFilter(string value)
|
|
{
|
|
string temp = value.ToUpper();
|
|
BitOutputView.Filter = new Predicate<object>(item => ((AddrInfo)item).Name.ToUpper().Contains(temp));
|
|
}
|
|
|
|
public void SelRowDataChange()
|
|
{
|
|
SelOut.Value ^= 1;
|
|
if (!_acsIO.SetOutput(SelOut.Addr, SelOut.Value)) {
|
|
SelOut.Value ^= 1; // 실패 시 원복
|
|
}
|
|
}
|
|
}
|
|
}
|