终端一体化运控平台
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.
 
 
 

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