终端一体化运控平台
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 

335 rader
19 KiB

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