|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using BPA.Helper;
- using System.Collections.Concurrent;
- using System.Collections.ObjectModel;
- using System.Windows;
- using System.Threading;
-
- namespace BPASmartClient.DosingSystem.ViewModel
- {
- public class HardwareStatusViewModel : NotifyBase
- {
- public HardwareStatusViewModel()
- {
- TopDeviceCurrentStatuses = DeviceInquire.GetInstance.TopDeviceCurrentStatuses;
- BottomDeviceCurrentStatuses = DeviceInquire.GetInstance.BottomDeviceCurrentStatuses;
-
- //for (int i = 0; i < Json<DevicePar>.Data.BaseParModel.ConveyerBeltCount; i++)
- //{
- // ConveyerBeltModels.Add(new ConveyerBeltModel() { Name = $"输送带{i}", Num = i++ });
- //}
-
- //ConveyerBeltControlCommand = new BPARelayCommand<object>(o =>
- //{
- // if (o != null && o is int tempCount)
- // {
- // string add = SiemensDevice.GetInstance.GetSiemensBitSingleAdd("DB5.DBX", tempCount, 6);
- // int index = ConveyerBeltModels.ToList().FindIndex(p => p.Num == tempCount);
- // if (index >= 0 && index < ConveyerBeltModels.Count)
- // {
- // SiemensDevice.GetInstance.MySiemens.Write(add, !ConveyerBeltModels.ElementAt(index).Control);
- // }
- // }
- //});
- ThreadManage.GetInstance().StartLong(new Action(() =>
- {
- for (int i = 0; i < Json<DevicePar>.Data.OutletInfoModels.Count; i++)
- {
- int count = Json<DevicePar>.Data.OutletInfoModels.ElementAt(i).SiloInfos.Count;
- if (count >= 1)
- {
- for (int m = 0; m < count; m++)
- {
- var deviceName = Json<DevicePar>.Data.OutletInfoModels.ElementAt(i).SiloInfos.ElementAt(m);
- int topIndex = TopDeviceCurrentStatuses.ToList().FindIndex(p => p.DeviceName == deviceName);
- int bottomIndex = BottomDeviceCurrentStatuses.ToList().FindIndex(p => p.DeviceName == deviceName);
- if (topIndex >= 0 && topIndex < TopDeviceCurrentStatuses.Count)
- TopDeviceCurrentStatuses.ElementAt(i).BucketFlagbit = GlobalDevice.PlcData.StationDetection[i];
- if (bottomIndex >= 0 && bottomIndex < BottomDeviceCurrentStatuses.Count)
- BottomDeviceCurrentStatuses.ElementAt(i).BucketFlagbit = GlobalDevice.PlcData.StationDetection[i];
- }
- }
- }
- StatusUpdate(TopDeviceCurrentStatuses);
- StatusUpdate(BottomDeviceCurrentStatuses);
- OnDetection = GlobalDevice.PlcData.OnDetection;
- UnderDetection = GlobalDevice.PlcData.UnderDetection;
- ConveyerBeltStatus = GlobalDevice.MotorControlFeedback > 0;
- Thread.Sleep(100);
- }), "输送带料仓状态监控");
-
- RecipeControlCommand = new BPARelayCommand<object>((o) =>
- {
- if (o != null && o is DeviceCurrentStatus currentStatus)
- {
- var res = DeviceInquire.GetInstance.devices.FirstOrDefault(p => p.DeviceName == currentStatus.DeviceName);
- if (res != null)
- {
- DeviceInquire.GetInstance.GetDevice(res.IpAddress).Start(currentStatus.SetWeight);
- }
- }
- });
- }
-
- private void StatusUpdate(ObservableCollection<DeviceCurrentStatus> devices)
- {
- if (devices == null) return;
- for (int i = 0; i < devices.Count; i++)
- {
- if (devices.ElementAt(i).BaitingControl)
- {
- var res = DeviceInquire.GetInstance.devices.FirstOrDefault(p => p.DeviceName == devices.ElementAt(i).DeviceName);
- if (res != null)
- {
- var runStatus = DeviceInquire.GetInstance.GetDevice(res.IpAddress).deviceStatus.RunStatus;
- if (runStatus == 3)
- {
- if (TopDeviceCurrentStatuses.FirstOrDefault(p => p.DeviceName == devices.ElementAt(i).DeviceName) != null)
- {
- TopDeviceCurrentStatuses.ElementAt(i).BaitingControl = false;
- }
- else if (BottomDeviceCurrentStatuses.FirstOrDefault(p => p.DeviceName == devices.ElementAt(i).DeviceName) != null)
- {
- BottomDeviceCurrentStatuses.ElementAt(i).BaitingControl = false;
- }
- DeviceInquire.GetInstance.GetDevice(res.IpAddress).StatusReset();
- }
- }
- }
- }
- }
-
- public ObservableCollection<DeviceCurrentStatus> TopDeviceCurrentStatuses { get; set; }
-
- public ObservableCollection<DeviceCurrentStatus> BottomDeviceCurrentStatuses { get; set; }
-
- public ObservableCollection<ConveyerBeltModel> ConveyerBeltModels { get; set; } = new ObservableCollection<ConveyerBeltModel>();
-
- public BPARelayCommand<object> ConveyerBeltControlCommand { get; set; }
-
- public BPARelayCommand<object> RecipeControlCommand { get; set; }
-
- /// <summary>
- /// 输送带状态
- /// </summary>
- public bool ConveyerBeltStatus { get { return _mConveyerBeltStatus; } set { _mConveyerBeltStatus = value; OnPropertyChanged(); } }
- private bool _mConveyerBeltStatus;
-
- /// <summary>
- /// 上桶工位检测
- /// </summary>
- public bool OnDetection { get { return _mOnDetection; } set { _mOnDetection = value; OnPropertyChanged(); } }
- private bool _mOnDetection;
-
- /// <summary>
- /// 下桶工位检测
- /// </summary>
- public bool UnderDetection { get { return _mUnderDetection; } set { _mUnderDetection = value; OnPropertyChanged(); } }
- private bool _mUnderDetection;
-
- }
-
-
- }
|