终端一体化运控平台
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

MonitorViewModel.cs 3.2 KiB

há 2 anos
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using BPASmartClient.Business;
  2. using BPASmartClient.Helper;
  3. using BPASmartClient.Model.乐白机器人;
  4. using Microsoft.Toolkit.Mvvm.ComponentModel;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Globalization;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading;
  11. using System.Threading.Tasks;
  12. using System.Windows.Data;
  13. using System.Windows.Media;
  14. namespace BPASmartClient.MorkT_HQ.ViewModel
  15. {
  16. public class MonitorViewModel: ObservableObject
  17. {
  18. #region 传感器
  19. /// <summary>
  20. /// 机器人夹爪传感器
  21. /// </summary>
  22. public bool RobotSenser { get { return _robotSenser; } set { _robotSenser = value; OnPropertyChanged(); } }
  23. private bool _robotSenser;
  24. /// <summary>
  25. /// 冰淇淋出口传感器
  26. /// </summary>
  27. public bool IceCreamSenser { get { return _iceCreamSenser; } set { _iceCreamSenser = value; OnPropertyChanged(); } }
  28. private bool _iceCreamSenser;
  29. /// <summary>
  30. /// 取餐口检测传感器
  31. /// </summary>
  32. public bool TakeMealSenser { get { return _takeMealSenser; } set { _takeMealSenser = value; OnPropertyChanged(); } }
  33. private bool _takeMealSenser;
  34. #endregion
  35. /// <summary>
  36. /// 设备ID
  37. /// </summary>
  38. int DeviceId;
  39. public MonitorViewModel()
  40. {
  41. Plugin.GetInstance()?.GetPlugin<DeviceMgr>()?.GetDevices().ForEach(device =>
  42. {
  43. if (device.Name == "MorkT") DeviceId = device.DeviceId;
  44. });
  45. ThreadManage.GetInstance().StartLong(new Action(() =>
  46. {
  47. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_GetTCPInputEvent() { DeviceId = DeviceId, Pin = 1 },(res)=>
  48. {
  49. if(res != null&& res.Length>0&& res[0] is bool b)
  50. {
  51. RobotSenser = b;
  52. }
  53. });
  54. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_GetInputEvent() { DeviceId = DeviceId, Pin = 0 }, (res) =>
  55. {
  56. if (res != null && res.Length > 0 && res[0] is bool b)
  57. {
  58. TakeMealSenser = b;
  59. }
  60. });
  61. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_GetTCPInputEvent() { DeviceId = DeviceId, Pin = 3 }, (res) =>
  62. {
  63. if (res != null && res.Length > 0 && res[0] is bool b)
  64. {
  65. IceCreamSenser = b;
  66. }
  67. });
  68. Thread.Sleep(500);
  69. }), "MorkT-传感器监视");
  70. }
  71. }
  72. public class BoolToColorConvert : IValueConverter
  73. {
  74. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  75. {
  76. return (bool) value? new SolidColorBrush(Color.FromRgb(144, 238, 144)) : new SolidColorBrush(Color.FromRgb(178, 34, 34));
  77. }
  78. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  79. {
  80. throw new NotImplementedException();
  81. }
  82. }
  83. }