ReadPLCHelp.cs 55 KB

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