ReadPLCHelp.cs 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069
  1. using Sunny.UI;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Concurrent;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. namespace HRT_Measure
  12. {
  13. public class ReadPLCHelp
  14. {
  15. public static WindowDisplay EnumWindowDisplay = WindowDisplay.主界面;
  16. public static Dictionary<string ,string> dictM01 = new Dictionary<string ,string>();
  17. public static Dictionary<string, string> dictM02 = new Dictionary<string, string>();
  18. public static Dictionary<string, string> dictM04 = new Dictionary<string, string>();
  19. public static Thread thReadPLCM01M02 = new Thread(new ThreadStart(ThReadPLCM01M02));
  20. public static Thread thReadPLCM03 = new Thread(new ThreadStart(ThReadPLCM03));
  21. public static Thread thReadPLCM04M05 = new Thread(new ThreadStart(ThReadPLCM04M05));
  22. public static Thread thPressure = new Thread(new ThreadStart(ThPressure));
  23. public static int iM01M02IOStation = 0;
  24. public static int iM03IOStation = 0;
  25. public static int iM04M05IOStation = 0;
  26. public static int iM01M02AxisStation = 0;
  27. public static int iM03AxisStation = 0;
  28. public static int iM04M05AxisStation = 0;
  29. //public static bool isM01M02Show = false;
  30. //public static bool isM03Show = false;
  31. //public static bool isM04M05Show = false;
  32. //public static bool isWeightShow = false;
  33. //压机
  34. public static List<string> listPressureStr = new List<string>();
  35. public static Dictionary<string, ClsPressure> dictPressure = new Dictionary<string, ClsPressure>();
  36. public static string str主缸当前位置 = "";
  37. public static string str主缸当前压力 = "";
  38. //public static bool is记录保压数据 = false;
  39. public static ConcurrentQueue<short> queuePressureSignals = new ConcurrentQueue<short>();
  40. public static UpTrigger upTrigger = new UpTrigger();
  41. //称重
  42. public static string strWeightStartAdd = "DB136.502.4";//称重开始信号
  43. //public static bool isWeightStart = false;
  44. public static string[] arrWeightStartSignalsAdd = new string[10] { "DB31.0", "DB31.2", "DB31.4", "DB31.6", "DB31.8", "DB31.10", "DB31.12", "DB31.14", "DB31.16", "DB31.18" };
  45. public static short[] arrShortWeightStart = new short[10] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  46. public static string[] arrWeightDoneAdd = new string[10] { "DB31.20", "DB31.24", "DB31.28", "DB31.32", "DB31.36", "DB31.40", "DB31.44", "DB31.48", "DB31.52", "DB31.56" };
  47. public static string[] arrWeightDoneStatus = new string[10] { "DB31.60", "DB31.62", "DB31.64", "DB31.66", "DB31.68", "DB31.70", "DB31.72", "DB31.74", "DB31.76", "DB31.78" };
  48. //public static int[] arrWeightValue = new int[10] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  49. public static void GetPressureInfo()
  50. {
  51. listPressureStr.Clear();
  52. #region MyRegion
  53. listPressureStr.Add("主缸位置,D5,short,0.1");
  54. listPressureStr.Add("位置修正值,D235,short,0.1");
  55. listPressureStr.Add("主缸压力,D4,short,0.1");
  56. //listPressureStr.Add("位置应用值,D5,short");
  57. listPressureStr.Add("当前动作,D10,short,1");
  58. listPressureStr.Add("动作提示,D11,short,1");
  59. listPressureStr.Add("设定1压力,D12,short,0.1");
  60. listPressureStr.Add("设定1流量,D13,short,1");
  61. listPressureStr.Add("顶缸位移,D106,short,0.1");
  62. listPressureStr.Add("主缸速度,D125,short,0.1");
  63. listPressureStr.Add("顶缸速度,D127,short,0.1");
  64. listPressureStr.Add("设定1压力模拟量,D130,short,1");
  65. listPressureStr.Add("设定1流量模拟量,D134,short,1");
  66. listPressureStr.Add("保压倒计时,D180,short,1");
  67. listPressureStr.Add("泄压倒计时,D185,short,1");
  68. listPressureStr.Add("主缸压力设定,D200,short,0.1");
  69. listPressureStr.Add("泄压延时设置,D202,short,0.1");
  70. listPressureStr.Add("保压延时设定,D203,short,0.1");
  71. listPressureStr.Add("顶出停止位置设定,D206,short,0.1");
  72. listPressureStr.Add("快退减速位置设定,D207,short,0.1");
  73. listPressureStr.Add("慢速顶出位置设定,D209,short,0.1");
  74. listPressureStr.Add("快速退回位置设定,D210,short,0.1");
  75. listPressureStr.Add("退回停止位置设定,D211,short,0.1");
  76. listPressureStr.Add("快上压力,D220,short,0.1");
  77. listPressureStr.Add("快上流量,D221,short,1");
  78. listPressureStr.Add("慢上压力,D222,short,0.1");
  79. listPressureStr.Add("慢上流量,D223,short,1");
  80. listPressureStr.Add("减退压力,D224,short,0.1");
  81. listPressureStr.Add("减退流量,D225,short,1");
  82. listPressureStr.Add("慢退压力,D226,short,0.1");
  83. listPressureStr.Add("慢退流量,D227,short,1");
  84. listPressureStr.Add("快退压力,D228,short,0.1");
  85. listPressureStr.Add("快退流量,D229,short,1");
  86. //listPressureStr.Add("位置修正值,D235,short,0.1");
  87. listPressureStr.Add("位置应用值,D245,short,0.1");
  88. listPressureStr.Add("工件计数,D400,short,1");
  89. listPressureStr.Add("设定计数,D401,short,1");
  90. listPressureStr.Add("第一次压力,D284,short,0.1");
  91. listPressureStr.Add("第二次压力,D262,short,0.1");
  92. listPressureStr.Add("第三次压力,D264,short,0.1");
  93. listPressureStr.Add("第一次保压时间,D266,short,0.1");
  94. listPressureStr.Add("第二次保压时间,D268,short,0.1");
  95. listPressureStr.Add("第三次保压时间,D270,short,0.1");
  96. listPressureStr.Add("第一次顶出停止位置,D272,short,0.1");
  97. listPressureStr.Add("第二次顶出停止位置,D274,short,0.1");
  98. listPressureStr.Add("第三次顶出停止位置,D276,short,0.1");
  99. listPressureStr.Add("第一次顶出减速位置,D278,short,0.1");
  100. listPressureStr.Add("第二次顶出减速位置,D280,short,0.1");
  101. listPressureStr.Add("第三次顶出减速位置,D282,short,0.1");
  102. #endregion
  103. dictPressure.Clear();
  104. for (int i = 0; i < listPressureStr.Count; i++)
  105. {
  106. ClsPressure clsPressure = new ClsPressure(listPressureStr[i]);
  107. dictPressure.Add(clsPressure.Name, clsPressure);
  108. }
  109. queuePressureSignals.Clear();
  110. }
  111. public static void LoadPLCAdd()
  112. {
  113. dictM01.Clear();
  114. dictM02.Clear();
  115. dictM04.Clear();
  116. dictPressure.Clear();
  117. #region M01M02M04M05
  118. //M01
  119. dictM01.Add("药A暂存当前盒数", "DB20.476");
  120. dictM01.Add("药B暂存当前盒数", "DB20.478");
  121. dictM01.Add("抛盖暂存槽当前数量", "DB20.492");
  122. dictM01.Add("空桶暂存槽当前数量", "DB20.490");
  123. //M02
  124. dictM02.Add("药A称重配比重量", "DB14.20");
  125. dictM02.Add("A料仓1当前重量", "DB20.76");
  126. dictM02.Add("A料仓2当前重量", "DB20.80");
  127. dictM02.Add("A料仓3当前重量", "DB20.84");
  128. dictM02.Add("A料仓4当前重量", "DB20.88");
  129. dictM02.Add("A料仓5当前重量", "DB20.92");
  130. dictM02.Add("药B称重配比重量", "DB14.24");
  131. dictM02.Add("B料仓1当前重量", "DB20.96");
  132. dictM02.Add("B料仓2当前重量", "DB20.100");
  133. dictM02.Add("B料仓3当前重量", "DB20.104");
  134. dictM02.Add("B料仓4当前重量", "DB20.108");
  135. dictM02.Add("B料仓5当前重量", "DB20.112");
  136. //M04
  137. dictM04.Add("允许下料", "DB186.26.0");
  138. dictM04.Add("当前检测高度", "DB31.50");
  139. dictM04.Add("当前重量", "DB31.8");
  140. dictM04.Add("产品高度", "DB80.0");
  141. dictM04.Add("产品重量", "DB80.4");
  142. dictM04.Add("相机结果", "DB80.8");
  143. dictM04.Add("废料数量", "DB80.12");
  144. dictM04.Add("合格数量", "DB80.16");
  145. dictM04.Add("盘数", "DB80.20");
  146. dictM04.Add("NG数量", "DB80.22");
  147. dictM04.Add("本次完成箱子数量", "DB80.26");
  148. dictM04.Add("产品信息打包上传", "DB80.40.0");
  149. #endregion
  150. GetPressureInfo();
  151. thReadPLCM01M02.IsBackground = true;
  152. thReadPLCM01M02.Start();
  153. thReadPLCM03.IsBackground = true;
  154. thReadPLCM03.Start();
  155. thReadPLCM04M05.IsBackground = true;
  156. thReadPLCM04M05.Start();
  157. thPressure.IsBackground = true;
  158. thPressure.Start();
  159. }
  160. #region GetValue
  161. #region M01M02
  162. public static void GetM01M02InitValue(PLCInitIO plcInitIO, CommPLC commPLC)
  163. {
  164. try
  165. {
  166. plcInitIO.isHandOrAuto = plcInitIO.HandOrAutoAdd != "" ? GetM01M02BoolValue(plcInitIO.HandOrAutoAdd, commPLC) : false;
  167. plcInitIO.isInitDone = plcInitIO.InitDoneAdd != "" ? GetM01M02BoolValue(plcInitIO.InitDoneAdd, commPLC) : false;
  168. plcInitIO.isAutoRunning = plcInitIO.AutoRunningAdd != "" ? GetM01M02BoolValue(plcInitIO.AutoRunningAdd, commPLC) : false;
  169. plcInitIO.isAlm = plcInitIO.AlmAdd != "" ? GetM01M02BoolValue(plcInitIO.AlmAdd, commPLC) : false;
  170. plcInitIO.isWait = plcInitIO.WaitAdd != "" ? GetM01M02BoolValue(plcInitIO.WaitAdd, commPLC) : false;
  171. plcInitIO.isBtnInit = plcInitIO.btnInitAdd != "" ? GetM01M02BoolValue(plcInitIO.btnInitAdd, commPLC) : false;
  172. plcInitIO.isBtnExceptionQuit = plcInitIO.btnExcetionQuitAdd != "" ? GetM01M02BoolValue(plcInitIO.btnExcetionQuitAdd, commPLC) : false;
  173. plcInitIO.isBtnStop = plcInitIO.btnStopAdd != "" ? GetM01M02BoolValue(plcInitIO.btnStopAdd, commPLC) : false;
  174. plcInitIO.isBtnStart = plcInitIO.btnStartAdd != "" ? GetM01M02BoolValue(plcInitIO.btnStartAdd, commPLC) : false;
  175. plcInitIO.isBtnHandOrAuto = plcInitIO.btnHandOrAutoAdd != "" ? GetM01M02BoolValue(plcInitIO.btnHandOrAutoAdd, commPLC) : false;
  176. }
  177. catch (Exception )
  178. {
  179. //MessageBox.Show(ex.ToString());
  180. }
  181. }
  182. public static void GetM01M02AlmValue(Dictionary <string,ClsAlm> dictAlm, CommPLC commPLC)
  183. {
  184. foreach (var item in dictAlm)
  185. {
  186. try
  187. {
  188. item.Value.isAlm = item.Value.AlmAdd != "" ? GetM01M02BoolValue(item.Value.AlmAdd, commPLC) : false;
  189. }
  190. catch (Exception )
  191. {
  192. //MessageBox.Show(ex.ToString());
  193. }
  194. }
  195. }
  196. public static void GetM01M02CylinderValue(Dictionary<string,ClsPLCIO> dictIO, CommPLC commPLC)
  197. {
  198. foreach (var item in dictIO)
  199. {
  200. try
  201. {
  202. item.Value.isLedResetOn = item.Value.LedResetAdd != "" ? GetM01M02BoolValue(item.Value.LedResetAdd, commPLC) : false ;
  203. item.Value.isLedSetOn = item.Value.LedSetAdd != "" ? GetM01M02BoolValue(item.Value.LedSetAdd, commPLC): false;
  204. item.Value.isSensorResetOn = item.Value.SensorResetAdd != "" ? GetM01M02BoolValue(item.Value.SensorResetAdd, commPLC): false;
  205. item.Value.isSensorSetOn = item.Value.SensorSetAdd != "" ? GetM01M02BoolValue(item.Value.SensorSetAdd, commPLC): false;
  206. item.Value.isResetEnableOn = item.Value.ResetEnableAdd != "" ? GetM01M02BoolValue(item.Value.ResetEnableAdd, commPLC): false;
  207. item.Value.isSetEnableOn = item.Value.SetEnableAdd != "" ? GetM01M02BoolValue(item.Value.SetEnableAdd, commPLC): false;
  208. }
  209. catch (Exception )
  210. {
  211. //MessageBox.Show(ex.ToString());
  212. }
  213. //Thread.Sleep(1);
  214. }
  215. }
  216. public static void GetM01M02AxisPos(Dictionary<string,ClsAxisPos> dictAxisPos,CommPLC commPLC)
  217. {
  218. try
  219. {
  220. foreach (var item in dictAxisPos)
  221. {
  222. item.Value.isLightOn = item.Value.LightAdd != "" ? GetM01M02BoolValue(item.Value.LightAdd, commPLC) : false;
  223. commPLC.ReadUshort(item.Value.GoAdd, out item.Value.GoCurrValue,out string str );
  224. //Thread.Sleep(1);
  225. }
  226. }
  227. catch (Exception )
  228. {
  229. // MessageBox.Show(ex.ToString());
  230. }
  231. }
  232. public static void GetM01M02Axis(ClsAxis dictAxis, CommPLC commPLC)
  233. {
  234. try
  235. {
  236. dictAxis.is使能完成 = dictAxis.使能完成 != "" ? GetM01M02BoolValue(dictAxis.使能完成, commPLC) : false;
  237. dictAxis.is运行允许 = dictAxis.运行允许 != "" ? GetM01M02BoolValue(dictAxis.运行允许, commPLC) : false;
  238. dictAxis.is异常 = dictAxis.异常 != "" ? GetM01M02BoolValue(dictAxis.异常, commPLC) : false;
  239. dictAxis.isPositiveLimitOn = dictAxis.正极限 != "" ? GetM01M02BoolValue(dictAxis.正极限, commPLC) : false;
  240. dictAxis.isOriginalLimitOn = dictAxis.原点 != "" ? GetM01M02BoolValue(dictAxis.原点, commPLC) : false;
  241. dictAxis.isNegativeLimitOn = dictAxis.负极限 != "" ? GetM01M02BoolValue(dictAxis.负极限, commPLC) : false;
  242. dictAxis.is轴使能 = dictAxis.轴使能 != "" ? GetM01M02BoolValue(dictAxis.轴使能, commPLC) : false;
  243. dictAxis.i当前位置 = GetM01M02IntValue(dictAxis.当前位置, commPLC);
  244. dictAxis.s异常代码 = GetM01M02Int16Value(dictAxis.异常代码, commPLC);
  245. dictAxis.i点动速度 = GetM01M02IntValue(dictAxis.点动速度, commPLC);
  246. }
  247. catch (Exception )
  248. {
  249. //MessageBox.Show(ex.ToString());
  250. }
  251. }
  252. #endregion
  253. #region M03
  254. public static void GetM03InitValue(PLCInitIO plcInitIO, CommPLC commPLC)
  255. {
  256. try
  257. {
  258. plcInitIO.isHandOrAuto = plcInitIO.HandOrAutoAdd != "" ? GetM03BoolValue(plcInitIO.HandOrAutoAdd, commPLC) : false;
  259. plcInitIO.isInitDone = plcInitIO.InitDoneAdd != "" ? GetM03BoolValue(plcInitIO.InitDoneAdd, commPLC) : false;
  260. plcInitIO.isAutoRunning = plcInitIO.AutoRunningAdd != "" ? GetM03BoolValue(plcInitIO.AutoRunningAdd, commPLC) : false;
  261. plcInitIO.isAlm = plcInitIO.AlmAdd != "" ? GetM03BoolValue(plcInitIO.AlmAdd, commPLC) : false;
  262. plcInitIO.isWait = plcInitIO.WaitAdd != "" ? GetM03BoolValue(plcInitIO.WaitAdd, commPLC) : false;
  263. plcInitIO.isBtnInit = plcInitIO.btnInitAdd != "" ? GetM03BoolValue(plcInitIO.btnInitAdd, commPLC) : false;
  264. plcInitIO.isBtnExceptionQuit = plcInitIO.btnExcetionQuitAdd != "" ? GetM03BoolValue(plcInitIO.btnExcetionQuitAdd, commPLC) : false;
  265. plcInitIO.isBtnStop = plcInitIO.btnStopAdd != "" ? GetM03BoolValue(plcInitIO.btnStopAdd, commPLC) : false;
  266. plcInitIO.isBtnStart = plcInitIO.btnStartAdd != "" ? GetM03BoolValue(plcInitIO.btnStartAdd, commPLC) : false;
  267. plcInitIO.isBtnHandOrAuto = plcInitIO.btnHandOrAutoAdd != "" ? GetM03BoolValue(plcInitIO.btnHandOrAutoAdd, commPLC) : false;
  268. }
  269. catch (Exception)
  270. {
  271. //MessageBox.Show(ex.ToString());
  272. }
  273. }
  274. public static void GetM03AlmValue(Dictionary<string, ClsAlm> dictAlm, CommPLC commPLC)
  275. {
  276. foreach (var item in dictAlm)
  277. {
  278. try
  279. {
  280. item.Value.isAlm = item.Value.AlmAdd != "" ? GetM03BoolValue(item.Value.AlmAdd, commPLC) : false;
  281. }
  282. catch (Exception )
  283. {
  284. //MessageBox.Show(ex.ToString());
  285. }
  286. }
  287. }
  288. public static void GetM03CylinderValue(Dictionary<string, ClsPLCIO> dictIO, CommPLC commPLC)
  289. {
  290. foreach (var item in dictIO)
  291. {
  292. try
  293. {
  294. item.Value.isLedResetOn = item.Value.LedResetAdd != "" ? GetM03BoolValue(item.Value.LedResetAdd, commPLC) : false;
  295. item.Value.isLedSetOn = item.Value.LedSetAdd != "" ? GetM03BoolValue(item.Value.LedSetAdd, commPLC) : false;
  296. item.Value.isSensorResetOn = item.Value.SensorResetAdd != "" ? GetM03BoolValue(item.Value.SensorResetAdd, commPLC) : false;
  297. item.Value.isSensorSetOn = item.Value.SensorSetAdd != "" ? GetM03BoolValue(item.Value.SensorSetAdd, commPLC) : false;
  298. item.Value.isResetEnableOn = item.Value.ResetEnableAdd != "" ? GetM03BoolValue(item.Value.ResetEnableAdd, commPLC) : false;
  299. item.Value.isSetEnableOn = item.Value.SetEnableAdd != "" ? GetM03BoolValue(item.Value.SetEnableAdd, commPLC) : false;
  300. }
  301. catch (Exception )
  302. {
  303. //MessageBox.Show(ex.ToString());
  304. }
  305. //Thread.Sleep(1);
  306. }
  307. }
  308. public static void GetM03AxisPos(Dictionary<string, ClsAxisPos> dictAxisPos, CommPLC commPLC)
  309. {
  310. try
  311. {
  312. foreach (var item in dictAxisPos)
  313. {
  314. item.Value.isLightOn = item.Value.LightAdd != "" ? GetM03BoolValue(item.Value.LightAdd, commPLC) : false;
  315. commPLC.ReadUshort(item.Value.GoAdd, out item.Value.GoCurrValue, out string str);
  316. Thread.Sleep(1);
  317. }
  318. }
  319. catch (Exception )
  320. {
  321. // MessageBox.Show(ex.ToString());
  322. }
  323. }
  324. public static void GetM03Axis(ClsAxis dictAxis, CommPLC commPLC)
  325. {
  326. try
  327. {
  328. dictAxis.is使能完成 = dictAxis.使能完成 != "" ? GetM03BoolValue(dictAxis.使能完成, commPLC) : false;
  329. dictAxis.is运行允许 = dictAxis.运行允许 != "" ? GetM03BoolValue(dictAxis.运行允许, commPLC) : false;
  330. dictAxis.is异常 = dictAxis.异常 != "" ? GetM03BoolValue(dictAxis.异常, commPLC) : false;
  331. dictAxis.isPositiveLimitOn = dictAxis.正极限 != "" ? GetM03BoolValue(dictAxis.正极限, commPLC) : false;
  332. dictAxis.isOriginalLimitOn = dictAxis.原点 != "" ? GetM03BoolValue(dictAxis.原点, commPLC) : false;
  333. dictAxis.isNegativeLimitOn = dictAxis.负极限 != "" ? GetM03BoolValue(dictAxis.负极限, commPLC) : false;
  334. dictAxis.i当前位置 = GetM03IntValue(dictAxis.当前位置, commPLC);
  335. dictAxis.s异常代码 = GetM03Int16Value(dictAxis.异常代码, commPLC);
  336. dictAxis.i点动速度 = GetM03IntValue(dictAxis.点动速度, commPLC);
  337. }
  338. catch (Exception )
  339. {
  340. //MessageBox.Show(ex.ToString());
  341. }
  342. }
  343. #endregion
  344. #region M04M05
  345. public static void GetM04M05InitValue(PLCInitIO plcInitIO, CommPLC commPLC)
  346. {
  347. try
  348. {
  349. plcInitIO.isHandOrAuto = plcInitIO.HandOrAutoAdd != "" ? GetM04M05BoolValue(plcInitIO.HandOrAutoAdd, commPLC) : false;
  350. plcInitIO.isInitDone = plcInitIO.InitDoneAdd != "" ? GetM04M05BoolValue(plcInitIO.InitDoneAdd, commPLC) : false;
  351. plcInitIO.isAutoRunning = plcInitIO.AutoRunningAdd != "" ? GetM04M05BoolValue(plcInitIO.AutoRunningAdd, commPLC) : false;
  352. plcInitIO.isAlm = plcInitIO.AlmAdd != "" ? GetM04M05BoolValue(plcInitIO.AlmAdd, commPLC) : false;
  353. plcInitIO.isWait = plcInitIO.WaitAdd != "" ? GetM04M05BoolValue(plcInitIO.WaitAdd, commPLC) : false;
  354. plcInitIO.isBtnInit = plcInitIO.btnInitAdd != "" ? GetM04M05BoolValue(plcInitIO.btnInitAdd, commPLC) : false;
  355. plcInitIO.isBtnExceptionQuit = plcInitIO.btnExcetionQuitAdd != "" ? GetM04M05BoolValue(plcInitIO.btnExcetionQuitAdd, commPLC) : false;
  356. plcInitIO.isBtnStop = plcInitIO.btnStopAdd != "" ? GetM04M05BoolValue(plcInitIO.btnStopAdd, commPLC) : false;
  357. plcInitIO.isBtnStart = plcInitIO.btnStartAdd != "" ? GetM04M05BoolValue(plcInitIO.btnStartAdd, commPLC) : false;
  358. plcInitIO.isBtnHandOrAuto = plcInitIO.btnHandOrAutoAdd != "" ? GetM04M05BoolValue(plcInitIO.btnHandOrAutoAdd, commPLC) : false;
  359. }
  360. catch (Exception )
  361. {
  362. //MessageBox.Show(ex.ToString());
  363. }
  364. }
  365. public static void GetM04M05AlmValue(Dictionary<string, ClsAlm> dictAlm, CommPLC commPLC)
  366. {
  367. foreach (var item in dictAlm)
  368. {
  369. try
  370. {
  371. item.Value.isAlm = item.Value.AlmAdd != "" ? GetM04M05BoolValue(item.Value.AlmAdd, commPLC) : false;
  372. }
  373. catch (Exception )
  374. {
  375. // MessageBox.Show(ex.ToString());
  376. }
  377. }
  378. }
  379. public static void GetM04M05CylinderValue(Dictionary<string, ClsPLCIO> dictIO, CommPLC commPLC)
  380. {
  381. foreach (var item in dictIO)
  382. {
  383. try
  384. {
  385. item.Value.isLedResetOn = item.Value.LedResetAdd != "" ? GetM04M05BoolValue(item.Value.LedResetAdd, commPLC) : false;
  386. item.Value.isLedSetOn = item.Value.LedSetAdd != "" ? GetM04M05BoolValue(item.Value.LedSetAdd, commPLC) : false;
  387. item.Value.isSensorResetOn = item.Value.SensorResetAdd != "" ? GetM04M05BoolValue(item.Value.SensorResetAdd, commPLC) : false;
  388. item.Value.isSensorSetOn = item.Value.SensorSetAdd != "" ? GetM04M05BoolValue(item.Value.SensorSetAdd, commPLC) : false;
  389. item.Value.isResetEnableOn = item.Value.ResetEnableAdd != "" ? GetM04M05BoolValue(item.Value.ResetEnableAdd, commPLC) : false;
  390. item.Value.isSetEnableOn = item.Value.SetEnableAdd != "" ? GetM04M05BoolValue(item.Value.SetEnableAdd, commPLC) : false;
  391. }
  392. catch (Exception )
  393. {
  394. //MessageBox.Show(ex.ToString());
  395. }
  396. //Thread.Sleep(1);
  397. }
  398. }
  399. public static void GetM04M05AxisPos(Dictionary<string, ClsAxisPos> dictAxisPos, CommPLC commPLC)
  400. {
  401. try
  402. {
  403. foreach (var item in dictAxisPos)
  404. {
  405. item.Value.isLightOn = item.Value.LightAdd != "" ? GetM04M05BoolValue(item.Value.LightAdd, commPLC) : false;
  406. commPLC.ReadUshort(item.Value.GoAdd, out item.Value.GoCurrValue, out string str);
  407. //Thread.Sleep(1);
  408. }
  409. }
  410. catch (Exception )
  411. {
  412. //MessageBox.Show(ex.ToString());
  413. }
  414. }
  415. public static void GetM04M05Axis(ClsAxis dictAxis, CommPLC commPLC)
  416. {
  417. try
  418. {
  419. dictAxis.is使能完成 = dictAxis.使能完成 != "" ? GetM04M05BoolValue(dictAxis.使能完成, commPLC) : false;
  420. dictAxis.is运行允许 = dictAxis.运行允许 != "" ? GetM04M05BoolValue(dictAxis.运行允许, commPLC) : false;
  421. dictAxis.is异常 = dictAxis.异常 != "" ? GetM04M05BoolValue(dictAxis.异常, commPLC) : false;
  422. dictAxis.isPositiveLimitOn = dictAxis.正极限 != "" ? GetM04M05BoolValue(dictAxis.正极限, commPLC) : false;
  423. dictAxis.isOriginalLimitOn = dictAxis.原点 != "" ? GetM04M05BoolValue(dictAxis.原点, commPLC) : false;
  424. dictAxis.isNegativeLimitOn = dictAxis.负极限 != "" ? GetM04M05BoolValue(dictAxis.负极限, commPLC) : false;
  425. dictAxis.i当前位置 = GetM04M05IntValue(dictAxis.当前位置, commPLC);
  426. dictAxis.s异常代码 = GetM04M05Int16Value(dictAxis.异常代码, commPLC);
  427. dictAxis.i点动速度 = GetM04M05IntValue(dictAxis.点动速度, commPLC);
  428. }
  429. catch (Exception )
  430. {
  431. //MessageBox.Show(ex.ToString());
  432. }
  433. }
  434. #endregion
  435. #endregion
  436. private static void ThReadPLCM01M02()
  437. {
  438. while(true)
  439. {
  440. if(!ProgramHelp.Instance.commPLC_M01M02.isPLCConnected)
  441. {
  442. Thread.Sleep(5);
  443. continue;
  444. }
  445. GetM01M02InitValue(PLCCylinder.dictPLC_InitIO["M01M02"], ProgramHelp.Instance.commPLC_M01M02);
  446. foreach (var itemM01 in dictM01)
  447. {
  448. short sResult = GetM01M02Int16Value(itemM01.Value, ProgramHelp.Instance.commPLC_M01M02);
  449. SetM01Result(sResult, itemM01.Key);
  450. }
  451. //foreach (var itemM02 in dictM02)
  452. //{
  453. // short sResult = GetM01M02Int16Value(itemM02.Value, ProgramHelp.Instance.commPLC_M01M02);
  454. // SetM02Result(sResult, itemM02.Key);
  455. //}
  456. PLCResultHelp.isM01_清料 = GetM01M02BoolValue("DB20.496.0", ProgramHelp.Instance.commPLC_M01M02);
  457. for (int i = 0; i < 10; i++)
  458. {
  459. arrShortWeightStart[i] = GetM01M02Int16Value(arrWeightStartSignalsAdd[i], ProgramHelp.Instance.commPLC_M01M02);
  460. }
  461. PLCResultHelp.isM01_称重开始 = GetM01M02BoolValue(strWeightStartAdd, ProgramHelp.Instance.commPLC_M01M02);
  462. //if (PLCResultHelp.isM01_称重开始)
  463. //{
  464. //}
  465. foreach (var itemM02 in dictM02)
  466. {
  467. int iResult = GetM01M02IntValue(itemM02.Value, ProgramHelp.Instance.commPLC_M01M02);
  468. SetM02Result(iResult, itemM02.Key);
  469. }
  470. GetM01M02AlmValue(PLCCylinder.dictM01M02_Alm, ProgramHelp.Instance.commPLC_M01M02);//
  471. if (EnumWindowDisplay != WindowDisplay.上料称重房)
  472. {
  473. Thread.Sleep(2);
  474. continue;
  475. }
  476. try
  477. {
  478. //ClsWeightHelp.GetWeightValue();//称重房
  479. if (EnumWindowDisplay == WindowDisplay.上料称重房)
  480. {
  481. switch (iM01M02IOStation)
  482. {
  483. case 0:
  484. GetM01M02CylinderValue(PLCCylinder.dictM01M02_上料工位, ProgramHelp.Instance.commPLC_M01M02);
  485. break;
  486. case 1:
  487. GetM01M02CylinderValue(PLCCylinder.dictM01M02_取出工位, ProgramHelp.Instance.commPLC_M01M02);
  488. break;
  489. case 2:
  490. GetM01M02CylinderValue(PLCCylinder.dictM01M02_提升机工位, ProgramHelp.Instance.commPLC_M01M02);
  491. break;
  492. case 3:
  493. GetM01M02CylinderValue(PLCCylinder.dictM01M02_称重工位, ProgramHelp.Instance.commPLC_M01M02);
  494. break;
  495. case 4:
  496. GetM01M02CylinderValue(PLCCylinder.dictM01M02_出口工位, ProgramHelp.Instance.commPLC_M01M02);
  497. break;
  498. }
  499. switch(iM01M02AxisStation)
  500. {
  501. case 0:
  502. GetM01M02AxisPos(PLCAxisPos.dictM01M02_取料X轴, ProgramHelp.Instance.commPLC_M01M02);
  503. GetM01M02Axis(PLCAxis.dictM01M02_轴["取料X轴"], ProgramHelp.Instance.commPLC_M01M02);
  504. break;
  505. case 1:
  506. GetM01M02AxisPos(PLCAxisPos.dictM01M02_取料Y轴, ProgramHelp.Instance.commPLC_M01M02);
  507. GetM01M02Axis(PLCAxis.dictM01M02_轴["取料Y轴"], ProgramHelp.Instance.commPLC_M01M02);
  508. break;
  509. case 2:
  510. GetM01M02AxisPos(PLCAxisPos.dictM01M02_取料Z轴, ProgramHelp.Instance.commPLC_M01M02);
  511. GetM01M02Axis(PLCAxis.dictM01M02_轴["取料Z轴"], ProgramHelp.Instance.commPLC_M01M02);
  512. break;
  513. case 3:
  514. GetM01M02AxisPos(PLCAxisPos.dictM01M02_取料R轴, ProgramHelp.Instance.commPLC_M01M02);
  515. GetM01M02Axis(PLCAxis.dictM01M02_轴["取料R轴"], ProgramHelp.Instance.commPLC_M01M02);
  516. break;
  517. case 4:
  518. GetM01M02AxisPos(PLCAxisPos.dictM01M02_上料站X轴, ProgramHelp.Instance.commPLC_M01M02);
  519. GetM01M02Axis(PLCAxis.dictM01M02_轴["上料站X轴"], ProgramHelp.Instance.commPLC_M01M02);
  520. break;
  521. case 5:
  522. GetM01M02AxisPos(PLCAxisPos.dictM01M02_上料站Y轴, ProgramHelp.Instance.commPLC_M01M02);
  523. GetM01M02Axis(PLCAxis.dictM01M02_轴["上料站Y轴"], ProgramHelp.Instance.commPLC_M01M02);
  524. break;
  525. case 6:
  526. GetM01M02AxisPos(PLCAxisPos.dictM01M02_上料站Z轴, ProgramHelp.Instance.commPLC_M01M02);
  527. GetM01M02Axis(PLCAxis.dictM01M02_轴["上料站Z轴"], ProgramHelp.Instance.commPLC_M01M02);
  528. break;
  529. }
  530. //GetM01M02Axis(PLCAxis.dictM01M02_轴, ProgramHelp.Instance.commPLC_M01M02);
  531. }
  532. }
  533. catch (Exception )
  534. {
  535. //MessageBox.Show(ex.ToString());
  536. }
  537. Thread.Sleep(1);
  538. }
  539. }
  540. private static void ThReadPLCM03()
  541. {
  542. while (true)
  543. {
  544. if (!ProgramHelp.Instance.commPLC_M03.isPLCConnected)
  545. {
  546. Thread.Sleep(5);
  547. continue;
  548. }
  549. GetM03InitValue(PLCCylinder.dictPLC_InitIO["M03"], ProgramHelp.Instance.commPLC_M03);
  550. GetM03AlmValue(PLCCylinder.dictM03_Alm, ProgramHelp.Instance.commPLC_M03);//
  551. if (EnumWindowDisplay != WindowDisplay.压机房)
  552. {
  553. Thread.Sleep(2);
  554. continue;
  555. }
  556. try
  557. {
  558. if (EnumWindowDisplay == WindowDisplay.压机房)
  559. {
  560. switch (iM03IOStation)
  561. {
  562. case 0:
  563. GetM03CylinderValue(PLCCylinder.dictM03_整平工位, ProgramHelp.Instance.commPLC_M03);
  564. break;
  565. case 1:
  566. GetM03CylinderValue(PLCCylinder.dictM03_装冲工位, ProgramHelp.Instance.commPLC_M03);
  567. break;
  568. case 2:
  569. GetM03CylinderValue(PLCCylinder.dictM03_压合工位, ProgramHelp.Instance.commPLC_M03);
  570. break;
  571. case 3:
  572. GetM03CylinderValue(PLCCylinder.dictM03_清洗工位, ProgramHelp.Instance.commPLC_M03);
  573. break;
  574. case 4:
  575. GetM03CylinderValue(PLCCylinder.dictM03_下流线工位, ProgramHelp.Instance.commPLC_M03);
  576. break;
  577. case 5:
  578. GetM03CylinderValue(PLCCylinder.dictM03_出料口工位, ProgramHelp.Instance.commPLC_M03);
  579. break;
  580. }
  581. switch (iM03AxisStation)
  582. {
  583. case 0:
  584. //GetM03AxisPos(PLCAxisPos.dictM03_取料X轴, ProgramHelp.Instance.commPLC_M03);
  585. GetM03Axis(PLCAxis.dictM03_轴["压机流线伺服"], ProgramHelp.Instance.commPLC_M03);
  586. break;
  587. case 1:
  588. //GetM03AxisPos(PLCAxisPos.dictM03_取料Y轴, ProgramHelp.Instance.commPLC_M03);
  589. GetM03Axis(PLCAxis.dictM03_轴["压机前流线伺服"], ProgramHelp.Instance.commPLC_M03);
  590. break;
  591. }
  592. //GetM03Axis(PLCAxis.dictM03_轴, ProgramHelp.Instance.commPLC_M03);
  593. }
  594. }
  595. catch (Exception )
  596. {
  597. //MessageBox.Show(ex.ToString());
  598. }
  599. Thread.Sleep(1);
  600. }
  601. }
  602. private static void ThReadPLCM04M05()
  603. {
  604. while(true)
  605. {
  606. if (!ProgramHelp.Instance.commPLC_M04M05.isPLCConnected)
  607. {
  608. Thread.Sleep(5);
  609. continue;
  610. }
  611. GetM04M05InitValue(PLCCylinder.dictPLC_InitIO["M04M05"], ProgramHelp.Instance.commPLC_M04M05);
  612. foreach (var itemM04 in dictM04)
  613. {
  614. switch (itemM04.Key)
  615. {
  616. case "允许下料":
  617. PLCResultHelp.isM04_允许下料 = GetM04M05BoolValue(itemM04.Value, ProgramHelp.Instance.commPLC_M04M05);
  618. break;
  619. case "当前检测高度":
  620. PLCResultHelp.fM04_当前检测高度 = GetM04M05RealValue(itemM04.Value, ProgramHelp.Instance.commPLC_M04M05);
  621. break;
  622. case "当前重量":
  623. PLCResultHelp.fM04_当前重量 = Convert.ToSingle(GetM04M05IntValue(itemM04.Value, ProgramHelp.Instance.commPLC_M04M05)) / 100;
  624. break;
  625. //case "产品高度":
  626. // PLCResultHelp.fM04_产品高度 = GetM04M05RealValue(itemM04.Value, ProgramHelp.Instance.commPLC_M04M05);
  627. // break;
  628. //case "产品重量":
  629. // PLCResultHelp.fM04_产品重量 = GetM04M05IntValue(itemM04.Value, ProgramHelp.Instance.commPLC_M04M05);
  630. // break;
  631. //case "废料数量":
  632. // PLCResultHelp.fM04_废料数量 = GetM04M05IntValue(itemM04.Value, ProgramHelp.Instance.commPLC_M04M05);
  633. // break;
  634. //case "合格数量":
  635. // PLCResultHelp.fM04_合格数量 = GetM04M05IntValue(itemM04.Value, ProgramHelp.Instance.commPLC_M04M05);
  636. // break;
  637. //case "相机结果":
  638. // ProgramHelp.Instance.commPLC_M04M05.ReadString(itemM04.Value, out PLCResultHelp.fM04_相机结果, out string str);
  639. // break;
  640. //case "盘数":
  641. // PLCResultHelp.fM04_盘数 = GetM04M05Int16Value(itemM04.Value, ProgramHelp.Instance.commPLC_M04M05);
  642. // break;
  643. case "产品信息打包上传":
  644. PLCResultHelp.isM04_产品信息打包上传 = GetM04M05BoolValue(itemM04.Value, ProgramHelp.Instance.commPLC_M04M05);
  645. break;
  646. }
  647. }
  648. int iM05Result = GetM04M05IntValue("DB186.12", ProgramHelp.Instance.commPLC_M04M05);
  649. PLCResultHelp.iM05_箱数 = iM05Result;
  650. GetM04M05AlmValue(PLCCylinder.dictM04M05_Alm, ProgramHelp.Instance.commPLC_M04M05);//
  651. if (EnumWindowDisplay != WindowDisplay.检测装箱房)
  652. {
  653. Thread.Sleep(5);
  654. continue;
  655. }
  656. try
  657. {
  658. if (EnumWindowDisplay == WindowDisplay.检测装箱房)
  659. {
  660. switch (iM04M05IOStation)
  661. {
  662. case 0:
  663. GetM04M05CylinderValue(PLCCylinder.dictM04M05_ST0进口门工位, ProgramHelp.Instance.commPLC_M04M05);
  664. break;
  665. case 1:
  666. GetM04M05CylinderValue(PLCCylinder.dictM04M05_取出工位, ProgramHelp.Instance.commPLC_M04M05);
  667. break;
  668. case 2:
  669. GetM04M05CylinderValue(PLCCylinder.dictM04M05_清洗工位, ProgramHelp.Instance.commPLC_M04M05);
  670. break;
  671. case 3:
  672. GetM04M05CylinderValue(PLCCylinder.dictM04M05_提升机工位, ProgramHelp.Instance.commPLC_M04M05);
  673. break;
  674. case 4:
  675. GetM04M05CylinderValue(PLCCylinder.dictM04M05_测量工位, ProgramHelp.Instance.commPLC_M04M05);
  676. break;
  677. case 5:
  678. GetM04M05CylinderValue(PLCCylinder.dictM04M05_装盘工位, ProgramHelp.Instance.commPLC_M04M05);
  679. break;
  680. case 6:
  681. GetM04M05CylinderValue(PLCCylinder.dictM04M05_出盘工位, ProgramHelp.Instance.commPLC_M04M05);
  682. break;
  683. case 7:
  684. GetM04M05CylinderValue(PLCCylinder.dictM04M05_下流线工位, ProgramHelp.Instance.commPLC_M04M05);
  685. break;
  686. case 8:
  687. GetM04M05CylinderValue(PLCCylinder.dictM04M05_下料站工位, ProgramHelp.Instance.commPLC_M04M05);
  688. break;
  689. }
  690. switch (iM04M05AxisStation)
  691. {
  692. case 0:
  693. GetM04M05AxisPos(PLCAxisPos.dictM04M05_取料X轴, ProgramHelp.Instance.commPLC_M04M05);
  694. GetM04M05Axis(PLCAxis.dictM04M05_轴["取料X轴"], ProgramHelp.Instance.commPLC_M04M05);
  695. break;
  696. case 1:
  697. GetM04M05AxisPos(PLCAxisPos.dictM04M05_取料Y轴, ProgramHelp.Instance.commPLC_M04M05);
  698. GetM04M05Axis(PLCAxis.dictM04M05_轴["取料Y轴"], ProgramHelp.Instance.commPLC_M04M05);
  699. break;
  700. case 2:
  701. GetM04M05AxisPos(PLCAxisPos.dictM04M05_装盘X轴, ProgramHelp.Instance.commPLC_M04M05);
  702. GetM04M05Axis(PLCAxis.dictM04M05_轴["装盘X轴"], ProgramHelp.Instance.commPLC_M04M05);
  703. break;
  704. case 3:
  705. GetM04M05AxisPos(PLCAxisPos.dictM04M05_装盘Y轴, ProgramHelp.Instance.commPLC_M04M05);
  706. GetM04M05Axis(PLCAxis.dictM04M05_轴["装盘Y轴"], ProgramHelp.Instance.commPLC_M04M05);
  707. break;
  708. case 4:
  709. GetM04M05AxisPos(PLCAxisPos.dictM04M05_装盘Z轴, ProgramHelp.Instance.commPLC_M04M05);
  710. GetM04M05Axis(PLCAxis.dictM04M05_轴["装盘Z轴"], ProgramHelp.Instance.commPLC_M04M05);
  711. break;
  712. case 5:
  713. GetM04M05AxisPos(PLCAxisPos.dictM04M05_下料站X轴, ProgramHelp.Instance.commPLC_M04M05);
  714. GetM04M05Axis(PLCAxis.dictM04M05_轴["下料站X轴"], ProgramHelp.Instance.commPLC_M04M05);
  715. break;
  716. case 6:
  717. GetM04M05AxisPos(PLCAxisPos.dictM04M05_下料站Y轴, ProgramHelp.Instance.commPLC_M04M05);
  718. GetM04M05Axis(PLCAxis.dictM04M05_轴["下料站Y轴"], ProgramHelp.Instance.commPLC_M04M05);
  719. break;
  720. case 7:
  721. GetM04M05AxisPos(PLCAxisPos.dictM04M05_下料站Z轴, ProgramHelp.Instance.commPLC_M04M05);
  722. GetM04M05Axis(PLCAxis.dictM04M05_轴["下料站Z轴"], ProgramHelp.Instance.commPLC_M04M05);
  723. break;
  724. }
  725. //GetM04M05Axis(PLCAxis.dictM04M05_轴, ProgramHelp.Instance.commPLC_M04M05);
  726. }
  727. }
  728. catch (Exception )
  729. {
  730. //MessageBox.Show(ex.ToString());
  731. }
  732. Thread.Sleep(1);
  733. }
  734. }
  735. private static void ThPressure()
  736. {
  737. short svalue = 0;
  738. float fvalue = 0;
  739. int ivalue = 0;
  740. string str;
  741. while (true)
  742. {
  743. if (!ProgramHelp.Instance.comm压机.isPLCConnected)
  744. {
  745. Thread.Sleep(5);
  746. continue;
  747. }
  748. //if(EnumWindowDisplay != WindowDisplay.压力机)
  749. //{
  750. // Thread.Sleep(5);
  751. // continue;
  752. //}
  753. try
  754. {
  755. foreach (var item in dictPressure)
  756. {
  757. if(item.Value.type == "short")
  758. {
  759. ProgramHelp.Instance.comm压机.ReadShort(item.Value.Address, out svalue, out str);
  760. item.Value.value = (svalue * item.Value.Scale).ToString();
  761. if(item.Value.Name == "主缸位置")
  762. {
  763. str主缸当前位置 = item.Value.value;
  764. }
  765. if (item.Value.Name == "主缸压力")
  766. {
  767. str主缸当前压力 = item.Value.value;
  768. }
  769. if(item.Value.Name == "当前动作")
  770. {
  771. upTrigger.Now = item.Value.value == "1" ? true : false;
  772. if(upTrigger.OutPut)
  773. {
  774. queuePressureSignals.Enqueue(1);
  775. }
  776. }
  777. }
  778. else if(item.Value.type == "float")
  779. {
  780. ProgramHelp.Instance.comm压机.ReadFloat(item.Value.Address, out fvalue, out str);
  781. item.Value.value =(fvalue * item.Value.Scale).ToString("0.0");
  782. }
  783. else if(item.Value.type == "int")
  784. {
  785. ProgramHelp.Instance.comm压机.ReadInt(item.Value.Address, out ivalue, out str);
  786. item.Value.value = (ivalue * item.Value.Scale).ToString();
  787. }
  788. Thread.Sleep(1);
  789. }
  790. }
  791. catch (Exception )
  792. {
  793. //MessageBox.Show(ex.ToString());
  794. }
  795. Thread.Sleep(2);
  796. }
  797. }
  798. #region read function
  799. #region M01M02
  800. public static bool GetM01M02BoolValue(string add, CommPLC commPLC)
  801. {
  802. if (!commPLC.isPLCConnected) return false;
  803. commPLC.ReadCoin(add, out bool result, out string str);
  804. return result;
  805. }
  806. public static int GetM01M02IntValue(string add,CommPLC commPLC)
  807. {
  808. if (!commPLC.isPLCConnected) return 0;
  809. commPLC.ReadInt(add,out int result,out string str);
  810. return result;
  811. }
  812. public static Int16 GetM01M02Int16Value(string add,CommPLC commPLC)
  813. {
  814. if (!commPLC.isPLCConnected) return 0;
  815. commPLC.ReadShort(add, out Int16 result, out string str);
  816. return result;
  817. }
  818. public static float GetM01M02RealValue(string add,CommPLC commPLC)
  819. {
  820. if (!commPLC.isPLCConnected) return 0;
  821. commPLC.ReadFloat(add, out float result, out string str);
  822. return result;
  823. }
  824. #endregion
  825. #region M03
  826. public static bool GetM03BoolValue(string add, CommPLC commPLC)
  827. {
  828. if (!commPLC.isPLCConnected) return false;
  829. commPLC.ReadCoin(add, out bool result, out string str);
  830. return result;
  831. }
  832. public static int GetM03IntValue(string add, CommPLC commPLC)
  833. {
  834. if (!commPLC.isPLCConnected) return 0;
  835. commPLC.ReadInt(add, out int result, out string str);
  836. return result;
  837. }
  838. public static Int16 GetM03Int16Value(string add, CommPLC commPLC)
  839. {
  840. if (!commPLC.isPLCConnected) return 0;
  841. commPLC.ReadShort(add, out Int16 result, out string str);
  842. return result;
  843. }
  844. public static float GetM03RealValue(string add, CommPLC commPLC)
  845. {
  846. if (!commPLC.isPLCConnected) return 0;
  847. commPLC.ReadFloat(add, out float result, out string str);
  848. return result;
  849. }
  850. #endregion
  851. #region M04M05
  852. public static bool GetM04M05BoolValue(string add, CommPLC commPLC)
  853. {
  854. if (!commPLC.isPLCConnected) return false;
  855. commPLC.ReadCoin(add, out bool result, out string str);
  856. return result;
  857. }
  858. public static int GetM04M05IntValue(string add, CommPLC commPLC)
  859. {
  860. if (!commPLC.isPLCConnected) return 0;
  861. commPLC.ReadInt(add, out int result, out string str);
  862. return result;
  863. }
  864. public static Int16 GetM04M05Int16Value(string add, CommPLC commPLC)
  865. {
  866. if (!commPLC.isPLCConnected) return 0;
  867. commPLC.ReadShort(add, out Int16 result, out string str);
  868. return result;
  869. }
  870. public static float GetM04M05RealValue(string add, CommPLC commPLC)
  871. {
  872. if (!commPLC.isPLCConnected) return 0;
  873. commPLC.ReadFloat(add, out float result, out string str);
  874. return result;
  875. }
  876. #endregion
  877. #endregion
  878. #region write function
  879. public static void SetBoolValue(string add, CommPLC commPLC,bool value)
  880. {
  881. if (!commPLC.isPLCConnected) return ;
  882. commPLC.WriteCoin(add, value, out string str);
  883. }
  884. public static void SetIntValue(string add, CommPLC commPLC,int value)
  885. {
  886. if (!commPLC.isPLCConnected) return;
  887. commPLC.WriteInt(add, value, out string str);
  888. }
  889. public static void SetInt16Value(string add, CommPLC commPLC,short value)
  890. {
  891. if (!commPLC.isPLCConnected) return;
  892. commPLC.WriteShort(add, value, out string str);
  893. }
  894. public static void SetRealValue(string add, CommPLC commPLC,float value)
  895. {
  896. if (!commPLC.isPLCConnected) return;
  897. commPLC.WriteFloat(add, value, out string str);
  898. }
  899. #endregion
  900. #region SetValue
  901. public static void SetM01Result(short value,string keyName)
  902. {
  903. switch(keyName)
  904. {
  905. case "药A暂存当前盒数":
  906. PLCResultHelp.iM01_药A暂存当前盒数 = value;
  907. break;
  908. case "药B暂存当前盒数":
  909. PLCResultHelp.iM01_药B暂存当前盒数 = value;
  910. break;
  911. case "抛盖暂存槽当前数量":
  912. PLCResultHelp.iM01_抛盖暂存槽当前数量 = value;
  913. break;
  914. case "空桶暂存槽当前数量":
  915. PLCResultHelp.iM01_空桶暂存槽当前数量 = value;
  916. break;
  917. }
  918. }
  919. public static void SetM02Result(int value, string keyName)
  920. {
  921. switch (keyName)
  922. {
  923. case "药A称重配比重量":
  924. PLCResultHelp.iM02_药A称重配比重量 = value;
  925. break;
  926. case "A料仓1当前重量":
  927. PLCResultHelp.iM02_A料仓1当前重量 = value;// 1000
  928. break;
  929. case "A料仓2当前重量":
  930. PLCResultHelp.iM02_A料仓2当前重量 = value;// 1000
  931. break;
  932. case "A料仓3当前重量":
  933. PLCResultHelp.iM02_A料仓3当前重量 = value ;// 1000
  934. break;
  935. case "A料仓4当前重量":
  936. PLCResultHelp.iM02_A料仓4当前重量 = value;// 1000
  937. break;
  938. case "A料仓5当前重量":
  939. PLCResultHelp.iM02_A料仓5当前重量 = value;// 1000
  940. break;
  941. case "药B称重配比重量":
  942. PLCResultHelp.iM02_药B称重配比重量 = value;
  943. break;
  944. case "B料仓1当前重量":
  945. PLCResultHelp.iM02_B料仓1当前重量 = value;// 1000
  946. break;
  947. case "B料仓2当前重量":
  948. PLCResultHelp.iM02_B料仓2当前重量 = value;// 1000
  949. break;
  950. case "B料仓3当前重量":
  951. PLCResultHelp.iM02_B料仓3当前重量 = value;// 1000
  952. break;
  953. case "B料仓4当前重量":
  954. PLCResultHelp.iM02_B料仓4当前重量 = value;// 1000
  955. break;
  956. case "B料仓5当前重量":
  957. PLCResultHelp.iM02_B料仓5当前重量 = value;// 1000
  958. break;
  959. }
  960. }
  961. public static void SetM04ResultInt(int value,string keyName)
  962. {
  963. //switch(keyName)
  964. //{
  965. // case "产品重量":
  966. // PLCResultHelp.iM04_产品重量 = value;
  967. // break;
  968. // case "废料数量":
  969. // PLCResultHelp.iM04_废料数量 = value;
  970. // break;
  971. // case "合格数量":
  972. // PLCResultHelp.iM04_合格数量 = value;
  973. // break;
  974. //}
  975. }
  976. public static void SetM04ResultShort(short value, string keyName)
  977. {
  978. //switch (keyName)
  979. //{
  980. // case "产品重量":
  981. // PLCResultHelp.iM04_相机结果 = value;
  982. // break;
  983. // case "废料数量":
  984. // PLCResultHelp.iM04_盘数 = value;
  985. // break;
  986. //}
  987. }
  988. #endregion
  989. }
  990. }