终端一体化运控平台
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 

335 wiersze
18 KiB

  1. using BPASmartClient.Business;
  2. using BPASmartClient.Device;
  3. using BPASmartClient.Helper;
  4. using BPASmartClient.MorkF.Model;
  5. using Microsoft.Toolkit.Mvvm.ComponentModel;
  6. using Microsoft.Toolkit.Mvvm.Input;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Collections.ObjectModel;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. namespace BPASmartClient.MorkF.ViewModel
  14. {
  15. internal class DebugViewModel : ObservableObject
  16. {
  17. public bool SimOrderEnable { get { return General_Config.SimOrderAllow; } set { General_Config.SimOrderAllow = value; OnPropertyChanged(); } }
  18. /// <summary>
  19. /// 设备数据
  20. /// </summary>
  21. public ObservableCollection<VariableMonitor> variableMonitors { get; set; }
  22. /// <summary>
  23. /// 设备ID
  24. /// </summary>
  25. public int DeviceId { get; set; }
  26. #region 设备控制
  27. public int FoodMenuID { get { return _foodMenuID; } set { _foodMenuID = value; OnPropertyChanged(); } }
  28. private int _foodMenuID;
  29. public RelayCommand PlcInite { get; set; }
  30. public RelayCommand FoodPlcInite { get; set; }
  31. public RelayCommand Plc1Reset { get; set; }
  32. public RelayCommand StartOrder { get; set; }
  33. public RelayCommand StopLocalOrder { get; set; }
  34. public RelayCommand ModeChange { get; set; }
  35. #endregion
  36. #region 菜品控制
  37. public string RealX { get { return _realX; } set { _realX = value; OnPropertyChanged(); } }
  38. private string _realX;
  39. public string RealY { get { return _realY; } set { _realY = value; OnPropertyChanged(); } }
  40. private string _realY;
  41. public int SettingX { get { return _settingX; } set { _settingX = value; OnPropertyChanged(); } }
  42. private int _settingX = 0;
  43. public int SettingY { get { return _settingY; } set { _settingY = value; OnPropertyChanged(); } }
  44. private int _settingY = 0;
  45. public int SettingNowX { get { return _settingNowX; } set { _settingNowX = value; OnPropertyChanged(); } }
  46. private int _settingNowX = 0;
  47. public int SettingNowY { get { return _settingNowY; } set { _settingNowY = value; OnPropertyChanged(); } }
  48. private int _settingNowY = 0;
  49. public int MoveSpeed { get { return _moveSpeed; } set { _moveSpeed = value; OnPropertyChanged(); } }
  50. private int _moveSpeed;
  51. public string SensingDistance_1 { get { return _sensingDistance_1; } set { _sensingDistance_1 = value; OnPropertyChanged(); } }
  52. private string _sensingDistance_1 ;
  53. public string SensingDistance_2 { get { return _sensingDistance_2; } set { _sensingDistance_2 = value; OnPropertyChanged(); } }
  54. private string _sensingDistance_2 ;
  55. public string SensingDistance_3 { get { return _sensingDistance_3; } set { _sensingDistance_3 = value; OnPropertyChanged(); } }
  56. private string _sensingDistance_3;
  57. public bool PawPositon1 { get { return _pawPositon1; } set { _pawPositon1 = value; OnPropertyChanged(); } }
  58. private bool _pawPositon1;
  59. public bool PawPositon2 { get { return _pawPositon2; } set { _pawPositon2 = value; OnPropertyChanged(); } }
  60. private bool _pawPositon2;
  61. public bool PawPositon3 { get { return _pawPositon3; } set { _pawPositon3 = value; OnPropertyChanged(); } }
  62. private bool _pawPositon3;
  63. public bool ArmRunUp { get { return _armRunUp; } set { _armRunUp = value; OnPropertyChanged(); } }
  64. private bool _armRunUp;
  65. public bool ArmRunDown { get { return _armRunDown; } set { _armRunDown = value; OnPropertyChanged(); } }
  66. private bool _armRunDown;
  67. public bool ArmRunLeft { get { return _armRunLeft; } set { _armRunLeft = value; OnPropertyChanged(); } }
  68. private bool _armRunLeft;
  69. public bool ArmRunRight { get { return _armRunRight; } set { _armRunRight = value; OnPropertyChanged(); } }
  70. private bool _armRunRight;
  71. public bool ArmRunEnable { get { return _ArmRunEnable; } set { _ArmRunEnable = value; OnPropertyChanged(); } }
  72. private bool _ArmRunEnable = true;
  73. public string ArmButtonName { get { return _ArmButtonName; } set { _ArmButtonName = value; OnPropertyChanged(); } }
  74. private string _ArmButtonName = "启动";
  75. public string ModeButten { get { return _ModeButten; } set { _ModeButten = value; OnPropertyChanged(); } }
  76. private string _ModeButten = "联网模式";
  77. public RelayCommand SetNowPosition { get; set; }//设置机械臂当前坐标
  78. public RelayCommand FoodLibInit { get; set; }//初始化
  79. public RelayCommand SurplusCheck { get; set; }//初始化
  80. public RelayCommand StartElectromagnetism { get; set; }//电磁阀启动
  81. public RelayCommand StopElectromagnetism { get; set; }
  82. public RelayCommand SetSpeed { get; set; }//速度设定
  83. public RelayCommand GetDistance_1 { get; set; }//感应测距1
  84. public RelayCommand GetDistance_2 { get; set; }//感应测距2
  85. public RelayCommand GetDistance_3 { get; set; }//感应测距3
  86. public RelayCommand PawTurnFront { get; set; }//夹爪正转
  87. public RelayCommand PawTurnBack { get; set; }//夹爪反转
  88. public RelayCommand SetArmPosition { get; set; }//机器臂位置设定
  89. public RelayCommand ArmRun { get; set; }//机械臂运动
  90. public RelayCommand PawToPoint1 { get; set; }//感应测距1
  91. public RelayCommand PawToPoint2 { get; set; }//感应测距2
  92. public RelayCommand PawToPoint3 { get; set; }//感应测距3
  93. #endregion
  94. #region 配料仓控制
  95. public List<string> PassageWays { get; set; } = new List<string>()
  96. {
  97. "通道1",
  98. "通道2",
  99. "通道3",
  100. "通道4",
  101. "通道5",
  102. "通道6",
  103. "通道7",
  104. "通道8",
  105. "通道9",
  106. "通道10",
  107. "通道11",
  108. "通道12",
  109. "通道13",
  110. "通道14",
  111. };
  112. public int PassagePosition { get { return _passagePosition; } set { _passagePosition = value; OnPropertyChanged(); } }
  113. private int _passagePosition;
  114. public int Weight { get { return _weight; } set { _weight = value; OnPropertyChanged(); } }
  115. private int _weight;
  116. public RelayCommand OutMaterials { get; set; }
  117. #endregion
  118. #region 炒锅1
  119. public RelayCommand Pot1SimOrder { get; set; }
  120. public RelayCommand AddOil { get; set; }
  121. public RelayCommand StartFire { get; set; }
  122. public RelayCommand StopFire { get; set; }
  123. public RelayCommand StartStir { get; set; }
  124. public RelayCommand StopStir { get; set; }
  125. public RelayCommand MagnetOn { get; set; }
  126. public RelayCommand MagnetOff { get; set; }
  127. public RelayCommand OutFood { get; set; }
  128. public RelayCommand StirArmGoOrigin { get; set; }
  129. public RelayCommand StirArmGoWork { get; set; }
  130. public RelayCommand HBOTGoWork { get; set; }
  131. public RelayCommand OutMeal { get; set; }
  132. public RelayCommand SetFire { get; set; }
  133. public RelayCommand SetFry { get; set; }
  134. public RelayCommand SetStir { get; set; }
  135. public List<int> lstFire { get; set; } = new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
  136. public List<int> lstFry { get; set; } = new List<int>() { 1, 2 };
  137. public List<int> lstStir { get; set; } = new List<int>() { 1, 2, 3 };
  138. public int FireGear { get { return _fireGear; } set { _fireGear = value; OnPropertyChanged(); } }
  139. private int _fireGear;
  140. public int FryGear { get { return _fryeGear; } set { _fryeGear = value; OnPropertyChanged(); } }
  141. private int _fryeGear;
  142. public int StirGear { get { return _stirGear; } set { _stirGear = value; OnPropertyChanged(); } }
  143. private int _stirGear;
  144. #region 模拟
  145. public int OilTime { get { return _oilTime; } set { _oilTime = value; OnPropertyChanged(); } }
  146. private int _oilTime = 10;
  147. public int OilFirGear { get { return _oilFirGear; } set { _oilFirGear = value; OnPropertyChanged(); } }
  148. private int _oilFirGear = 3;
  149. public int OilStrGear { get { return _oilStrGear; } set { _oilStrGear = value; OnPropertyChanged(); } }
  150. private int _oilStrGear = 1;
  151. public int Food1Time { get { return _food1Time; } set { _food1Time = value; OnPropertyChanged(); } }
  152. private int _food1Time = 30;
  153. public int Food1FirGear { get { return _food1FirGear; } set { _food1FirGear = value; OnPropertyChanged(); } }
  154. private int _food1FirGear = 6;
  155. public int Food1StrGear { get { return _food1StrGear; } set { _food1StrGear = value; OnPropertyChanged(); } }
  156. private int _food1StrGear = 2;
  157. public int Food2Time { get { return _food2Time; } set { _food2Time = value; OnPropertyChanged(); } }
  158. private int _food2Time = 30;
  159. public int Food2FirGear { get { return _food2FirGear; } set { _food2FirGear = value; OnPropertyChanged(); } }
  160. private int _food2FirGear = 6;
  161. public int Food2StrGear { get { return _food2StrGear; } set { _food2StrGear = value; OnPropertyChanged(); } }
  162. private int _food2StrGear = 2;
  163. #endregion
  164. #endregion
  165. #region 炒锅2
  166. public RelayCommand SecAddOil { get; set; }
  167. public RelayCommand SecTempTurnOff { get; set; }
  168. public RelayCommand SecOneBlock { get; set; }
  169. public RelayCommand SecTwoBlock { get; set; }
  170. public RelayCommand SecThreeBlock { get; set; }
  171. public RelayCommand SecOverTurnOff { get; set; }
  172. public RelayCommand SecOverOneBlock { get; set; }
  173. public RelayCommand SecOverTwoBlock { get; set; }
  174. public RelayCommand SecOverThreeBlock { get; set; }
  175. public RelayCommand SecOverGoOn { get; set; }
  176. public RelayCommand SecOverGoDown { get; set; }
  177. public RelayCommand SecAutoModel { get; set; }
  178. public RelayCommand SecManualModel { get; set; }
  179. #endregion
  180. public DebugViewModel()
  181. {
  182. #region 设备控制
  183. PlcInite = new RelayCommand(() => { ActionManage.GetInstance.Send("InitCommand"); });
  184. Plc1Reset = new RelayCommand(() => { ActionManage.GetInstance.Send("Plc1Reset"); });
  185. StartOrder = new RelayCommand(() => { ActionManage.GetInstance.Send("StartOrder", FoodMenuID); });
  186. StopLocalOrder = new RelayCommand(() => { ActionManage.GetInstance.Send("StopLocalOrder"); });
  187. ModeChange = new RelayCommand(() => {
  188. ActionManage.GetInstance.Send("ModeChange");
  189. if(ModeButten == "联网模式")
  190. {
  191. ModeButten = "本地模式";
  192. }
  193. else
  194. {
  195. ModeButten = "联网模式";
  196. }
  197. });
  198. #endregion
  199. #region 菜品控制
  200. FoodLibInit = new RelayCommand(() => { ActionManage.GetInstance.Send("FoodLibInit"); });//菜品库初始化
  201. SurplusCheck = new RelayCommand(() => { ActionManage.GetInstance.Send("SurplusCheck"); });//菜品库初始化
  202. StartElectromagnetism = new RelayCommand(() => { ActionManage.GetInstance.Send("Electromagnetism", new List<bool> { false }); });//电磁阀启动
  203. StopElectromagnetism = new RelayCommand(() => { ActionManage.GetInstance.Send("Electromagnetism", new List<bool> { true });});//电磁阀关闭
  204. SetSpeed = new RelayCommand(() =>
  205. {
  206. ActionManage.GetInstance.Send("SetSpeed", new List<int> { MoveSpeed });
  207. });//设定速度
  208. PawToPoint1 = new RelayCommand(() => { ActionManage.GetInstance.Send("PawToPoint1"); });//爪子去1号位
  209. PawToPoint2 = new RelayCommand(() => { ActionManage.GetInstance.Send("PawToPoint2"); });//爪子去2号位
  210. PawToPoint3 = new RelayCommand(() => { ActionManage.GetInstance.Send("PawToPoint3"); });//爪子去3号位
  211. GetDistance_1 = new RelayCommand(() => { ActionManage.GetInstance.Send("GetDistance_1"); });//感应距离1
  212. GetDistance_2 = new RelayCommand(() => { ActionManage.GetInstance.Send("GetDistance_2"); });//感应距离2
  213. GetDistance_3 = new RelayCommand(() => { ActionManage.GetInstance.Send("GetDistance_3"); });//感应距离3
  214. PawTurnFront = new RelayCommand(() => { ActionManage.GetInstance.Send("PawTurnFront"); });//夹爪正转
  215. PawTurnBack = new RelayCommand(() => { ActionManage.GetInstance.Send("PawTurnBack"); });//夹爪反转
  216. SetArmPosition = new RelayCommand(() => { ActionManage.GetInstance.Send("SetArmPosition", new List<int> { SettingX, SettingY }); });//设定机械臂位置
  217. SetNowPosition = new RelayCommand(() => { ActionManage.GetInstance.Send("SetNowPosition", new List<int> { SettingX, SettingY }); });//设定机械臂当前位置
  218. ArmRun = new RelayCommand(() => {
  219. //判断是否都未点击
  220. if(!ArmRunDown&&!ArmRunUp&&!ArmRunLeft&&!ArmRunRight)
  221. {
  222. return;
  223. }
  224. ArmRunEnable = !ArmRunEnable;
  225. if(ArmRunEnable)
  226. {
  227. ArmButtonName = "启动";
  228. }
  229. else
  230. {
  231. ArmButtonName = "停止";
  232. }
  233. if(ArmRunUp)
  234. {
  235. ActionManage.GetInstance.Send("ArmRunUp", !ArmRunEnable);
  236. }
  237. else if(ArmRunDown)
  238. {
  239. ActionManage.GetInstance.Send("ArmRunDown", !ArmRunEnable);
  240. }
  241. else if (ArmRunLeft)
  242. {
  243. ActionManage.GetInstance.Send("ArmRunLeft", !ArmRunEnable);
  244. }
  245. else if(ArmRunRight)
  246. {
  247. ActionManage.GetInstance.Send("ArmRunRight", !ArmRunEnable);
  248. }
  249. });//设定机械臂位置
  250. #endregion
  251. #region 配料仓控制
  252. OutMaterials = new RelayCommand(() => { ActionManage.GetInstance.Send("OutMaterials" ,new List<int> { PassagePosition + 1,Weight } ); });
  253. #endregion
  254. #region 炒锅1
  255. Pot1SimOrder = new RelayCommand(() => { ActionManage.GetInstance.Send("模拟小炒锅1订单",new List<int> { OilTime,OilFirGear,OilStrGear,Food1Time,Food1FirGear,Food1StrGear,Food2Time,Food2FirGear,Food2StrGear }); });//模拟订单
  256. AddOil = new RelayCommand(() => { ActionManage.GetInstance.Send("AddOil", 1); });//加油
  257. StartFire = new RelayCommand(() => { ActionManage.GetInstance.Send("StartFire"); });//加热启动
  258. StopFire = new RelayCommand(() => { ActionManage.GetInstance.Send("StopFire"); });//加热停止
  259. StartStir = new RelayCommand(() => { ActionManage.GetInstance.Send("StartStir"); });//搅拌启动
  260. StopStir = new RelayCommand(() => { ActionManage.GetInstance.Send("StopStir"); });//搅拌停止
  261. MagnetOn = new RelayCommand(() => { ActionManage.GetInstance.Send("MagnetOn"); });//磁吸开启
  262. MagnetOff = new RelayCommand(() => { ActionManage.GetInstance.Send("MagnetOff"); });//磁吸开启
  263. OutFood = new RelayCommand(() => { ActionManage.GetInstance.Send("OutFood"); });//倒菜启动
  264. StirArmGoOrigin = new RelayCommand(() => { ActionManage.GetInstance.Send("StirArmGoOrigin"); });//搅拌臂去原点位
  265. StirArmGoWork = new RelayCommand(() => { ActionManage.GetInstance.Send("StirArmGoWork"); });//搅拌臂去炒制位
  266. HBOTGoWork = new RelayCommand(() => { ActionManage.GetInstance.Send("HBOTGoWork"); });//放盒子到位
  267. OutMeal = new RelayCommand(() => { ActionManage.GetInstance.Send("OutMeal"); });//出餐启动
  268. SetFire = new RelayCommand(() => { ActionManage.GetInstance.Send("SetFire", new List<int> { FireGear }); });//加热挡位设定
  269. SetStir = new RelayCommand(() => { ActionManage.GetInstance.Send("SetStir", new List<int> { StirGear }); });//搅拌挡位设定
  270. SetFry = new RelayCommand(() => { ActionManage.GetInstance.Send("SetFry", new List<int> { FryGear }); });//炒锅选择
  271. #endregion
  272. #region 炒锅2
  273. SecAddOil = new RelayCommand(() => { ActionManage.GetInstance.Send("AddOil", 2); });
  274. SecTempTurnOff = new RelayCommand(() => { ActionManage.GetInstance.Send("TakeOff", 2); });
  275. SecOneBlock = new RelayCommand(() => { ActionManage.GetInstance.Send("OneBlock", 2); });
  276. SecTwoBlock = new RelayCommand(() => { ActionManage.GetInstance.Send("TwoBlock", 2); });
  277. SecThreeBlock = new RelayCommand(() => { ActionManage.GetInstance.Send("ThreeBlock", 2); });
  278. SecOverTurnOff = new RelayCommand(() => { ActionManage.GetInstance.Send("OverTurnOff", 2); });
  279. SecOverOneBlock = new RelayCommand(() => { ActionManage.GetInstance.Send("OverOneBlock", 2); });
  280. SecOverTwoBlock = new RelayCommand(() => { ActionManage.GetInstance.Send("OverTwoBlock", 2); });
  281. SecOverThreeBlock = new RelayCommand(() => { ActionManage.GetInstance.Send("OverThreeBlock", 2); });
  282. SecOverGoOn = new RelayCommand(() => { ActionManage.GetInstance.Send("OverGoOn", 2); });
  283. SecOverGoDown = new RelayCommand(() => { ActionManage.GetInstance.Send("OverGoDown", 2); });
  284. SecAutoModel = new RelayCommand(() => { ActionManage.GetInstance.Send("AutoModel", 2); });
  285. SecManualModel = new RelayCommand(() => { ActionManage.GetInstance.Send("ManualModel", 2); });
  286. #endregion
  287. Plugin.GetInstance()?.GetPlugin<DeviceMgr>()?.GetDevices().ForEach(device =>
  288. {
  289. if (device.Name == "MorkT") DeviceId = device.DeviceId
  290. ;
  291. });
  292. ThreadManage.GetInstance().StartLong(new Action(() =>
  293. {
  294. //variableMonitors = Plugin.GetInstance()?.GetPlugin<DeviceMgr>()?.GetDevices()?.FirstOrDefault(p => p.DeviceId == DeviceId)?.variableMonitors;
  295. if(variableMonitors != null)
  296. {
  297. RealX = variableMonitors.FirstOrDefault(p => p.Notes == "机械手臂X").CurrentValue;
  298. RealY = variableMonitors.FirstOrDefault(p => p.Notes == "机械手臂Y").CurrentValue;
  299. }
  300. }), "获取小炒数据");
  301. }
  302. }
  303. }