Form1.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Net;
  9. using System.Text;
  10. using System.Timers;
  11. using System.Windows.Forms;
  12. using Curtain.DataAccess;
  13. using Curtain.Framework.Json;
  14. using Curtain.Net.Sockets.PLC;
  15. using Curtain.Net.Sockets.PLC.Model.Siemens;
  16. using Newtonsoft.Json.Linq;
  17. using PLC_S.EPTS;
  18. namespace TEST_HPGP
  19. {
  20. public partial class Form1 : Form
  21. {
  22. public Form1()
  23. {
  24. InitializeComponent();
  25. }
  26. private void button1_Click(object sender, EventArgs e)
  27. {
  28. try
  29. {
  30. INI_HPGP plc_ini = INI_HPGP.Get("HPGP1_1");
  31. plc_ini.INI_WS_CODE = "HPGP1_1";
  32. this.textBox1.Text += System.Environment.NewLine + button1.Text + System.Environment.NewLine;
  33. this.Do(plc_ini);
  34. //this.Do2(plc_ini);
  35. this.textBox1.SelectionStart = this.textBox1.TextLength;
  36. this.textBox1.ScrollToCaret();
  37. this.textBox1.Focus();
  38. }
  39. catch(Exception ex)
  40. {
  41. MessageBox.Show(ex.Message, "MAIN", MessageBoxButtons.OK, MessageBoxIcon.Error);
  42. }
  43. }
  44. private void button2_Click(object sender, EventArgs e)
  45. {
  46. try
  47. {
  48. INI_HPGP plc_ini = INI_HPGP.Get("HPGP1_2");
  49. plc_ini.INI_WS_CODE = "HPGP1_2";
  50. this.textBox1.Text += System.Environment.NewLine + button2.Text + System.Environment.NewLine;
  51. this.textBox1.SelectionStart = this.textBox1.TextLength;
  52. this.Do(plc_ini);
  53. //this.Do2(plc_ini);
  54. this.textBox1.SelectionStart = this.textBox1.TextLength;
  55. this.textBox1.ScrollToCaret();
  56. this.textBox1.Focus();
  57. }
  58. catch (Exception ex)
  59. {
  60. MessageBox.Show(ex.Message, "MAIN", MessageBoxButtons.OK, MessageBoxIcon.Error);
  61. }
  62. }
  63. private void button3_Click(object sender, EventArgs e)
  64. {
  65. try
  66. {
  67. INI_HPGP plc_ini = INI_HPGP.Get("HPGP1_3");
  68. plc_ini.INI_WS_CODE = "HPGP1_3";
  69. this.textBox1.Text += System.Environment.NewLine + button3.Text + System.Environment.NewLine;
  70. this.textBox1.SelectionStart = this.textBox1.TextLength;
  71. this.Do(plc_ini);
  72. //this.Do2(plc_ini);
  73. this.textBox1.SelectionStart = this.textBox1.TextLength;
  74. this.textBox1.ScrollToCaret();
  75. this.textBox1.Focus();
  76. }
  77. catch (Exception ex)
  78. {
  79. MessageBox.Show(ex.Message, "MAIN", MessageBoxButtons.OK, MessageBoxIcon.Error);
  80. }
  81. }
  82. private int Do(INI_HPGP plc_ini)
  83. {
  84. try
  85. {
  86. using (SocketClient<SiemensS7_1200Model> plc = new SocketClient<SiemensS7_1200Model>())
  87. {
  88. string outputMessage = $"[{plc_ini.INI_WS_CODE}]PLC_Connect={plc_ini.PLC_IP+":"+plc_ini.PLC_PORT}";
  89. //logger_t.OutputTrace(outputMessage);
  90. this.textBox1.Text += outputMessage + System.Environment.NewLine;
  91. try
  92. {
  93. plc.Connect(plc_ini.PLC_IP, plc_ini.PLC_PORT);
  94. }
  95. catch (Exception ex1)
  96. {
  97. //logger_t.OutputWarn(ex1.Message);
  98. //logger_e.OutputWarn(ex1.Message);
  99. //logger_e_out.OutputWarn(ex1.Message);
  100. MessageBox.Show(ex1.Message, "DO", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  101. this.textBox1.Text += ex1.Message + System.Environment.NewLine;
  102. return 1;
  103. }
  104. // 1. 读取PLC 标识
  105. string s = null;
  106. if (plc_ini.Add_F_CodeNum == "2558")
  107. {
  108. s = "50.1";
  109. }
  110. if (plc_ini.Add_F_CodeNum == "2560")
  111. {
  112. s = "35.4";
  113. }
  114. if (plc_ini.Add_F_CodeNum == "2562")
  115. {
  116. s = "100.1";
  117. }
  118. PLCResult<bool> flag1_result = plc.Read<bool>("M", s);
  119. outputMessage = $"[{plc_ini.INI_WS_CODE}]注浆标识=[{flag1_result.Data}]{"M" + s}";
  120. //logger_t.OutputTrace(outputMessage);
  121. this.textBox1.Text += outputMessage + System.Environment.NewLine;
  122. //outputMessage = $"[{plc_ini.INI_WS_CODE}]GET_F_Code=[ ]{plc_ini.Add_F_Code + plc_ini.Add_F_CodeNum}";
  123. ////logger_t.OutputTrace(outputMessage);
  124. //this.textBox1.Text += outputMessage + System.Environment.NewLine;
  125. PLCResult<short> flag_result = plc.Read<short>(plc_ini.Add_F_Code, plc_ini.Add_F_CodeNum);
  126. outputMessage = $"[{plc_ini.INI_WS_CODE}]注浆标识=[{flag_result.Data}]{plc_ini.Add_F_Code + plc_ini.Add_F_CodeNum}";
  127. //logger_t.OutputTrace(outputMessage);
  128. this.textBox1.Text += outputMessage + System.Environment.NewLine;
  129. //if (flag_result.Data != 1)
  130. //if (!flag_result.Data)
  131. {
  132. //return 1;
  133. }
  134. // 3. 读取PLC 模具是否注浆
  135. JObject jGroutingData = new JObject();
  136. jGroutingData.Add("GROUTINGDATE", DateTime.Now.ToString("yyyy-MM-dd"));
  137. jGroutingData.Add("GROUTINGLINECODE", plc_ini.GL_CODE);
  138. jGroutingData.Add("GROUTINGTIMES", 1);
  139. JArray jGROUTINGLINEDETAIL = new JArray();
  140. for (int i = 0; i < 10; i++)
  141. {
  142. //outputMessage = $"[{plc_ini.INI_WS_CODE}]GET_G_{i}=[ ]{plc_ini.Add_Gs[i] + plc_ini.Add_G_NUMs[i]}";
  143. ////logger_t.OutputTrace(outputMessage);
  144. //this.textBox1.Text += outputMessage + System.Environment.NewLine;
  145. PLCResult<bool> g_result = plc.Read<bool>(plc_ini.Add_Gs[i], plc_ini.Add_G_NUMs[i]);
  146. outputMessage = $"[{plc_ini.INI_WS_CODE}]模具注浆{i+1}=[{g_result.Data}]{plc_ini.Add_Gs[i] + plc_ini.Add_G_NUMs[i]}";
  147. //logger_t.OutputTrace(outputMessage);
  148. this.textBox1.Text += outputMessage + System.Environment.NewLine;
  149. JObject jToken = new JObject();
  150. jToken.Add("GROUTINGMOULDCODE", plc_ini.GL_CODE + $"-{(i + 1):000}");
  151. //if (g_result.Data == 1)
  152. if (g_result.Data)
  153. {
  154. jToken.Add("GROUTINGFLAG", "1");
  155. jToken.Add("NOGROUTINGRREASON", "null");
  156. }
  157. else
  158. {
  159. //jToken.Add("GROUTINGFLAG", "0");
  160. //jToken.Add("NOGROUTINGRREASON", plc_ini.NOGROUTINGRREASON);
  161. }
  162. jGROUTINGLINEDETAIL.Add(jToken);
  163. }
  164. jGroutingData.Add("GROUTINGLINEDETAIL", jGROUTINGLINEDETAIL);
  165. string groutingData = jGroutingData.ToString();
  166. // 工号
  167. string usercode = "";
  168. DataRow dataRow = null;
  169. //using (IDataAccess dataAccess = PLC_S_DataAccess.GetDataAccess())
  170. {
  171. string sqlString = $@"SELECT t.usercode
  172. ,gl.h_linecode
  173. ,gl.h_lineindex
  174. ,gl.h_batchno
  175. ,gl.h_batchindex
  176. FROM tp_mst_workstation t
  177. INNER JOIN tp_pc_groutingline gl
  178. ON gl.groutinglineid = t.groutinglineid
  179. WHERE t.workstationtypeid = 3501
  180. AND t.workstationid = {plc_ini.WS_ID}
  181. AND t.groutinglineid = {plc_ini.GL_ID}";
  182. //this.textBox1.Text += sqlString + System.Environment.NewLine;
  183. // CDAParameter[] ps = new CDAParameter[]
  184. // {
  185. // new CDAParameter("groutinglineid", plc_ini.GL_ID),
  186. // new CDAParameter("workstationid", plc_ini.WS_ID),
  187. // };
  188. // DataTable dataTable = dataAccess.ExecuteDatatable(sqlString, ps);
  189. // if (dataTable.HasData())
  190. // {
  191. // dataRow = dataTable.Rows[0];
  192. // usercode = dataTable.Rows[0]["usercode"].ToString();
  193. // }
  194. //}
  195. //ServiceResultEntity result = SmartDeviceProxy.Instance.Invoke<ServiceResultEntity>(
  196. // p => p.SetHGrouting(
  197. // _mes_s.AccountCode,
  198. // usercode,
  199. // plc_ini.GL_CODE,
  200. // groutingData,
  201. // null));
  202. //// 返回状态(成功、失败)
  203. //if (result.Status != ServiceResultStatus.Success)
  204. //{
  205. // if (result.Status == ServiceResultStatus.SystemError)
  206. // {
  207. // outputMessage = $"MES服务端异常(详情参见MES端日志)";
  208. // }
  209. // else if (result.Message == "EU-01")
  210. // {
  211. // outputMessage = $"无效的帐套或工号(详情参见MES端日志)";
  212. // }
  213. // else
  214. // {
  215. // outputMessage = $"其他错误(详情参见MES端日志)[{result}]";
  216. // }
  217. // logger_e_out.OutputError(null, outputMessage);
  218. // logger_t.OutputError(null, outputMessage);
  219. // logger_e.OutputError(null, outputMessage);
  220. // this.textBox1.Text += outputMessage + System.Environment.NewLine;
  221. // return 1;
  222. }
  223. if (flag_result.Data == 1)
  224. {
  225. //plc_ini.GDD_ID = result.Result.ToInt32();
  226. // 7. 写入PLC 标识 = 2
  227. //outputMessage = $"[{plc_ini.INI_WS_CODE}]SET_F_Code=[ ]{plc_ini.Add_F_Code + plc_ini.Add_F_CodeNum}";
  228. ////logger_t.OutputTrace(outputMessage);
  229. //this.textBox1.Text += outputMessage + System.Environment.NewLine;
  230. //PLCResult f_result = plc.Write<short>(plc_ini.Add_F_Code, plc_ini.Add_F_CodeNum, 2);
  231. //outputMessage = $"[{plc_ini.INI_WS_CODE}]SET_F_Code=[2]{plc_ini.Add_F_Code + plc_ini.Add_F_CodeNum}";
  232. ////logger_t.OutputTrace(outputMessage);
  233. //this.textBox1.Text += outputMessage + System.Environment.NewLine;
  234. }
  235. else
  236. {
  237. //outputMessage = $"[{plc_ini.INI_WS_CODE}]SET_F_Code=[ ]{plc_ini.Add_F_Code + plc_ini.Add_F_CodeNum}";
  238. ////logger_t.OutputTrace(outputMessage);
  239. //this.textBox1.Text += outputMessage + System.Environment.NewLine;
  240. }
  241. // 低注时间
  242. //outputMessage = $"[{plc_ini.INI_WS_CODE}]GET_Add_LZ=[ ]{plc_ini.Add_LZ + plc_ini.Add_LZ_NUM}";
  243. ////logger_t.OutputTrace(outputMessage);
  244. //this.textBox1.Text += "低注时间" + System.Environment.NewLine;
  245. PLCResult<short> lz_result = plc.Read<short>(plc_ini.Add_LZ, plc_ini.Add_LZ_NUM);
  246. outputMessage = $"[{plc_ini.INI_WS_CODE}]低注时间=[{lz_result.Data}]{plc_ini.Add_LZ + plc_ini.Add_LZ_NUM}";
  247. //logger_t.OutputTrace(outputMessage);
  248. this.textBox1.Text += outputMessage + System.Environment.NewLine;
  249. // 高注时间
  250. //outputMessage = $"[{plc_ini.INI_WS_CODE}]GET_Add_GZ=[ ]{plc_ini.Add_GZ + plc_ini.Add_GZ_NUM}";
  251. ////logger_t.OutputTrace(outputMessage);
  252. //this.textBox1.Text += "高注时间" + System.Environment.NewLine;
  253. PLCResult<short> gz_result = plc.Read<short>(plc_ini.Add_GZ, plc_ini.Add_GZ_NUM);
  254. outputMessage = $"[{plc_ini.INI_WS_CODE}]高注时间=[{gz_result.Data}]{plc_ini.Add_GZ + plc_ini.Add_GZ_NUM}";
  255. //logger_t.OutputTrace(outputMessage);
  256. this.textBox1.Text += outputMessage + System.Environment.NewLine;
  257. // 排泥时间
  258. //outputMessage = $"[{plc_ini.INI_WS_CODE}]GET_Add_PN=[ ]{plc_ini.Add_PN + plc_ini.Add_PN_NUM}";
  259. ////logger_t.OutputTrace(outputMessage);
  260. //this.textBox1.Text += "排泥时间" + System.Environment.NewLine;
  261. PLCResult<short> pn_result = plc.Read<short>(plc_ini.Add_PN, plc_ini.Add_PN_NUM);
  262. outputMessage = $"[{plc_ini.INI_WS_CODE}]排泥时间=[{pn_result.Data}]{plc_ini.Add_PN + plc_ini.Add_PN_NUM}";
  263. //logger_t.OutputTrace(outputMessage);
  264. this.textBox1.Text += outputMessage + System.Environment.NewLine;
  265. // 巩固时间
  266. //outputMessage = $"[{plc_ini.INI_WS_CODE}]GET_Add_GG=[ ]{plc_ini.Add_GG + plc_ini.Add_GG_NUM}";
  267. ////logger_t.OutputTrace(outputMessage);
  268. //this.textBox1.Text += "巩固时间" + System.Environment.NewLine;
  269. PLCResult<short> gg_result = plc.Read<short>(plc_ini.Add_GG, plc_ini.Add_GG_NUM);
  270. outputMessage = $"[{plc_ini.INI_WS_CODE}]巩固时间=[{gg_result.Data}]{plc_ini.Add_GG + plc_ini.Add_GG_NUM}";
  271. //logger_t.OutputTrace(outputMessage);
  272. this.textBox1.Text += outputMessage + System.Environment.NewLine;
  273. float[] fs = GetPT_NUM(plc_ini);
  274. // using (IDataAccess dataAccess = PLC_S_DataAccess.GetDataAccess())
  275. // {
  276. // //dataAccess.Open(true);
  277. // string sqlString = @"
  278. //INSERT INTO TP_PM_H_GroutingParas
  279. // (GroutingDailyID
  280. // ,GroutingLineID
  281. // ,GroutingLineCode
  282. // ,H_LineCode
  283. // ,H_LineIndex
  284. // ,H_BatchNo
  285. // ,H_BatchIndex
  286. // ,lz_time
  287. // ,gz_time
  288. // ,pn_time
  289. // ,gg_time
  290. // ,g_pressure
  291. // ,g_temperature
  292. // )
  293. //VALUES
  294. // (@GroutingDailyID@
  295. // ,@GroutingLineID@
  296. // ,@GroutingLineCode@
  297. // ,@H_LineCode@
  298. // ,@H_LineIndex@
  299. // ,@H_BatchNo@
  300. // ,@H_BatchIndex@
  301. // ,@lz_time@
  302. // ,@gz_time@
  303. // ,@pn_time@
  304. // ,@gg_time@
  305. // ,@g_pressure@
  306. // ,@g_temperature@
  307. // )";
  308. // CDAParameter[] ps = new CDAParameter[]
  309. // {
  310. // new CDAParameter("GroutingDailyID", plc_ini.GDD_ID),
  311. // new CDAParameter("GroutingLineID", plc_ini.GL_ID),
  312. // new CDAParameter("GroutingLineCode", plc_ini.GL_CODE),
  313. // new CDAParameter("H_LineCode", plc_ini.GL_H_CODE),
  314. // new CDAParameter("H_LineIndex", plc_ini.GL_H_INDEX),
  315. // new CDAParameter("H_BatchNo", dataRow["H_BatchNo"]),
  316. // new CDAParameter("H_BatchIndex", dataRow["H_BatchIndex"]),
  317. // new CDAParameter("lz_time", lz_result.Data),
  318. // new CDAParameter("gz_time", gz_result.Data),
  319. // new CDAParameter("pn_time", pn_result.Data),
  320. // new CDAParameter("gg_time", gg_result.Data),
  321. // new CDAParameter("g_pressure", (fs==null?0f:fs[0])),
  322. // new CDAParameter("g_temperature", (fs==null?0f:fs[1])),
  323. // };
  324. // dataAccess.ExecuteNonQuery(sqlString, ps);
  325. // sqlString = @"
  326. //INSERT INTO TP_PM_H_GROUTINGPARAS_PT
  327. // (HGPT_ID
  328. // ,groutingdailyid
  329. // ,g_pressure
  330. // ,g_temperature
  331. // )
  332. //VALUES
  333. // (SEQ_PM_H_GROUTINGPARAS_PT.Nextval
  334. // ,@groutingdailyid@
  335. // ,@g_pressure@
  336. // ,@g_temperature@
  337. // )";
  338. // ps = new CDAParameter[]
  339. // {
  340. // new CDAParameter("groutingdailyid", plc_ini.GDD_ID),
  341. // new CDAParameter("g_pressure", (fs==null?0f:fs[0])),
  342. // new CDAParameter("g_temperature", (fs==null?0f:fs[1])),
  343. // };
  344. // dataAccess.ExecuteNonQuery(sqlString, ps);
  345. // //dataAccess.Commit();
  346. // }
  347. }
  348. }
  349. catch (Exception ex)
  350. {
  351. //logger_e_out.OutputError(ex);
  352. //logger_e.OutputError(ex);
  353. //logger_t.OutputError(ex);
  354. //FormLogShow?.ShowLog($"[{plc_ini.INI_WS_CODE}]ERROR={ex.Message}");
  355. MessageBox.Show(ex.Message, "DO", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  356. this.textBox1.Text += ex.Message + System.Environment.NewLine;
  357. return 1;
  358. }
  359. finally
  360. {
  361. //logger_t.EndTracking();
  362. }
  363. return 2;
  364. }
  365. private int Do2(INI_HPGP plc_ini)
  366. {
  367. try
  368. {
  369. //logger_t.BeginTracking();
  370. using (SocketClient<SiemensS7_1200Model> plc = new SocketClient<SiemensS7_1200Model>())
  371. {
  372. string outputMessage = $"[{plc_ini.INI_WS_CODE}]PLC_Connect={JsonHelper.FromObject(plc_ini)}";
  373. //logger_t.OutputTrace(outputMessage);
  374. this.textBox1.Text += outputMessage + System.Environment.NewLine;
  375. try
  376. {
  377. plc.Connect(plc_ini.PLC_IP, plc_ini.PLC_PORT);
  378. }
  379. catch (Exception ex1)
  380. {
  381. //logger_t.OutputWarn(ex1.Message);
  382. //logger_e.OutputWarn(ex1.Message);
  383. //logger_e_out.OutputWarn(ex1.Message);
  384. MessageBox.Show(ex1.Message, "DO2", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  385. this.textBox1.Text += ex1.Message + System.Environment.NewLine;
  386. return 1;
  387. }
  388. // 1. 读取PLC 标识
  389. ////outputMessage = $"[{plc_ini.INI_WS_CODE}]GET_F_Code=[ ]{plc_ini.Add_F_Code + plc_ini.Add_F_CodeNum}";
  390. //////logger_t.OutputTrace(outputMessage);
  391. ////this.textBox1.Text += outputMessage + System.Environment.NewLine;
  392. //PLCResult<short> flag_result = plc.Read<short>(plc_ini.Add_F_Code, plc_ini.Add_F_CodeNum);
  393. //outputMessage = $"[{plc_ini.INI_WS_CODE}]GET_F_Code=[{flag_result.Data}]{plc_ini.Add_F_Code + plc_ini.Add_F_CodeNum}";
  394. ////logger_t.OutputTrace(outputMessage);
  395. //this.textBox1.Text += outputMessage + System.Environment.NewLine;
  396. //PLCResult f_result = plc.Write<short>(plc_ini.Add_F_Code, plc_ini.Add_F_CodeNum, 2);
  397. //outputMessage = $"[{plc_ini.INI_WS_CODE}]SET_F_Code=[2]{plc_ini.Add_F_Code + plc_ini.Add_F_CodeNum}";
  398. ////logger_t.OutputTrace(outputMessage);
  399. //this.textBox1.Text += outputMessage + System.Environment.NewLine;
  400. //if (flag_result.Data != 2)
  401. //if (!flag_result.Data)
  402. {
  403. return 1;
  404. }
  405. float[] fs = GetPT_NUM(plc_ini);
  406. if (fs == null || fs.Length < 2)
  407. {
  408. return 1;
  409. }
  410. // using (IDataAccess dataAccess = PLC_S_DataAccess.GetDataAccess())
  411. // {
  412. // string sqlString = @"
  413. //INSERT INTO TP_PM_H_GROUTINGPARAS_PT
  414. // (HGPT_ID
  415. // ,groutingdailyid
  416. // ,g_pressure
  417. // ,g_temperature
  418. // )
  419. //VALUES
  420. // (SEQ_PM_H_GROUTINGPARAS_PT.Nextval
  421. // ,@groutingdailyid@
  422. // ,@g_pressure@
  423. // ,@g_temperature@
  424. // )";
  425. // CDAParameter[] ps = new CDAParameter[]
  426. // {
  427. // new CDAParameter("groutingdailyid", plc_ini.GDD_ID),
  428. // new CDAParameter("g_pressure", fs[0]),
  429. // new CDAParameter("g_temperature", fs[1]),
  430. // };
  431. // dataAccess.ExecuteNonQuery(sqlString, ps);
  432. // }
  433. }
  434. }
  435. catch (Exception ex)
  436. {
  437. //logger_e_out.OutputError(ex);
  438. //logger_e.OutputError(ex);
  439. //logger_t.OutputError(ex);
  440. //FormLogShow?.ShowLog($"[{plc_ini.INI_WS_CODE}]ERROR={ex.Message}");
  441. MessageBox.Show(ex.Message, "DO2", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  442. this.textBox1.Text += ex.Message + System.Environment.NewLine;
  443. return 1;
  444. }
  445. finally
  446. {
  447. //logger_t.EndTracking();
  448. }
  449. return 2;
  450. }
  451. private float[] GetPT_NUM(INI_HPGP plc_ini)
  452. {
  453. using (SocketClient<SiemensS7_1200Model> plc = new SocketClient<SiemensS7_1200Model>())
  454. {
  455. string outputMessage = $"[{plc_ini.INI_WS_CODE}]PLC_Connect={plc_ini.PT_IP + ":" + plc_ini.PT_PORT}";
  456. //logger_t.OutputTrace(outputMessage);
  457. this.textBox1.Text += outputMessage + System.Environment.NewLine;
  458. try
  459. {
  460. plc.Connect(plc_ini.PT_IP, plc_ini.PT_PORT);
  461. }
  462. catch (Exception ex1)
  463. {
  464. //logger_t.OutputWarn(ex1.Message);
  465. //logger_e.OutputWarn(ex1.Message);
  466. //logger_e_out.OutputWarn(ex1.Message);
  467. MessageBox.Show(ex1.Message, "DO_PT", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  468. this.textBox1.Text += ex1.Message + System.Environment.NewLine;
  469. return null;
  470. }
  471. // 压力
  472. //outputMessage = $"[{plc_ini.INI_WS_CODE}]GET_PT_P=[ ]{plc_ini.PT_P_Code + plc_ini.PT_P_NUM}";
  473. ////logger_t.OutputTrace(outputMessage);
  474. //this.textBox1.Text += "压力" + System.Environment.NewLine;
  475. PLCResult<short> p_result = plc.Read<short>(plc_ini.PT_P_Code, plc_ini.PT_P_NUM);
  476. outputMessage = $"[{plc_ini.INI_WS_CODE}]压力=[{p_result.Data / 10f}]{plc_ini.PT_P_Code + plc_ini.PT_P_NUM}";
  477. //logger_t.OutputTrace(outputMessage);
  478. this.textBox1.Text += outputMessage + System.Environment.NewLine;
  479. // 温度
  480. //outputMessage = $"[{plc_ini.INI_WS_CODE}]GET_PT_T=[ ]{plc_ini.PT_T_Code + plc_ini.PT_T_NUM}";
  481. //logger_t.OutputTrace(outputMessage);
  482. //this.textBox1.Text += "温度" + System.Environment.NewLine;
  483. PLCResult<short> t_result = plc.Read<short>(plc_ini.PT_T_Code, plc_ini.PT_T_NUM);
  484. outputMessage = $"[{plc_ini.INI_WS_CODE}]温度=[{t_result.Data / 10f}]{plc_ini.PT_T_Code + plc_ini.PT_T_NUM}";
  485. //logger_t.OutputTrace(outputMessage);
  486. this.textBox1.Text += outputMessage + System.Environment.NewLine;
  487. float[] fs = new float[2];
  488. fs[0] = p_result.Data / 10f;
  489. fs[1] = t_result.Data / 10f;
  490. return fs;
  491. }
  492. }
  493. private void button4_Click(object sender, EventArgs e)
  494. {
  495. string s = "\u0000\u0000\u0000\u0000";
  496. bool b = s.StartsWith("\u0000");
  497. this.textBox1.Clear();
  498. }
  499. }
  500. }