终端一体化运控平台
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 

95 рядки
3.2 KiB

  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.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. }