PLCCylinder.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. using BaseLibRWFile;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows.Forms;
  9. namespace HRT_Measure
  10. {
  11. public class PLCCylinder
  12. {
  13. public static List<string> listPLC_IniIO = new List<string>();
  14. public static Dictionary<string, PLCInitIO> dictPLC_InitIO = new Dictionary<string, PLCInitIO>();
  15. public static List<string> listPLC_M01M02Alm = new List<string>();
  16. public static Dictionary<string,ClsAlm> dictM01M02_Alm = new Dictionary<string,ClsAlm>();
  17. public static List<string> listPLC_M03Alm = new List<string>();
  18. public static Dictionary<string, ClsAlm> dictM03_Alm = new Dictionary<string, ClsAlm>();
  19. public static List<string> listPLC_M04M05Alm = new List<string>();
  20. public static Dictionary<string, ClsAlm> dictM04M05_Alm = new Dictionary<string, ClsAlm>();
  21. //public static List<string> listM03_IniIO = new List<string>();
  22. //public static Dictionary<string, PLCInitIO> dictM03_InitIO = new Dictionary<string, PLCInitIO>();
  23. //public static List<string> listM04M05_IniIO = new List<string>();
  24. //public static Dictionary<string, PLCInitIO> dictM04M05_InitIO = new Dictionary<string, PLCInitIO>();
  25. //M01M02
  26. public static List<string> listM01M02_上料工位 = new List<string>();
  27. public static List<string> listM01M02_取出工位 = new List<string>();
  28. public static List<string> listM01M02_提升机工位 = new List<string>();
  29. public static List<string> listM01M02_称重工位 = new List<string>();
  30. public static List<string> listM01M02_出口工位 = new List<string>();
  31. public static Dictionary<string, ClsPLCIO> dictM01M02_上料工位 = new Dictionary<string, ClsPLCIO>();
  32. public static Dictionary<string, ClsPLCIO> dictM01M02_取出工位 = new Dictionary<string, ClsPLCIO>();
  33. public static Dictionary<string, ClsPLCIO> dictM01M02_提升机工位 = new Dictionary<string, ClsPLCIO>();
  34. public static Dictionary<string, ClsPLCIO> dictM01M02_称重工位 = new Dictionary<string, ClsPLCIO>();
  35. public static Dictionary<string, ClsPLCIO> dictM01M02_出口工位 = new Dictionary<string, ClsPLCIO>();
  36. //M03
  37. public static List<string> listM03_整平工位 = new List<string>();
  38. public static List<string> listM03_装冲工位 = new List<string>();
  39. public static List<string> listM03_压合工位 = new List<string>();
  40. public static List<string> listM03_清洗工位 = new List<string>();
  41. public static List<string> listM03_下流线工位 = new List<string>();
  42. public static List<string> listM03_出料口工位 = new List<string>();
  43. public static Dictionary<string, ClsPLCIO> dictM03_整平工位 = new Dictionary<string, ClsPLCIO>();
  44. public static Dictionary<string, ClsPLCIO> dictM03_装冲工位 = new Dictionary<string, ClsPLCIO>();
  45. public static Dictionary<string, ClsPLCIO> dictM03_压合工位 = new Dictionary<string, ClsPLCIO>();
  46. public static Dictionary<string, ClsPLCIO> dictM03_清洗工位 = new Dictionary<string, ClsPLCIO>();
  47. public static Dictionary<string, ClsPLCIO> dictM03_下流线工位 = new Dictionary<string, ClsPLCIO>();
  48. public static Dictionary<string, ClsPLCIO> dictM03_出料口工位 = new Dictionary<string, ClsPLCIO>();
  49. //M04M05
  50. public static List<string> listM04M05_ST0进口门工位 = new List<string>();
  51. public static List<string> listM04M05_取出工位 = new List<string>();
  52. public static List<string> listM04M05_清洗工位 = new List<string>();
  53. public static List<string> listM04M05_提升机工位 = new List<string>();
  54. public static List<string> listM04M05_测量工位 = new List<string>();
  55. public static List<string> listM04M05_装盘工位 = new List<string>();
  56. public static List<string> listM04M05_出盘工位 = new List<string>();
  57. public static List<string> listM04M05_下流线工位 = new List<string>();
  58. public static List<string> listM04M05_下料站工位 = new List<string>();
  59. public static Dictionary<string, ClsPLCIO> dictM04M05_ST0进口门工位 = new Dictionary<string, ClsPLCIO>();
  60. public static Dictionary<string, ClsPLCIO> dictM04M05_取出工位 = new Dictionary<string, ClsPLCIO>();
  61. public static Dictionary<string, ClsPLCIO> dictM04M05_清洗工位 = new Dictionary<string, ClsPLCIO>();
  62. public static Dictionary<string, ClsPLCIO> dictM04M05_提升机工位 = new Dictionary<string, ClsPLCIO>();
  63. public static Dictionary<string, ClsPLCIO> dictM04M05_测量工位 = new Dictionary<string, ClsPLCIO>();
  64. public static Dictionary<string, ClsPLCIO> dictM04M05_装盘工位 = new Dictionary<string, ClsPLCIO>();
  65. public static Dictionary<string, ClsPLCIO> dictM04M05_出盘工位 = new Dictionary<string, ClsPLCIO>();
  66. public static Dictionary<string, ClsPLCIO> dictM04M05_下流线工位 = new Dictionary<string, ClsPLCIO>();
  67. public static Dictionary<string, ClsPLCIO> dictM04M05_下料站工位 = new Dictionary<string, ClsPLCIO>();
  68. public static Ini newIni;
  69. #region Cylinder
  70. public static void GetM01M02Add()
  71. {
  72. newIni = new Ini(Application.StartupPath + "\\Config\\PLCAddressM01M02.ini");
  73. int count上料工位 = Convert.ToInt32(newIni.ReadIni("System", "上料工位Count", "20"));
  74. int count取出工位 = Convert.ToInt32(newIni.ReadIni("System", "取出工位Count", "20"));
  75. int count提升机工位 = Convert.ToInt32(newIni.ReadIni("System", "提升机工位Count", "20"));
  76. int count称重工位 = Convert.ToInt32(newIni.ReadIni("System", "称重工位Count", "20"));
  77. int count出口工位 = Convert.ToInt32(newIni.ReadIni("System", "出口工位Count", "20"));
  78. for (int i = 0; i < count上料工位; i++)
  79. {
  80. string str = newIni.ReadIni("上料工位手动", (i + 1).ToString(), "20");
  81. listM01M02_上料工位.Add(str);
  82. ClsPLCIO clsPLCIO = new ClsPLCIO("M01M02", str);
  83. dictM01M02_上料工位.Add(str.Split(',')[0], clsPLCIO);
  84. }
  85. for (int i = 0; i < count取出工位; i++)
  86. {
  87. string str = newIni.ReadIni("取出工位手动", (i + 1).ToString(), "20");
  88. listM01M02_取出工位.Add(str);
  89. ClsPLCIO clsPLCIO = new ClsPLCIO("M01M02", str);
  90. dictM01M02_取出工位.Add(str.Split(',')[0], clsPLCIO);
  91. }
  92. for (int i = 0; i < count提升机工位; i++)
  93. {
  94. string str = newIni.ReadIni("提升机工位手动", (i + 1).ToString(), "20");
  95. listM01M02_提升机工位.Add(str);
  96. ClsPLCIO clsPLCIO = new ClsPLCIO("M01M02", str);
  97. dictM01M02_提升机工位.Add(str.Split(',')[0], clsPLCIO);
  98. }
  99. for (int i = 0; i < count称重工位; i++)
  100. {
  101. string str = newIni.ReadIni("称重工位手动", (i + 1).ToString(), "20");
  102. listM01M02_称重工位.Add(str);
  103. ClsPLCIO clsPLCIO = new ClsPLCIO("M01M02", str);
  104. dictM01M02_称重工位.Add(str.Split(',')[0], clsPLCIO);
  105. }
  106. for (int i = 0; i < count出口工位; i++)
  107. {
  108. string str = newIni.ReadIni("出口工位手动", (i + 1).ToString(), "20");
  109. listM01M02_出口工位.Add(str);
  110. ClsPLCIO clsPLCIO = new ClsPLCIO("M01M02", str);
  111. dictM01M02_出口工位.Add(str.Split(',')[0], clsPLCIO);
  112. }
  113. }
  114. public static void GetM03Add()
  115. {
  116. newIni = new Ini(Application.StartupPath + "\\Config\\PLCAddressM03.ini");
  117. int count整平工位 = Convert.ToInt32(newIni.ReadIni("System", "整平工位Count", "20"));
  118. int count装冲工位 = Convert.ToInt32(newIni.ReadIni("System", "装冲工位Count", "20"));
  119. int count压合工位 = Convert.ToInt32(newIni.ReadIni("System", "压合工位Count", "20"));
  120. int count清洗工位 = Convert.ToInt32(newIni.ReadIni("System", "清洗工位Count", "20"));
  121. int count下流线工位 = Convert.ToInt32(newIni.ReadIni("System", "下流线工位Count", "20"));
  122. int count出料口工位 = Convert.ToInt32(newIni.ReadIni("System", "出料口工位Count", "20"));
  123. for (int i = 0; i < count整平工位; i++)
  124. {
  125. string str = newIni.ReadIni("整平工位手动", (i + 1).ToString(), "20");
  126. listM03_整平工位.Add(str);
  127. ClsPLCIO clsPLCIO = new ClsPLCIO("M03", str);
  128. dictM03_整平工位.Add(str.Split(',')[0], clsPLCIO);
  129. }
  130. for (int i = 0; i < count装冲工位; i++)
  131. {
  132. string str = newIni.ReadIni("装冲工位手动", (i + 1).ToString(), "20");
  133. listM03_装冲工位.Add(str);
  134. ClsPLCIO clsPLCIO = new ClsPLCIO("M03", str);
  135. dictM03_装冲工位.Add(str.Split(',')[0], clsPLCIO);
  136. }
  137. for (int i = 0; i < count压合工位; i++)
  138. {
  139. string str = newIni.ReadIni("压合工位手动", (i + 1).ToString(), "20");
  140. listM03_压合工位.Add(str);
  141. ClsPLCIO clsPLCIO = new ClsPLCIO("M03", str);
  142. dictM03_压合工位.Add(str.Split(',')[0], clsPLCIO);
  143. }
  144. for (int i = 0; i < count清洗工位; i++)
  145. {
  146. string str = newIni.ReadIni("清洗工位手动", (i + 1).ToString(), "20");
  147. listM03_清洗工位.Add(str);
  148. ClsPLCIO clsPLCIO = new ClsPLCIO("M03", str);
  149. dictM03_清洗工位.Add(str.Split(',')[0], clsPLCIO);
  150. }
  151. for (int i = 0; i < count下流线工位; i++)
  152. {
  153. string str = newIni.ReadIni("下流线工位手动", (i + 1).ToString(), "20");
  154. listM03_下流线工位.Add(str);
  155. ClsPLCIO clsPLCIO = new ClsPLCIO("M03", str);
  156. dictM03_下流线工位.Add(str.Split(',')[0], clsPLCIO);
  157. }
  158. for (int i = 0; i < count出料口工位; i++)
  159. {
  160. string str = newIni.ReadIni("出料口工位手动", (i + 1).ToString(), "20");
  161. listM03_出料口工位.Add(str);
  162. ClsPLCIO clsPLCIO = new ClsPLCIO("M03", str);
  163. dictM03_出料口工位.Add(str.Split(',')[0], clsPLCIO);
  164. }
  165. }
  166. public static void GetM04M05Add()
  167. {
  168. newIni = new Ini(Application.StartupPath + "\\Config\\PLCAddressM04M05.ini");
  169. int countST0进口门工位 = Convert.ToInt32(newIni.ReadIni("System", "ST0进口门工位Count", "20"));
  170. int count取出工位 = Convert.ToInt32(newIni.ReadIni("System", "取出工位Count", "20"));
  171. int count清洗工位 = Convert.ToInt32(newIni.ReadIni("System", "清洗工位Count", "20"));
  172. int count提升机工位 = Convert.ToInt32(newIni.ReadIni("System", "提升机工位Count", "20"));
  173. int count测量工位 = Convert.ToInt32(newIni.ReadIni("System", "测量工位Count", "20"));
  174. int count装盘工位 = Convert.ToInt32(newIni.ReadIni("System", "装盘工位Count", "20"));
  175. int count出盘工位 = Convert.ToInt32(newIni.ReadIni("System", "出盘工位Count", "20"));
  176. int count下流线工位 = Convert.ToInt32(newIni.ReadIni("System", "下流线工位Count", "20"));
  177. int count下料站工位 = Convert.ToInt32(newIni.ReadIni("System", "下料站工位Count", "20"));
  178. for (int i = 0; i < countST0进口门工位; i++)
  179. {
  180. string str = newIni.ReadIni("ST0进口门工位手动", (i + 1).ToString(), "20");
  181. listM04M05_ST0进口门工位.Add(str);
  182. ClsPLCIO clsPLCIO = new ClsPLCIO("M04M05", str);
  183. dictM04M05_ST0进口门工位.Add(str.Split(',')[0], clsPLCIO);
  184. }
  185. for (int i = 0; i < count取出工位; i++)
  186. {
  187. string str = newIni.ReadIni("取出工位手动", (i + 1).ToString(), "20");
  188. listM04M05_取出工位.Add(str);
  189. ClsPLCIO clsPLCIO = new ClsPLCIO("M04M05", str);
  190. dictM04M05_取出工位.Add(str.Split(',')[0], clsPLCIO);
  191. }
  192. for (int i = 0; i < count清洗工位; i++)
  193. {
  194. string str = newIni.ReadIni("清洗工位手动", (i + 1).ToString(), "20");
  195. listM04M05_清洗工位.Add(str);
  196. ClsPLCIO clsPLCIO = new ClsPLCIO("M04M05", str);
  197. dictM04M05_清洗工位.Add(str.Split(',')[0], clsPLCIO);
  198. }
  199. for (int i = 0; i < count提升机工位; i++)
  200. {
  201. string str = newIni.ReadIni("提升机工位手动", (i + 1).ToString(), "20");
  202. listM04M05_提升机工位.Add(str);
  203. ClsPLCIO clsPLCIO = new ClsPLCIO("M04M05", str);
  204. dictM04M05_提升机工位.Add(str.Split(',')[0], clsPLCIO);
  205. }
  206. for (int i = 0; i < count测量工位; i++)
  207. {
  208. string str = newIni.ReadIni("测量工位手动", (i + 1).ToString(), "20");
  209. listM04M05_测量工位.Add(str);
  210. ClsPLCIO clsPLCIO = new ClsPLCIO("M04M05", str);
  211. dictM04M05_测量工位.Add(str.Split(',')[0], clsPLCIO);
  212. }
  213. for (int i = 0; i < count装盘工位; i++)
  214. {
  215. string str = newIni.ReadIni("装盘工位手动", (i + 1).ToString(), "20");
  216. listM04M05_装盘工位.Add(str);
  217. ClsPLCIO clsPLCIO = new ClsPLCIO("M04M05", str);
  218. dictM04M05_装盘工位.Add(str.Split(',')[0], clsPLCIO);
  219. }
  220. for (int i = 0; i < count出盘工位; i++)
  221. {
  222. string str = newIni.ReadIni("出盘工位手动", (i + 1).ToString(), "20");
  223. listM04M05_出盘工位.Add(str);
  224. ClsPLCIO clsPLCIO = new ClsPLCIO("M04M05", str);
  225. dictM04M05_出盘工位.Add(str.Split(',')[0], clsPLCIO);
  226. }
  227. for (int i = 0; i < count下流线工位; i++)
  228. {
  229. string str = newIni.ReadIni("下流线工位手动", (i + 1).ToString(), "20");
  230. listM04M05_下流线工位.Add(str);
  231. ClsPLCIO clsPLCIO = new ClsPLCIO("M04M05", str);
  232. dictM04M05_下流线工位.Add(str.Split(',')[0], clsPLCIO);
  233. }
  234. for (int i = 0; i < count下料站工位; i++)
  235. {
  236. string str = newIni.ReadIni("下料站工位手动", (i + 1).ToString(), "20");
  237. listM04M05_下料站工位.Add(str);
  238. ClsPLCIO clsPLCIO = new ClsPLCIO("M04M05", str);
  239. dictM04M05_下料站工位.Add(str.Split(',')[0], clsPLCIO);
  240. }
  241. }
  242. #endregion
  243. public static void GetInitIO()
  244. {
  245. //strHandOrAuto = "DB20.494.5";
  246. //strInitDone = "DB48.24.4";
  247. //strWait = "DB20.495.1";
  248. //strAutoRunning = "DB20.495.2";
  249. //strAlm = "DB20.495.0";
  250. //初始化按钮,异常消除按钮,停止按钮,启动按钮,手动模式,
  251. string strIOM01M02 = "DB20.494.5,DB48.24.4,DB20.495.1,DB20.495.2,DB20.495.0,DB48.25.3,DB20.494.2,DB20.494.4,DB48.24.0,DB20.494.5";
  252. listPLC_IniIO.Add(strIOM01M02);
  253. PLCInitIO pLCInitIOM01M02 = new PLCInitIO("M01M02", strIOM01M02);
  254. dictPLC_InitIO.Add("M01M02", pLCInitIOM01M02);
  255. //strHandOrAuto = "DB20.4.5";
  256. //strInitDone = "DB48.24.4";
  257. //strWait = "DB20.5.1";
  258. //strAutoRunning = "DB20.5.2";
  259. //strAlm = "DB20.5.0";
  260. string strIOM03 = "DB20.4.5,DB48.24.4,DB20.5.1,DB20.5.2,DB20.5.0,DB48.25.3,DB20.4.2,DB20.4.4,DB48.24.0,DB20.4.5";
  261. listPLC_IniIO.Add(strIOM03);
  262. PLCInitIO pLCInitIOM03 = new PLCInitIO("M03", strIOM03);
  263. dictPLC_InitIO.Add("M03", pLCInitIOM03);
  264. //strHandOrAuto = "DB20.0.5";
  265. //strInitDone = "DB48.24.4";
  266. //strWait = "DB20.1.1";
  267. //strAutoRunning = "DB20.1.2";
  268. //strAlm = "DB20.1.0";
  269. string strIOM04M05 = "DB20.0.5,DB48.24.4,DB20.1.1,DB20.1.2,DB20.1.0,DB48.25.3,DB20.0.2,DB20.0.4,DB48.24.0,DB48.24.3,";
  270. listPLC_IniIO.Add(strIOM04M05);
  271. PLCInitIO pLCInitIOM04M05 = new PLCInitIO("M04M05", strIOM04M05);
  272. dictPLC_InitIO.Add("M04M05", pLCInitIOM04M05);
  273. }
  274. public static void GetAlm()
  275. {
  276. newIni = new Ini(Application.StartupPath + "\\Config\\PLCAlmM01M02.ini");
  277. int countM01M02 = Convert.ToInt32(newIni.ReadIni("System", "Count", "20"));
  278. for (int i = 0; i < countM01M02; i++)
  279. {
  280. string str = newIni.ReadIni("报警", (i + 1).ToString(), "20");
  281. listPLC_M01M02Alm.Add(str);
  282. ClsAlm clsAlm = new ClsAlm("M01M02", str);
  283. dictM01M02_Alm.Add(str.Split(',')[0], clsAlm);
  284. }
  285. newIni = new Ini(Application.StartupPath + "\\Config\\PLCAlmM03.ini");
  286. int countM03 = Convert.ToInt32(newIni.ReadIni("System", "Count", "20"));
  287. for (int i = 0; i < countM03; i++)
  288. {
  289. string str = newIni.ReadIni("报警", (i + 1).ToString(), "20");
  290. listPLC_M03Alm.Add(str);
  291. ClsAlm clsAlm = new ClsAlm("M03", str);
  292. dictM03_Alm.Add(str.Split(',')[0], clsAlm);
  293. }
  294. newIni = new Ini(Application.StartupPath + "\\Config\\PLCAlmM04M05.ini");
  295. int countM04M05 = Convert.ToInt32(newIni.ReadIni("System", "Count", "20"));
  296. for (int i = 0; i < countM04M05; i++)
  297. {
  298. string str = newIni.ReadIni("报警", (i + 1).ToString(), "20");
  299. listPLC_M04M05Alm.Add(str);
  300. ClsAlm clsAlm = new ClsAlm("M04M05", str);
  301. dictM04M05_Alm.Add(str.Split(',')[0], clsAlm);
  302. }
  303. }
  304. }
  305. }