|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- using BPA.Helper;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Threading;
-
- namespace BPASmartClient.DosingSystem.ViewModel
- {
- public class HardwareStatusViewModel : NotifyBase
- {
- public HardwareStatusViewModel()
- {
-
-
- //TopDeviceCurrentStatuses = DeviceInquire.GetInstance.TopDeviceCurrentStatuses;
- //BottomDeviceCurrentStatuses = DeviceInquire.GetInstance.BottomDeviceCurrentStatuses;
- //2023/7/3调整
- TopDeviceCurrentStatuses = ConvertToObservableCollention(DeviceInquire.GetInstance.TopDeviceCurrentStatuses.OrderByDescending(p => p.DeviceNum).Reverse());
- BottomDeviceCurrentStatuses = ConvertToObservableCollention(DeviceInquire.GetInstance.BottomDeviceCurrentStatuses.OrderByDescending(p => p.DeviceNum).Reverse());
- UnifordColumNum();
- //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);
- // }
- // }
- //});
- TaskManage.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);
- }), "输送带料仓状态监控", true);
-
- 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);
- }
- }
- });
- }
- /// <summary>
- /// 数组集合转换
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="array"></param>
- /// <returns></returns>
- public ObservableCollection<T> ConvertToObservableCollention<T>(IEnumerable<T> array)
- {
- ObservableCollection<T> collec = new ObservableCollection<T>();
- foreach (var item in array)
- {
- collec.Add(item);
- }
- return collec;
- }
- 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();
- }
- }
- }
- }
- }
- /// <summary>
- /// 根据料仓数来进行uniform列划分
- /// </summary>
- private void UnifordColumNum()
- {
- StockNum = TopDeviceCurrentStatuses.Count >= BottomDeviceCurrentStatuses.Count ? TopDeviceCurrentStatuses.Count : BottomDeviceCurrentStatuses.Count;
- //switch ((ConveryType)System.Enum.Parse(typeof(ConveryType), Json<DevicePar>.Data.BaseParModel.ConveryType))
- //{
- // case ConveryType.直线型: StockNum = Json<DevicePar>.Data.BaseParModel.StockCount; break;
- // //case ConveryType.直线型:
- // // if (Json<DevicePar>.Data.BaseParModel.StockCount > 0 && Json<DevicePar>.Data.BaseParModel.StockCount % 2 == 0)
- // // {
- // // StockNum = Json<DevicePar>.Data.BaseParModel.StockCount / 2;
- // // }
- // // else
- // // {
- // // StockNum = 8;//默认值
- // // }
- // // break;
- //}
-
-
-
- }
- 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>
- /// Uniford根据料仓数量来划分列数量
- /// </summary>
- private int _stockNum;
- public int StockNum { get { return _stockNum; } set { _stockNum = value; OnPropertyChanged(); } }
- /// <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;
-
- }
-
-
- }
|