终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

87 lines
3.2 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Microsoft.Toolkit.Mvvm.ComponentModel;
  7. using System.Collections.Concurrent;
  8. using System.Collections.ObjectModel;
  9. using System.Windows;
  10. using BPASmartClient.Helper;
  11. using Microsoft.Toolkit.Mvvm.Input;
  12. using BPASmartClient.JXJFoodBigStation.Model;
  13. namespace BPASmartClient.JXJFoodBigStation.ViewModel
  14. {
  15. public class HardwareStatusViewModel : ObservableObject
  16. {
  17. public HardwareStatusViewModel()
  18. {
  19. for (int i = 0; i <8; i++)
  20. {
  21. TopDeviceCurrentStatuses.Add(new DeviceCurrentStatus()
  22. {
  23. DeviceName = i.ToString(),
  24. DeviceNum=i,
  25. RunStatus = false,
  26. Weight = new Random().Next(0, 100)
  27. });
  28. }
  29. for (int i = 8; i < 16; i++)
  30. {
  31. BottomDeviceCurrentStatuses.Add(new DeviceCurrentStatus()
  32. {
  33. DeviceName = i.ToString(),
  34. DeviceNum = i,
  35. RunStatus = false,
  36. Weight = new Random().Next(0, 100)
  37. });
  38. }
  39. StartCommand = new RelayCommand<string>((deviceName) => {
  40. //PLC控制
  41. //动画
  42. if (deviceName != null)
  43. {
  44. var top= TopDeviceCurrentStatuses.FirstOrDefault(p => p.DeviceName == deviceName);
  45. if (top != null)
  46. {
  47. ActionManage.GetInstance.Send("StartTopDevice", deviceName);
  48. }
  49. var bottom = BottomDeviceCurrentStatuses.FirstOrDefault(p => p.DeviceName == deviceName);
  50. if (bottom != null)
  51. {
  52. ActionManage.GetInstance.Send("StartBottomDevice", deviceName);
  53. }
  54. }
  55. });
  56. StopCommand = new RelayCommand<string>((deviceName) => {
  57. //PLC控制
  58. //动画
  59. if (deviceName != null)
  60. {
  61. var top = TopDeviceCurrentStatuses.FirstOrDefault(p => p.DeviceName == deviceName);
  62. if (top != null)
  63. {
  64. ActionManage.GetInstance.Send("StopTopDevice", deviceName);
  65. }
  66. var bottom = BottomDeviceCurrentStatuses.FirstOrDefault(p => p.DeviceName == deviceName);
  67. if (bottom != null)
  68. {
  69. ActionManage.GetInstance.Send("StopBottomDevice", deviceName);
  70. }
  71. }
  72. });
  73. }
  74. public ObservableCollection<DeviceCurrentStatus> TopDeviceCurrentStatuses { get; set; } = new ObservableCollection<DeviceCurrentStatus>();
  75. public ObservableCollection<DeviceCurrentStatus> BottomDeviceCurrentStatuses { get; set; } = new ObservableCollection<DeviceCurrentStatus>();
  76. public RelayCommand<string> StartCommand { get; set; }
  77. public RelayCommand<string> StopCommand { get; set; }
  78. }
  79. }