WagoSocketSimulator.cs 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937
  1. using Aitex.Common.Util;
  2. using Aitex.Core.RT.Device;
  3. using Aitex.Core.RT.Log;
  4. using Aitex.Core.UI.Control;
  5. using Aitex.Core.Util;
  6. using MECF.Framework.Common.Device.Festo;
  7. using MECF.Framework.Common.Device.Wago;
  8. using MECF.Framework.Common.Net;
  9. using MECF.Framework.Common.Simulator;
  10. using MECF.Framework.Simulator.Core.Driver;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.IO;
  14. using static MECF.Framework.Common.Simulator.MotorSimulator;
  15. namespace CyberX8_Simulator.Devices
  16. {
  17. public class WagoSocketSimulator : SocketDeviceSimulator
  18. {
  19. private const short WRITE_DO_STARTADDRESS = 0x0200;
  20. private const short WRITE_AO_STARTADDRESS = 0x0200;
  21. //键是名字,值是对应数据所在的位置 注意:要和WagoControlCfg里面的地址顺序对上
  22. public Dictionary<string, int> DONameIndexDic;
  23. public Dictionary<string, int> DINameIndexDic;
  24. public Dictionary<string, int> AINameIndexDic;
  25. public Dictionary<string, int> AONameIndexDic;
  26. private IByteTransform byteTransform = new BigEndianByteTransformBase();
  27. //存储模拟器数据的数组
  28. public byte[] DOBytes = new byte[200];
  29. public short[] AOShorts = new short[200];
  30. public byte[] DIBytes = new byte[200];
  31. public short[] AIShorts = new short[200];
  32. /// <summary>
  33. /// 写DO锁
  34. /// </summary>
  35. private object _writeDOLocker = new object();
  36. /// <summary>
  37. /// 写AO锁
  38. /// </summary>
  39. private object _writeAOLocker = new object();
  40. /// <summary>
  41. /// Festo Data Buffer
  42. /// </summary>
  43. private Dictionary<string, bool> _festoDataBuffer = new Dictionary<string, bool>();
  44. /// <summary>
  45. /// Name-WagoDO dictionary
  46. /// </summary>
  47. private Dictionary<string, WagoDO> _doNameWagoDODic = new Dictionary<string, WagoDO>();
  48. /// <summary>
  49. /// Name-WagoDI dictionary
  50. /// </summary>
  51. private Dictionary<string, WagoDI> _diNameWagoDIDic = new Dictionary<string, WagoDI>();
  52. /// <summary>
  53. /// 定时器
  54. /// </summary>
  55. private PeriodicJob _LoaderPeriodicJob;
  56. private PeriodicJob _Wago2PeriodicJob;
  57. private PeriodicJob _Wago4PeriodicJob;
  58. private bool _rinse1FillValve = false;
  59. private bool _rinse1DumpValve = false;
  60. private bool _rinse2FillValve = false;
  61. private bool _rinse2DumpValve = false;
  62. private bool _rinse3FillValve = false;
  63. private bool _rinse3DumpValve = false;
  64. private bool _rinse4FillValve = false;
  65. private bool _rinse4DumpValve = false;
  66. private bool _reservoir1PumpOn = false;
  67. private int _srd1currentVacuumValue;
  68. private int _srd2currentVacuumValue;
  69. private int _port;
  70. //delegate
  71. #region Delegate
  72. public delegate void VariableValueChanged(object obj);
  73. public delegate void UpdateVariableValueWagoDatasChanged(string sourceName, string targetName, bool value,bool invert);
  74. #endregion
  75. #region 事件
  76. /// <summary>
  77. /// 变量变更事件
  78. /// </summary>
  79. public event VariableValueChanged OnDIVariableValueChanged;
  80. public event VariableValueChanged OnAIVariableValueChanged;
  81. public event VariableValueChanged OnDOVariableValueChanged;
  82. public event VariableValueChanged OnAOVariableValueChanged;
  83. #endregion
  84. public WagoSocketSimulator(int port):base(port)
  85. {
  86. SimulatorCommManager.Instance.OnUpdateVariableValueChanged += UpdataDataCausedByOtherModule;
  87. MotorSimulator.Instance.OnUpdateWagoDatasChanged += UpdataDataCausedByOtherModule;
  88. InitializeData(port);
  89. _port = port;
  90. }
  91. private void UpdataDataCausedByOtherModule(string sourceName,string name, bool value, bool invert)
  92. {
  93. value = invert ? !value : value;
  94. //AI Data
  95. if (AINameIndexDic.ContainsKey(name))
  96. {
  97. switch (name)
  98. {
  99. case "r_LoaderA_LS_Vacuum_anlg":
  100. case "r_LoaderB_LS_Vacuum_anlg":
  101. AIShorts[AINameIndexDic[name]] = value ? (short)0x32C8 : (short)0x2AF8;
  102. break;
  103. case "r_DPUF_A_CHUCK_A_VAC":
  104. case "r_DPUF_A_CHUCK_B_VAC":
  105. AIShorts[AINameIndexDic[name]] = value ? (short)0x0C80 : (short)0x32C8;
  106. break;
  107. case "r_LOADERA_BERNOULLI_PRESSURE":
  108. case "r_LOADERB_BERNOULLI_PRESSURE":
  109. case "r_LOADERA_CHUCK_BLADDER":
  110. case "r_LOADERB_CHUCK_BLADDER":
  111. case "r_LOADERA_WS_BLADDER_PRESSURE":
  112. case "r_LOADERB_WS_BLADDER_PRESSURE":
  113. AIShorts[AINameIndexDic[name]] = value ? (short)0x2AF8 : (short)0x00;
  114. break;
  115. case "r_PREWET_DI_PRESS":
  116. AIShorts[AINameIndexDic[name]] = value ? (short)15000 : (short)3276;
  117. AIShorts[AINameIndexDic["r_PREWET_FLOW"]] = value ? (short)25000 : (short)3276;
  118. break;
  119. default:
  120. break;
  121. }
  122. }
  123. if (!string.IsNullOrEmpty(sourceName))
  124. {
  125. switch (sourceName)
  126. {
  127. case "c_QDRD1_DI_FILL":
  128. _rinse1FillValve = value;
  129. break;
  130. case "c_QDRD1_DUMP":
  131. _rinse1DumpValve = value;
  132. break;
  133. case "c_QDRD2_DI_FILL":
  134. _rinse2FillValve = value;
  135. break;
  136. case "c_QDRD2_DUMP":
  137. _rinse2DumpValve = value;
  138. break;
  139. case "c_QDRD3_DI_FILL":
  140. _rinse3FillValve = value;
  141. break;
  142. case "c_QDRD3_DUMP":
  143. _rinse3DumpValve = value;
  144. break;
  145. case "c_QDRD4_DI_FILL":
  146. _rinse4FillValve = value;
  147. break;
  148. case "c_QDRD4_DUMP":
  149. _rinse4DumpValve = value;
  150. break;
  151. case "c_METAL1_PUMP_ON":
  152. _reservoir1PumpOn = value;
  153. break;
  154. default:
  155. break;
  156. }
  157. }
  158. //DI Data
  159. UpdataDIBytes(name, value ? 1 : 0);
  160. //Festo Data
  161. if (name == "FlowTestClamp") _festoDataBuffer[name] = value;
  162. }
  163. /// <summary>
  164. /// 触发Wago对应数据更新
  165. /// </summary>
  166. /// <param name="position"></param>
  167. /// <param name="value"></param>
  168. private void UpdateDataCausedByWago(int position, bool value)
  169. {
  170. //Puf Simulator
  171. if (DONameIndexDic.ContainsKey("c_PUF_CHUCK") && position == DONameIndexDic["c_PUF_CHUCK"])
  172. {
  173. value = _doNameWagoDODic["c_PUF_CHUCK"].Invert? !value : value;
  174. UpdataDIBytes("r_PUF_A_CHUCK_OUT", value ? 1 : 0);
  175. UpdataDIBytes("r_PUF_B_CHUCK_OUT", value ? 1 : 0);
  176. UpdataDIBytes("r_PUF_A_CHUCK_IN", !value ? 1 : 0);
  177. UpdataDIBytes("r_PUF_B_CHUCK_IN", !value ? 1 : 0);
  178. }
  179. //HVD Simulator
  180. if (DONameIndexDic.ContainsKey("c_HVD_1_HIGH") && position == DONameIndexDic["c_HVD_1_HIGH"])
  181. {
  182. value = _doNameWagoDODic["c_HVD_1_HIGH"].Invert ? !value : value;
  183. UpdataAIShorts("r_HVD_1_ANALOG", value ? 4500 : 0);
  184. }
  185. if (DONameIndexDic.ContainsKey("c_HVD_2_HIGH") && position == DONameIndexDic["c_HVD_2_HIGH"])
  186. {
  187. value = _doNameWagoDODic["c_HVD_2_HIGH"].Invert ? !value : value;
  188. UpdataAIShorts("r_HVD_2_ANALOG", value ? 4500 : 0);
  189. }
  190. //SRD Simulator
  191. //Lift UP
  192. if (DONameIndexDic.ContainsKey("c_SRD1_LIFT_UP") && position == DONameIndexDic["c_SRD1_LIFT_UP"])
  193. {
  194. value = (_doNameWagoDODic["c_SRD1_LIFT_UP"].Invert ^ _diNameWagoDIDic["r_SRD1_LIFT_UP"].Invert) ? !value : value;
  195. UpdataDIBytes("r_SRD1_LIFT_UP", value ? 1 : 0);
  196. }
  197. if (DONameIndexDic.ContainsKey("c_SRD2_LIFT_UP") && position == DONameIndexDic["c_SRD2_LIFT_UP"])
  198. {
  199. value = (_doNameWagoDODic["c_SRD2_LIFT_UP"].Invert ^ _diNameWagoDIDic["r_SRD2_LIFT_UP"].Invert) ? !value : value;
  200. UpdataDIBytes("r_SRD2_LIFT_UP", value ? 1 : 0);
  201. }
  202. //Flippers
  203. if (DONameIndexDic.ContainsKey("c_SRD1_150_FLIPPERS_IN") && position == DONameIndexDic["c_SRD1_150_FLIPPERS_IN"])
  204. {
  205. value = (_doNameWagoDODic["c_SRD1_150_FLIPPERS_IN"].Invert ^ _diNameWagoDIDic["r_SRD1_150_FLIPPER1_OUT"].Invert) ? !value : value;
  206. UpdataDIBytes("r_SRD1_150_FLIPPER1_OUT", value ? 0 : 1);
  207. UpdataDIBytes("r_SRD1_150_FLIPPER2_OUT", value ? 0 : 1);
  208. UpdataDIBytes("r_SRD1_150_FLIPPER3_OUT", value ? 0 : 1);
  209. }
  210. if (DONameIndexDic.ContainsKey("c_SRD2_150_FLIPPERS_IN") && position == DONameIndexDic["c_SRD2_150_FLIPPERS_IN"])
  211. {
  212. value = (_doNameWagoDODic["c_SRD2_150_FLIPPERS_IN"].Invert ^ _diNameWagoDIDic["r_SRD2_150_FLIPPER1_OUT"].Invert) ? !value : value;
  213. UpdataDIBytes("r_SRD2_150_FLIPPER1_OUT", value ? 0 : 1);
  214. UpdataDIBytes("r_SRD2_150_FLIPPER2_OUT", value ? 0 : 1);
  215. UpdataDIBytes("r_SRD2_150_FLIPPER3_OUT", value ? 0 : 1);
  216. }
  217. if (DONameIndexDic.ContainsKey("c_SRD1_200_FLIPPERS_IN") && position == DONameIndexDic["c_SRD1_200_FLIPPERS_IN"])
  218. {
  219. value = (_doNameWagoDODic["c_SRD1_200_FLIPPERS_IN"].Invert ^ _diNameWagoDIDic["r_SRD1_200_FLIPPER1_OUT"].Invert) ? !value : value;
  220. UpdataDIBytes("r_SRD1_200_FLIPPER1_OUT", value ? 0 : 1);
  221. UpdataDIBytes("r_SRD1_200_FLIPPER2_OUT", value ? 0 : 1);
  222. UpdataDIBytes("r_SRD1_200_FLIPPER3_OUT", value ? 0 : 1);
  223. }
  224. if (DONameIndexDic.ContainsKey("c_SRD2_200_FLIPPERS_IN") && position == DONameIndexDic["c_SRD2_200_FLIPPERS_IN"])
  225. {
  226. value = (_doNameWagoDODic["c_SRD2_200_FLIPPERS_IN"].Invert ^ _diNameWagoDIDic["r_SRD2_200_FLIPPER1_OUT"].Invert) ? !value : value;
  227. UpdataDIBytes("r_SRD2_200_FLIPPER1_OUT", value ? 0 : 1);
  228. UpdataDIBytes("r_SRD2_200_FLIPPER2_OUT", value ? 0 : 1);
  229. UpdataDIBytes("r_SRD2_200_FLIPPER3_OUT", value ? 0 : 1);
  230. }
  231. //Shuttle
  232. if (DONameIndexDic.ContainsKey("c_SRD1_Shutter_Close") && position == DONameIndexDic["c_SRD1_Shutter_Close"])
  233. {
  234. value = (_doNameWagoDODic["c_SRD1_Shutter_Close"].Invert ^ _diNameWagoDIDic["r_SRD1_SHUTTER_OPEN"].Invert) ? !value : value;
  235. UpdataDIBytes("r_SRD1_SHUTTER_OPEN", value ? 0 : 1);
  236. UpdataDIBytes("r_SRD1_SHUTTER_CLOSED", value ? 1 : 0);
  237. }
  238. if (DONameIndexDic.ContainsKey("c_SRD2_Shutter_Close") && position == DONameIndexDic["c_SRD2_Shutter_Close"])
  239. {
  240. value = (_doNameWagoDODic["c_SRD2_Shutter_Close"].Invert ^ _diNameWagoDIDic["r_SRD2_SHUTTER_OPEN"].Invert) ? !value : value;
  241. UpdataDIBytes("r_SRD2_SHUTTER_OPEN", value ? 0 : 1);
  242. UpdataDIBytes("r_SRD2_SHUTTER_CLOSED", value ? 1 : 0);
  243. }
  244. //Vacuum
  245. if (DONameIndexDic.ContainsKey("c_SRD1_CHUCK_VACUUM") && position == DONameIndexDic["c_SRD1_CHUCK_VACUUM"])
  246. {
  247. value = (_doNameWagoDODic["c_SRD1_CHUCK_VACUUM"].Invert ) ? !value : value;
  248. _srd1currentVacuumValue = value ? 5000 : 15000;
  249. UpdataAIShorts("r_SRD1_CHUCK_VACUUM_anlg", _srd1currentVacuumValue);
  250. UpdataDIBytes("r_SRD1_CHUCK_VAC_OK", value ? 0 : 1);
  251. }
  252. if (DONameIndexDic.ContainsKey("c_SRD2_CHUCK_VACUUM") && position == DONameIndexDic["c_SRD2_CHUCK_VACUUM"])
  253. {
  254. value = _doNameWagoDODic["c_SRD2_CHUCK_VACUUM"].Invert ? !value : value;
  255. _srd2currentVacuumValue = value ? 5000 : 15000;
  256. UpdataAIShorts("r_SRD2_CHUCK_VACUUM_anlg", _srd2currentVacuumValue);
  257. UpdataDIBytes("r_SRD2_CHUCK_VAC_OK", value ? 0 : 1);
  258. }
  259. if (DONameIndexDic.ContainsKey("c_SRD1_CHUCK_ATM_ON") && position == DONameIndexDic["c_SRD1_CHUCK_ATM_ON"])
  260. {
  261. value = _doNameWagoDODic["c_SRD1_CHUCK_ATM_ON"].Invert ? !value : value;
  262. _srd1currentVacuumValue = value ? _srd1currentVacuumValue - 8000 : _srd1currentVacuumValue;
  263. UpdataAIShorts("r_SRD1_CHUCK_VACUUM_anlg", _srd1currentVacuumValue);
  264. }
  265. if (DONameIndexDic.ContainsKey("c_SRD2_CHUCK_ATM_ON") && position == DONameIndexDic["c_SRD2_CHUCK_ATM_ON"])
  266. {
  267. value = _doNameWagoDODic["c_SRD2_CHUCK_ATM_ON"].Invert ? !value : value;
  268. _srd2currentVacuumValue = value ? _srd2currentVacuumValue - 8000 : _srd2currentVacuumValue;
  269. UpdataAIShorts("r_SRD2_CHUCK_VACUUM_anlg", _srd2currentVacuumValue);
  270. }
  271. //Water
  272. if (DONameIndexDic.ContainsKey("c_SRD1_WATER_ON") && position == DONameIndexDic["c_SRD1_WATER_ON"])
  273. {
  274. value = _doNameWagoDODic["c_SRD1_WATER_ON"].Invert ? !value : value;
  275. UpdataAIShorts("r_SRD1_WATER_FLOW", value ? 30000 : 3277);
  276. }
  277. if (DONameIndexDic.ContainsKey("c_SRD2_WATER_ON") && position == DONameIndexDic["c_SRD2_WATER_ON"])
  278. {
  279. value = _doNameWagoDODic["c_SRD2_WATER_ON"].Invert ? !value : value;
  280. UpdataAIShorts("r_SRD2_WATER_FLOW", value ? 30000 : 3277);
  281. }
  282. //metal 1 pump
  283. if (DONameIndexDic.ContainsKey("c_METAL1_PUMP_ON") && position == DONameIndexDic["c_METAL1_PUMP_ON"])
  284. {
  285. value = _doNameWagoDODic["c_METAL1_PUMP_ON"].Invert ? !value : value;
  286. UpdataDIBytes("r_METAL1_PUMP_ON", value ? 1 : 0);
  287. }
  288. }
  289. /// <summary>
  290. /// 初始化字典
  291. /// </summary>
  292. private void InitializeData(int port) //端口用于初始化不同Wago设备的字典
  293. {
  294. //加载对应配置文件 WagoControllerCfg-Simulator.xml
  295. try
  296. {
  297. string oldXmlPath = PathManager.GetCfgDir();
  298. string newXmlPath = oldXmlPath.Replace("CyberX8_Simulator", "CyberX8_RT") + "Devices\\WagoControllerCfg-Simulator.xml";
  299. WagoControllerCfg cfg = CustomXmlSerializer.Deserialize<WagoControllerCfg>(new FileInfo(newXmlPath));
  300. if (cfg != null)
  301. {
  302. foreach (WagoDeviceConfig config in cfg.WagoDeviceConfigs)
  303. {
  304. if (port == config.Port)
  305. {
  306. if(config.Module == "Loader" && _LoaderPeriodicJob == null)
  307. {
  308. _LoaderPeriodicJob = new PeriodicJob(100, OnTimer, $"Wago {config.Module} timer",true);
  309. }
  310. if (config.Module == "Wago2" && _Wago2PeriodicJob == null)
  311. {
  312. _Wago2PeriodicJob = new PeriodicJob(100, OnTimer1, $"Wago {config.Module} timer", true);
  313. }
  314. if (config.Module == "Wago4" && _Wago2PeriodicJob == null)
  315. {
  316. _Wago2PeriodicJob = new PeriodicJob(100, OnTimer3, $"Wago {config.Module} timer", true);
  317. }
  318. //加载DO
  319. int i = 0;
  320. DONameIndexDic = new Dictionary<string, int>();
  321. if(config.WagoDigOut != null && config.WagoDigOut.WagoDOGroups != null)
  322. {
  323. foreach (var group in config.WagoDigOut.WagoDOGroups)
  324. {
  325. foreach (var item in group.WagoDOs)
  326. {
  327. DONameIndexDic[item.Name] = i;
  328. i++;
  329. _doNameWagoDODic[item.Name] = item;
  330. }
  331. }
  332. }
  333. //加载DI
  334. i = 0;
  335. DINameIndexDic = new Dictionary<string, int>();
  336. if(config.WagoDigIn != null && config.WagoDigIn.WagoDIGroups != null)
  337. {
  338. foreach (var group in config.WagoDigIn.WagoDIGroups)
  339. {
  340. foreach (var item in group.WagoDIs)
  341. {
  342. DINameIndexDic[item.Name] = i;
  343. i++;
  344. _diNameWagoDIDic[item.Name] = item;
  345. }
  346. }
  347. }
  348. //加载AO
  349. i = 0;
  350. AONameIndexDic = new Dictionary<string, int>();
  351. if (config.WagoAnoOut != null && config.WagoAnoOut.WagoAOGroups != null)
  352. {
  353. foreach (var group in config.WagoAnoOut.WagoAOGroups)
  354. {
  355. foreach (var item in group.WagoAOs)
  356. {
  357. AONameIndexDic[item.Name] = i;
  358. i++;
  359. }
  360. }
  361. }
  362. //加载AI
  363. i = 0;
  364. AINameIndexDic = new Dictionary<string, int>();
  365. if (config.WagoAnoIn != null && config.WagoAnoIn.WagoAIGroups != null)
  366. {
  367. foreach (var group in config.WagoAnoIn.WagoAIGroups)
  368. {
  369. foreach (var item in group.WagoAIs)
  370. {
  371. AINameIndexDic[item.Name] = i;
  372. i++;
  373. }
  374. }
  375. }
  376. }
  377. }
  378. }
  379. }
  380. catch
  381. {
  382. LOG.WriteLog(eEvent.ERR_WAGO, "Wago", "Load wago WagoControllerCfg-Simulator.xml failed");
  383. }
  384. //设置IO变量默认值
  385. if (AINameIndexDic.ContainsKey("r_LoaderA_LS_Vacuum_anlg")) AIShorts[AINameIndexDic["r_LoaderA_LS_Vacuum_anlg"]] = 0x32C8;
  386. if (AINameIndexDic.ContainsKey("r_LoaderB_LS_Vacuum_anlg")) AIShorts[AINameIndexDic["r_LoaderB_LS_Vacuum_anlg"]] = 0x32C8;
  387. if (AINameIndexDic.ContainsKey("r_DPUF_A_CHUCK_A_VAC")) AIShorts[AINameIndexDic["r_DPUF_A_CHUCK_A_VAC"]] = 0x32C8;
  388. if (AINameIndexDic.ContainsKey("r_DPUF_A_CHUCK_B_VAC")) AIShorts[AINameIndexDic["r_DPUF_A_CHUCK_B_VAC"]] = 0x32C8;
  389. if (AINameIndexDic.ContainsKey("r_SYSTEM_EXHAUST")) AIShorts[AINameIndexDic["r_SYSTEM_EXHAUST"]] = 0x3A98;
  390. if (DONameIndexDic.ContainsKey("c_HVD_1_ENABLE")) DOBytes[DONameIndexDic["c_HVD_1_ENABLE"]] = 1;
  391. if (DONameIndexDic.ContainsKey("c_HVD_2_ENABLE")) DOBytes[DONameIndexDic["c_HVD_2_ENABLE"]] = 1;
  392. //QDR
  393. if (AINameIndexDic.ContainsKey("r_QDRD1_WATER_LEVEL")) AIShorts[AINameIndexDic["r_QDRD1_WATER_LEVEL"]] = 0;
  394. if (AINameIndexDic.ContainsKey("r_QDRD2_WATER_LEVEL")) AIShorts[AINameIndexDic["r_QDRD2_WATER_LEVEL"]] = 0;
  395. if (AINameIndexDic.ContainsKey("r_QDRD3_WATER_LEVEL")) AIShorts[AINameIndexDic["r_QDRD3_WATER_LEVEL"]] = 0;
  396. if (AINameIndexDic.ContainsKey("r_QDRD4_WATER_LEVEL")) AIShorts[AINameIndexDic["r_QDRD4_WATER_LEVEL"]] = 0;
  397. //SRD
  398. if (AINameIndexDic.ContainsKey("r_SRD1_CHUCK_VACUUM_anlg")) AIShorts[AINameIndexDic["r_SRD1_CHUCK_VACUUM_anlg"]] = 15000;
  399. if (AINameIndexDic.ContainsKey("r_SRD2_CHUCK_VACUUM_anlg")) AIShorts[AINameIndexDic["r_SRD2_CHUCK_VACUUM_anlg"]] = 15000;
  400. if (DINameIndexDic.ContainsKey("r_SRD1_SHUTTER_OPEN")) DIBytes[DINameIndexDic["r_SRD1_SHUTTER_OPEN"]] = 1;
  401. if (DINameIndexDic.ContainsKey("r_SRD1_SHUTTER_CLOSED")) DIBytes[DINameIndexDic["r_SRD1_SHUTTER_CLOSED"]] = 0;
  402. if (DINameIndexDic.ContainsKey("r_SRD2_SHUTTER_OPEN")) DIBytes[DINameIndexDic["r_SRD2_SHUTTER_OPEN"]] = 1;
  403. if (DINameIndexDic.ContainsKey("r_SRD2_SHUTTER_CLOSED")) DIBytes[DINameIndexDic["r_SRD2_SHUTTER_CLOSED"]] = 0;
  404. if (DINameIndexDic.ContainsKey("r_SRD_FLUID_LEVEL")) DIBytes[DINameIndexDic["r_SRD_FLUID_LEVEL"]] = 1;
  405. if (DINameIndexDic.ContainsKey("r_SRD1_CHUCK_VAC_OK")) DIBytes[DINameIndexDic["r_SRD1_CHUCK_VAC_OK"]] = 1;
  406. if (DINameIndexDic.ContainsKey("r_SRD2_CHUCK_VAC_OK")) DIBytes[DINameIndexDic["r_SRD2_CHUCK_VAC_OK"]] = 1;
  407. if (DINameIndexDic.ContainsKey("r_SRD1_150_FLIPPER1_OUT")) DIBytes[DINameIndexDic["r_SRD1_150_FLIPPER1_OUT"]] = 1;
  408. if (DINameIndexDic.ContainsKey("r_SRD1_150_FLIPPER2_OUT")) DIBytes[DINameIndexDic["r_SRD1_150_FLIPPER2_OUT"]] = 1;
  409. if (DINameIndexDic.ContainsKey("r_SRD1_150_FLIPPER3_OUT")) DIBytes[DINameIndexDic["r_SRD1_150_FLIPPER3_OUT"]] = 1;
  410. if (DINameIndexDic.ContainsKey("r_SRD1_200_FLIPPER1_OUT")) DIBytes[DINameIndexDic["r_SRD1_200_FLIPPER1_OUT"]] = 1;
  411. if (DINameIndexDic.ContainsKey("r_SRD1_200_FLIPPER2_OUT")) DIBytes[DINameIndexDic["r_SRD1_200_FLIPPER2_OUT"]] = 1;
  412. if (DINameIndexDic.ContainsKey("r_SRD1_200_FLIPPER3_OUT")) DIBytes[DINameIndexDic["r_SRD1_200_FLIPPER3_OUT"]] = 1;
  413. if (DINameIndexDic.ContainsKey("r_SRD2_150_FLIPPER1_OUT")) DIBytes[DINameIndexDic["r_SRD2_150_FLIPPER1_OUT"]] = 1;
  414. if (DINameIndexDic.ContainsKey("r_SRD2_150_FLIPPER2_OUT")) DIBytes[DINameIndexDic["r_SRD2_150_FLIPPER2_OUT"]] = 1;
  415. if (DINameIndexDic.ContainsKey("r_SRD2_150_FLIPPER3_OUT")) DIBytes[DINameIndexDic["r_SRD2_150_FLIPPER3_OUT"]] = 1;
  416. if (DINameIndexDic.ContainsKey("r_SRD2_200_FLIPPER1_OUT")) DIBytes[DINameIndexDic["r_SRD2_200_FLIPPER1_OUT"]] = 1;
  417. if (DINameIndexDic.ContainsKey("r_SRD2_200_FLIPPER2_OUT")) DIBytes[DINameIndexDic["r_SRD2_200_FLIPPER2_OUT"]] = 1;
  418. if (DINameIndexDic.ContainsKey("r_SRD2_200_FLIPPER3_OUT")) DIBytes[DINameIndexDic["r_SRD2_200_FLIPPER3_OUT"]] = 1;
  419. if (DONameIndexDic.ContainsKey("c_SRD1_150_FLIPPERS_IN")) DOBytes[DONameIndexDic["c_SRD1_150_FLIPPERS_IN"]] = 1;
  420. if (DONameIndexDic.ContainsKey("c_SRD2_150_FLIPPERS_IN")) DOBytes[DONameIndexDic["c_SRD2_150_FLIPPERS_IN"]] = 1;
  421. if (DONameIndexDic.ContainsKey("c_SRD1_200_FLIPPERS_IN")) DOBytes[DONameIndexDic["c_SRD1_200_FLIPPERS_IN"]] = 1;
  422. if (DONameIndexDic.ContainsKey("c_SRD2_200_FLIPPERS_IN")) DOBytes[DONameIndexDic["c_SRD2_200_FLIPPERS_IN"]] = 1;
  423. if (DONameIndexDic.ContainsKey("c_SRD1_LIFT_UP")) DOBytes[DONameIndexDic["c_SRD1_LIFT_UP"]] = 1;
  424. if (DONameIndexDic.ContainsKey("c_SRD2_LIFT_UP")) DOBytes[DONameIndexDic["c_SRD2_LIFT_UP"]] = 1;
  425. if (DINameIndexDic.ContainsKey("r_SRD1_WAFER_PRESENT")) DIBytes[DINameIndexDic["r_SRD1_WAFER_PRESENT"]] = 1;
  426. if (DINameIndexDic.ContainsKey("r_SRD2_WAFER_PRESENT")) DIBytes[DINameIndexDic["r_SRD2_WAFER_PRESENT"]] = 1;
  427. if (AINameIndexDic.ContainsKey("r_SRD_SUPPLY_WATER_PRESS")) AIShorts[AINameIndexDic["r_SRD_SUPPLY_WATER_PRESS"]] = 20000;
  428. //Metal
  429. if (AINameIndexDic.ContainsKey("r_PUMP4_FLOW")) AIShorts[AINameIndexDic["r_PUMP4_FLOW"]] = 3277;
  430. if (AINameIndexDic.ContainsKey("r_PUMP3_FLOW")) AIShorts[AINameIndexDic["r_PUMP3_FLOW"]] = 3277;
  431. if (AINameIndexDic.ContainsKey("r_PUMP2_FLOW")) AIShorts[AINameIndexDic["r_PUMP2_FLOW"]] = 3277;
  432. if (AINameIndexDic.ContainsKey("r_PUMP1_FLOW")) AIShorts[AINameIndexDic["r_PUMP1_FLOW"]] = 3277;
  433. //Facility
  434. if (AINameIndexDic.ContainsKey("r_DI_WATER_PRESSURE")) AIShorts[AINameIndexDic["r_DI_WATER_PRESSURE"]] = 12000;
  435. if (AINameIndexDic.ContainsKey("r_HCW_FLOW")) AIShorts[AINameIndexDic["r_HCW_FLOW"]] = 16300;
  436. if (AINameIndexDic.ContainsKey("r_N2_1B_PRESSURE")) AIShorts[AINameIndexDic["r_N2_1B_PRESSURE"]] = 5400;
  437. if (AINameIndexDic.ContainsKey("r_N2_1A_PRESSURE")) AIShorts[AINameIndexDic["r_N2_1A_PRESSURE"]] = 8900;
  438. if (AINameIndexDic.ContainsKey("r_N2_2B_PRESSURE")) AIShorts[AINameIndexDic["r_N2_2B_PRESSURE"]] = 5400;
  439. if (AINameIndexDic.ContainsKey("r_N2_2A_PRESSURE")) AIShorts[AINameIndexDic["r_N2_2A_PRESSURE"]] = 5400;
  440. if (AINameIndexDic.ContainsKey("r_SYSTEM_VACUUM")) AIShorts[AINameIndexDic["r_SYSTEM_VACUUM"]] = 3276;
  441. if (AINameIndexDic.ContainsKey("r_CDA_HIGH_PRESSURE")) AIShorts[AINameIndexDic["r_CDA_HIGH_PRESSURE"]] = 10000;
  442. if (AINameIndexDic.ContainsKey("r_CDA_LOW_PRESSURE")) AIShorts[AINameIndexDic["r_CDA_LOW_PRESSURE"]] = 10000;
  443. if (AINameIndexDic.ContainsKey("r_CDA_EXTERNAL_PRESSURE")) AIShorts[AINameIndexDic["r_CDA_EXTERNAL_PRESSURE"]] = 10000;
  444. if (AINameIndexDic.ContainsKey("r_pH3")) AIShorts[AINameIndexDic["r_pH3"]] = 15000;
  445. if (AINameIndexDic.ContainsKey("r_MBS3_FLOW")) AIShorts[AINameIndexDic["r_MBS3_FLOW"]] = 16000;
  446. }
  447. #region 公共方法
  448. public void UpdataDOBytes(string name,int value)
  449. {
  450. if (OnDOVariableValueChanged != null)
  451. {
  452. OnDOVariableValueChanged(name);
  453. }
  454. if (DONameIndexDic.ContainsKey(name))
  455. {
  456. if (DONameIndexDic[name] < DOBytes.Length)
  457. {
  458. DOBytes[DONameIndexDic[name]] = value == 0 ? (byte)0 : (byte)1;
  459. }
  460. }
  461. }
  462. public void UpdataDIBytes(string name, int value)
  463. {
  464. if (OnDIVariableValueChanged != null)
  465. {
  466. OnDIVariableValueChanged(name);
  467. }
  468. if (DINameIndexDic.ContainsKey(name))
  469. {
  470. if (DINameIndexDic[name] < DIBytes.Length)
  471. {
  472. DIBytes[DINameIndexDic[name]] = value == 0 ? (byte)0 : (byte)1;
  473. }
  474. }
  475. }
  476. public void UpdataAOShorts(string name, int value)
  477. {
  478. if (OnAOVariableValueChanged != null)
  479. {
  480. OnAOVariableValueChanged(name);
  481. }
  482. if (AONameIndexDic.ContainsKey(name))
  483. {
  484. string hexValue = value.ToString("X2");
  485. try
  486. {
  487. short result = Convert.ToInt16(hexValue, 16);
  488. if (AONameIndexDic[name] < AOShorts.Length)
  489. {
  490. AOShorts[AONameIndexDic[name]] = result;
  491. }
  492. }
  493. catch (FormatException)
  494. {
  495. }
  496. }
  497. }
  498. public void UpdataAIShorts(string name, int value)
  499. {
  500. if (OnAIVariableValueChanged != null)
  501. {
  502. OnAIVariableValueChanged(name);
  503. }
  504. if (AINameIndexDic.ContainsKey(name))
  505. {
  506. string hexValue = value.ToString("X2");
  507. try
  508. {
  509. short result = Convert.ToInt16(hexValue, 16);
  510. if(AINameIndexDic[name] < AIShorts.Length)
  511. {
  512. AIShorts[AINameIndexDic[name]] = result;
  513. }
  514. }
  515. catch (FormatException)
  516. {
  517. }
  518. }
  519. }
  520. #endregion
  521. #region 功能方法
  522. /// <summary>
  523. /// 将长度为8的二进制byte数组转成对应十六进制byte值(大端模式)
  524. /// </summary>
  525. /// <param name="byteArray"></param>
  526. /// <returns></returns>
  527. public byte ConvertByteArrayToHex(byte[] byteArray)
  528. {
  529. byte result = 0;
  530. // 先将 byte 数组转换为二进制数
  531. int binaryValue = 0;
  532. for (int i = 0; i < 8; i++)
  533. {
  534. binaryValue |= (byteArray[i] << (7 - i));
  535. }
  536. // 逆转二进制数
  537. int reversedValue = 0;
  538. for (int i = 0; i < 8; i++)
  539. {
  540. reversedValue |= ((binaryValue >> i) & 1) << (7 - i);
  541. }
  542. // 转换为十六进制byte
  543. if (byte.TryParse(reversedValue.ToString("X2"), System.Globalization.NumberStyles.HexNumber, null, out result))
  544. {
  545. return result;
  546. }
  547. return 0;
  548. }
  549. /// <summary>
  550. /// 将short数组转成长度两倍的byte数组
  551. /// </summary>
  552. /// <param name="shortArray"></param>
  553. /// <returns></returns>
  554. private byte[] ConvertShortArrayToByteArray(short[] shortArray)
  555. {
  556. byte[] byteArray = new byte[shortArray.Length * 2];
  557. for (int i = 0; i < shortArray.Length; i++)
  558. {
  559. byte[] tempBytes = BitConverter.GetBytes(shortArray[i]);
  560. Array.Reverse(tempBytes);
  561. Array.Copy(tempBytes, 0, byteArray, i * 2, 2);
  562. }
  563. return byteArray;
  564. }
  565. #endregion
  566. protected override void ProcessUnsplitMessage(byte[] data)
  567. {
  568. byte command = data[7];
  569. if (command == 0x01) //读DO
  570. {
  571. short flag = byteTransform.TransInt16(data, 0);
  572. byte channel = data[6];
  573. short startAddress = byteTransform.TransInt16(data, 8);
  574. short bitCount = byteTransform.TransInt16(data, 10);
  575. byte byteCount = (byte)(bitCount / 8 + 1);
  576. byte[] bytes = new byte[byteCount];
  577. for(int i = 0; i < byteCount;i++)
  578. {
  579. byte[] tempbytes = new byte[8];
  580. Array.Copy(DOBytes,8 * i, tempbytes, 0, 8);
  581. bytes[i] = ConvertByteArrayToHex(tempbytes);
  582. }
  583. OnWriteMessage(CreateReadDigitalResponse(flag, channel, command, byteCount, bytes));
  584. return;
  585. }
  586. else if(command == 0x03)//读AO
  587. {
  588. short flag = byteTransform.TransInt16(data, 0);
  589. byte channel = data[6];
  590. short startAddress = byteTransform.TransInt16(data, 8);
  591. short registerCount = byteTransform.TransInt16(data, 10);
  592. short[] shorts = new short[registerCount];//获取指定寄存器里的内容
  593. Array.Copy(AOShorts, 0, shorts, 0, registerCount);
  594. byte[] bytes = new byte[registerCount * 2];
  595. bytes = ConvertShortArrayToByteArray(shorts); //转入长度为shorts数组长度两倍的bytes数组中
  596. OnWriteMessage(CreateReadAnalogyResponse(flag, channel, command, (byte)registerCount, bytes));
  597. return;
  598. }
  599. else if (command == 0x02)//读DI
  600. {
  601. short flag = byteTransform.TransInt16(data, 0);
  602. byte channel = data[6];
  603. short startAddress = byteTransform.TransInt16(data, 8);
  604. short bitCount = byteTransform.TransInt16(data, 10);
  605. byte byteCount = (byte)(bitCount / 8 + 1);
  606. byte[] bytes = new byte[byteCount];
  607. for (int i = 0; i < byteCount; i++)
  608. {
  609. byte[] tempbytes = new byte[8];
  610. Array.Copy(DIBytes, 8 * i, tempbytes, 0, 8);
  611. bytes[i] = ConvertByteArrayToHex(tempbytes);
  612. }
  613. OnWriteMessage(CreateReadDigitalResponse(flag, channel, command, byteCount, bytes));
  614. return;
  615. }
  616. else if (command == 0x04)//读AI
  617. {
  618. short flag = byteTransform.TransInt16(data, 0);
  619. byte channel = data[6];
  620. short startAddress = byteTransform.TransInt16(data, 8);
  621. short registerCount = byteTransform.TransInt16(data, 10);
  622. short[] shorts = new short[registerCount];//获取指定寄存器里的内容
  623. Array.Copy(AIShorts, 0, shorts, 0, registerCount);
  624. byte[] bytes = new byte[registerCount * 2];
  625. bytes = ConvertShortArrayToByteArray(shorts); //转入长度为shorts数组两倍的bytes数组中
  626. OnWriteMessage(CreateReadAnalogyResponse(flag, channel, command, (byte)registerCount, bytes));
  627. return;
  628. }
  629. else if (command == 0x05)//写DO
  630. {
  631. short startAddress = byteTransform.TransInt16(data, 8);
  632. if (startAddress > 0x03FF || startAddress < WRITE_DO_STARTADDRESS)
  633. {
  634. short flag = byteTransform.TransInt16(data, 0);
  635. byte channel = data[6];
  636. OnWriteMessage(CreateError(flag, channel, command, 0x02)); //地址错误
  637. return;
  638. }
  639. int position = startAddress - WRITE_DO_STARTADDRESS;
  640. bool status = data[10] == 0xFF ? true : false;
  641. lock (_writeDOLocker)
  642. {
  643. DOBytes[position] = status ? (byte)1 : (byte)0;
  644. }
  645. OnWriteMessage(data); //原消息返回
  646. //触发Wago对应数据更新
  647. UpdateDataCausedByWago(position, status);
  648. return;
  649. }
  650. else if (command == 0x06)//写AO
  651. {
  652. short startAddress = byteTransform.TransInt16(data, 8);
  653. if(startAddress > 0x02FF || startAddress < WRITE_AO_STARTADDRESS)
  654. {
  655. short flag = byteTransform.TransInt16(data, 0);
  656. byte channel = data[6];
  657. OnWriteMessage(CreateError(flag, channel, command, 0x02)); //地址错误
  658. return;
  659. }
  660. int position = startAddress - WRITE_AO_STARTADDRESS;
  661. short value = byteTransform.TransInt16(data, 10);
  662. lock (_writeAOLocker)
  663. {
  664. AOShorts[position] = value;
  665. }
  666. OnWriteMessage(data); //原消息返回
  667. return;
  668. }
  669. else
  670. {
  671. short flag = byteTransform.TransInt16(data, 0);
  672. byte channel = data[6];
  673. OnWriteMessage(CreateError(flag, channel, command, 0x01)); //指令错误
  674. return;
  675. }
  676. }
  677. /// <summary>
  678. /// 回复读数字量
  679. /// </summary>
  680. /// <param name="flag"></param>
  681. /// <param name="channel"></param>
  682. /// <param name="command"></param>
  683. /// <param name="byteCount"></param>
  684. /// <param name="values"></param>
  685. /// <returns></returns>
  686. private byte[] CreateReadDigitalResponse(short flag, byte channel, byte command, byte byteCount, byte[] values)
  687. {
  688. byte[] bytes = new byte[7 + 2 + values.Length]; //回复字节长度,前面7个字节固定长度 + functionCode一个字节 + byteCount一个字节+values.length个字节
  689. Array.Copy(byteTransform.GetBytes(flag), 0, bytes, 0, 2);
  690. bytes[2] = 0x00;
  691. bytes[3] = 0x00;
  692. short dataLength = (short)(3 + values.Length);
  693. Array.Copy(byteTransform.GetBytes(dataLength), 0, bytes, 4, 2);
  694. bytes[6] = channel;
  695. bytes[7] = command;
  696. bytes[8] = byteCount;
  697. Array.Copy(values, 0, bytes, 9, values.Length);
  698. return bytes;
  699. }
  700. /// <summary>
  701. /// 回复读模拟量
  702. /// </summary>
  703. /// <param name="flag"></param>
  704. /// <param name="channel"></param>
  705. /// <param name="command"></param>
  706. /// <param name="registerCount"></param>
  707. /// <param name="values"></param>
  708. /// <returns></returns>
  709. private byte[] CreateReadAnalogyResponse(short flag, byte channel, byte command, byte registerCount, byte[] values)
  710. {
  711. byte[] bytes = new byte[7 + 2 + 2 * registerCount]; //回复字节长度,前面7个字节固定长度 + functionCode一个字节 + byteCount一个字节+registerCount*2个字节(一个寄存器占两个字节)
  712. Array.Copy(byteTransform.GetBytes(flag), 0, bytes, 0, 2);
  713. bytes[2] = 0x00;
  714. bytes[3] = 0x00;
  715. short dataLength = (short)(3 + 2 * registerCount);
  716. Array.Copy(byteTransform.GetBytes(dataLength), 0, bytes, 4, 2);
  717. bytes[6] = channel;
  718. bytes[7] = command;
  719. bytes[8] = (byte)(2 * registerCount);
  720. Array.Copy(values, 0, bytes, 9, values.Length);
  721. return bytes;
  722. }
  723. /// <summary>
  724. /// 错误回复
  725. /// </summary>
  726. /// <param name="flag"></param>
  727. /// <param name="channel"></param>
  728. /// <param name="command"></param>
  729. /// <param name="error"></param>
  730. /// <returns></returns>
  731. private byte[] CreateError(short flag, byte channel, byte command, byte error)
  732. {
  733. byte[] bytes = new byte[9];
  734. Array.Copy(byteTransform.GetBytes(flag), 0, bytes, 0, 2);
  735. bytes[2] = 0x00;
  736. bytes[3] = 0x00;
  737. bytes[4] = 0x00;
  738. bytes[5] = 0x03;
  739. bytes[6] = channel;
  740. bytes[7] = (byte)(command | 0x80);
  741. bytes[8] = error;
  742. return bytes;
  743. }
  744. /// <summary>
  745. /// loader 定时器
  746. /// </summary>
  747. /// <returns></returns>
  748. private bool OnTimer()
  749. {
  750. LeakTestSimulator();
  751. return true;
  752. }
  753. /// <summary>
  754. /// Wago2定时器
  755. /// </summary>
  756. /// <returns></returns>
  757. private bool OnTimer1()
  758. {
  759. RinseWaterLevelSimulator();
  760. PumpFlowSimulator();
  761. return true;
  762. }
  763. /// <summary>
  764. /// Wago4定时器
  765. /// </summary>
  766. /// <returns></returns>
  767. private bool OnTimer3()
  768. {
  769. Pump1FlowSimulator();
  770. return true;
  771. }
  772. #region 模拟方法
  773. /// <summary>
  774. /// Loader LeakTest模拟
  775. /// </summary>
  776. private void LeakTestSimulator()
  777. {
  778. if (DOBytes[DONameIndexDic["c_VACUUM_TEST"]] == 1 && _festoDataBuffer["FlowTestClamp"] && AIShorts[AINameIndexDic["r_LOADER_GasFlowSensor_FLOW"]] == 0)
  779. {
  780. AIShorts[AINameIndexDic["r_LOADER_GasFlowSensor_FLOW"]] = 15000;
  781. }
  782. else if (DOBytes[DONameIndexDic["c_VACUUM_TEST"]] == 0 && !_festoDataBuffer["FlowTestClamp"])
  783. {
  784. AIShorts[AINameIndexDic["r_LOADER_GasFlowSensor_FLOW"]] = 0;
  785. }
  786. if (DOBytes[DONameIndexDic["c_VACUUM_TEST"]] == 1 && _festoDataBuffer["FlowTestClamp"] && AIShorts[AINameIndexDic["r_LOADER_GasFlowSensor_FLOW"]] > 3500)
  787. {
  788. AIShorts[AINameIndexDic["r_LOADER_GasFlowSensor_FLOW"]] -= 40;
  789. if (AIShorts[AINameIndexDic["r_LOADER_GasFlowSensor_FLOW"]] < 14000)
  790. {
  791. AIShorts[AINameIndexDic["r_LOADER_GasFlowSensor_FLOW"]] -= 140;
  792. }
  793. }
  794. }
  795. /// <summary>
  796. /// QDR水位模拟
  797. /// </summary>
  798. private void RinseWaterLevelSimulator()
  799. {
  800. //QDR1
  801. if (_rinse1FillValve && AIShorts[AINameIndexDic["r_QDRD1_WATER_LEVEL"]] < 25000)
  802. {
  803. AIShorts[AINameIndexDic["r_QDRD1_WATER_LEVEL"]] += 250;
  804. }
  805. if (_rinse1DumpValve && AIShorts[AINameIndexDic["r_QDRD1_WATER_LEVEL"]] > 3500) //快排
  806. {
  807. AIShorts[AINameIndexDic["r_QDRD1_WATER_LEVEL"]] -= 350;
  808. }
  809. if (AIShorts[AINameIndexDic["r_QDRD1_WATER_LEVEL"]] > 3500)//慢排
  810. {
  811. AIShorts[AINameIndexDic["r_QDRD1_WATER_LEVEL"]] -= 2;
  812. }
  813. //QDR2
  814. if (_rinse2FillValve && AIShorts[AINameIndexDic["r_QDRD2_WATER_LEVEL"]] < 25000)
  815. {
  816. AIShorts[AINameIndexDic["r_QDRD2_WATER_LEVEL"]] += 250;
  817. }
  818. if (_rinse2DumpValve && AIShorts[AINameIndexDic["r_QDRD2_WATER_LEVEL"]] > 3500)
  819. {
  820. AIShorts[AINameIndexDic["r_QDRD2_WATER_LEVEL"]] -= 300;
  821. }
  822. if (AIShorts[AINameIndexDic["r_QDRD2_WATER_LEVEL"]] > 3500)//慢排
  823. {
  824. AIShorts[AINameIndexDic["r_QDRD2_WATER_LEVEL"]] -= 2;
  825. }
  826. //QDR3
  827. if (_rinse3FillValve && AIShorts[AINameIndexDic["r_QDRD3_WATER_LEVEL"]] < 25000)
  828. {
  829. AIShorts[AINameIndexDic["r_QDRD3_WATER_LEVEL"]] += 250;
  830. }
  831. if (_rinse3DumpValve && AIShorts[AINameIndexDic["r_QDRD3_WATER_LEVEL"]] > 3500)
  832. {
  833. AIShorts[AINameIndexDic["r_QDRD3_WATER_LEVEL"]] -= 300;
  834. }
  835. if (AIShorts[AINameIndexDic["r_QDRD3_WATER_LEVEL"]] > 3500)//慢排
  836. {
  837. AIShorts[AINameIndexDic["r_QDRD3_WATER_LEVEL"]] -= 2;
  838. }
  839. //QDR4
  840. if (_rinse4FillValve && AIShorts[AINameIndexDic["r_QDRD4_WATER_LEVEL"]] < 25000)
  841. {
  842. AIShorts[AINameIndexDic["r_QDRD4_WATER_LEVEL"]] += 250;
  843. }
  844. if (_rinse4DumpValve && AIShorts[AINameIndexDic["r_QDRD4_WATER_LEVEL"]] > 3500)
  845. {
  846. AIShorts[AINameIndexDic["r_QDRD4_WATER_LEVEL"]] -= 300;
  847. }
  848. if (AIShorts[AINameIndexDic["r_QDRD4_WATER_LEVEL"]] > 3500)//慢排
  849. {
  850. AIShorts[AINameIndexDic["r_QDRD4_WATER_LEVEL"]] -= 2;
  851. }
  852. //reservoir1 pump flow
  853. AIShorts[AINameIndexDic["r_PUMP1_FLOW"]] = _reservoir1PumpOn ? (short)6000 : (short)3277;
  854. }
  855. /// <summary>
  856. /// metal 2/3/4 pump流量模拟
  857. /// </summary>
  858. private void PumpFlowSimulator()
  859. {
  860. if (DOBytes[DONameIndexDic["c_METAL3_PUMP_ON"]] == 1)
  861. {
  862. AIShorts[AINameIndexDic["r_PUMP3_FLOW"]] = 6000;
  863. }
  864. else
  865. {
  866. AIShorts[AINameIndexDic["r_PUMP3_FLOW"]] = 3277;
  867. }
  868. if (DOBytes[DONameIndexDic["c_METAL2_PUMP_ON"]] == 1)
  869. {
  870. AIShorts[AINameIndexDic["r_PUMP2_FLOW"]] = 6000;
  871. }
  872. else
  873. {
  874. AIShorts[AINameIndexDic["r_PUMP2_FLOW"]] = 3277;
  875. }
  876. if (DOBytes[DONameIndexDic["c_METAL4_PUMP_ON"]] == 1)
  877. {
  878. AIShorts[AINameIndexDic["r_PUMP4_FLOW"]] = 6000;
  879. }
  880. else
  881. {
  882. AIShorts[AINameIndexDic["r_PUMP4_FLOW"]] = 3277;
  883. }
  884. }
  885. /// <summary>
  886. /// metal1 pump流量模拟
  887. /// </summary>
  888. private void Pump1FlowSimulator()
  889. {
  890. if (DONameIndexDic.ContainsKey("c_METAL1_PUMP_ON") && DOBytes[DONameIndexDic["c_METAL1_PUMP_ON"]] == 1)
  891. {
  892. SimulatorCommManager.Instance.CheckDataChanged("c_METAL1_PUMP_ON",true,false);
  893. }
  894. else if (DONameIndexDic.ContainsKey("c_METAL1_PUMP_ON") && DOBytes[DONameIndexDic["c_METAL1_PUMP_ON"]] == 0)
  895. {
  896. SimulatorCommManager.Instance.CheckDataChanged("c_METAL1_PUMP_ON", false, false);
  897. }
  898. }
  899. #endregion
  900. }
  901. }