• .NET的PLC帮助类


     TCP和UDP协议:

            TCP(传输控制协议)和UDP(用户数据报协议)是TCP/IP协议簇中的两种核心协议。它们在传输层上提供数据传输服务,但具有不同的特性和功能。

            TCP协议是一种提供可靠、面向连接的字节流服务的传输协议。在数据传输前,发送方和接收方必须先建立TCP连接,然后才能进行数据传输。它通过超时重发、丢弃重复数据、数据检验等功能,确保数据能从一端传输到另一端。

            UDP协议则是一种简单的面向数据报的传输层协议,它提供的是非面向连接、不可靠的数据流传输服务。由于UDP在传输数据报前不需要在客户和服务器之间建立连接,也没有超时重发等机制,因此其传输速度相对较快。但这也意味着它不能提供数据传输的可靠性保障。

            总的来说,TCP和UDP各有其优点和使用场景。TCP主要应用于可靠性要求高的应用,如网页浏览、文件传输等;而UDP则更适合于可靠性要求低、对传输速度和经济性有一定需求的应用,如视频流、游戏等。

    RS-232和RS-475通信接口标准及Modbus协议:

            RS-232是一种常见的串行通信接口标准,由美国电子工业协会(EIA)联合贝尔系统公司、调制解调器厂家及计算机终端生产厂家于1970年共同制定。其全名为“数据终端设备(DTE)和数据通信设备(DCE)之间串行二进制数据交换接口技术标准”。它通常被应用于计算机、调制解调器和各种电子设备之间的通信连接。

            RS-475是一种由美国电子工业协会(EIA)制定的半双工通信接口标准,它通常被应用于电子设备之间的数据传输。它采用平衡驱动和差分接收,因此具有较好的抗干扰能力,同时传输距离较远,可以达到数百米甚至千米级别。与RS-232不同的是,RS-475通常采用9针D型连接器,并且其引脚定义也与RS-232有所不同。RS-475主要用于工业、科学和医疗等领域的设备间通信,但由于其半双工的限制,应用场景不如RS-232和RS-485广泛。

            Modbus是一种串行通信协议,最初由Modicon公司(现在的施耐德电气 Schneider Electric)于1979年开发,用于可编程逻辑控制器(PLC)之间的通信。此协议已经成为工业领域通信协议的业界标准,并且现在是工业电子设备之间常用的连接方式。西门子的S1200和S1500用的就是Modbus协议

            Modbus协议定义了一个控制器能够识别的消息结构,不管它们是经过何种网络进行通信的。它描述了控制器请求访问其他设备的过程,如果回应来自其他设备的请求,以及怎样侦测错误并记录。它制定了消息域格局和内容的公共格式。当在Modbus网络上通信时,此协议决定了每个控制器需要知道它们的设备地址,识别按地址发来的消息,决定要产生何种行动。如果需要回应,控制器将生成反馈信息并用Modbus协议发出。总的来说,Modbus是一种应用于电子控制器之间的通用语言,通过它,不同厂商生产的控制设备可以连成工业网络,进行集中监控。

    一、使用HslCommunication程序集,官网:胡工科技

    1. using Newtonsoft.Json.Linq;
    2. using System;
    3. using System.Collections.Generic;
    4. using System.Net;
    5. using System.Threading;
    6. using HslCommunication;
    7. using HslCommunication.Profinet.Siemens;
    8. using HslCommunication.Profinet.Omron;
    9. using HslCommunication.Profinet.Keyence;
    10. namespace PLC.Class
    11. {
    12. public class PLCHelper
    13. {
    14. #region 连接西门子PLC--SiemensS7Net
    15. /// <summary>
    16. /// 连接西门子PLC--SiemensS7Net
    17. /// </summary>
    18. /// <param name="siemens"></param>
    19. /// <param name="ip">IP地址</param>
    20. /// <param name="port">端口</param>
    21. /// <returns></returns>
    22. private bool ConnectSiemens(SiemensS7Net siemens, string ip, int port)
    23. {
    24. try
    25. {
    26. IPAddress ipaddress;
    27. bool flag = !IPAddress.TryParse(ip, out ipaddress);
    28. if (flag)
    29. {
    30. return false;
    31. }
    32. else
    33. {
    34. siemens.IpAddress = ip;
    35. siemens.Port = port;
    36. OperateResult operateResult = siemens.ConnectServer();
    37. bool isSuccess = operateResult.IsSuccess;
    38. if (isSuccess)
    39. {
    40. return true;
    41. }
    42. else
    43. {
    44. return false;
    45. }
    46. }
    47. }
    48. catch (Exception)
    49. {
    50. return false;
    51. }
    52. }
    53. /// <summary>
    54. /// 给西门子PLC点位写信号
    55. /// </summary>
    56. /// <param name="siemens"></param>
    57. /// <param name="ip">IP地址</param>
    58. /// <param name="port">端口</param>
    59. /// <param name="point">PLC点位</param>
    60. /// <param name="flag">给点位传入的值</param>
    61. /// <returns></returns>
    62. public bool WriteFlagBySiemens(SiemensS7Net siemens, string ip, int port, string point, short flag)
    63. {
    64. if (ConnectSiemens(siemens, ip, port))
    65. {
    66. OperateResult result = siemens.Write(point, flag);
    67. siemens.ConnectClose();
    68. return result.IsSuccess;
    69. }
    70. else
    71. {
    72. return false;
    73. }
    74. }
    75. /// <summary>
    76. /// 读取西门子PLC的状态
    77. /// </summary>
    78. /// <param name="siemens"></param>
    79. /// <param name="ip">IP地址</param>
    80. /// <param name="port">端口</param>
    81. /// <param name="point">PLC点位</param>
    82. /// <returns></returns>
    83. public bool ReadBoolBySiemens(SiemensS7Net siemens, string ip, int port, string point)
    84. {
    85. if (ConnectSiemens(siemens, ip, port))
    86. {
    87. OperateResult<bool> value = siemens.ReadBool(point);
    88. siemens.ConnectClose();
    89. return value.Content;
    90. }
    91. else
    92. {
    93. return false;
    94. }
    95. }
    96. /// <summary>
    97. /// 读取西门子PLC的值
    98. /// </summary>
    99. /// <param name="siemens"></param>
    100. /// <param name="ip">IP地址</param>
    101. /// <param name="port">端口</param>
    102. /// <param name="point">PLC点位</param>
    103. /// <param name="length">读取长度</param>
    104. /// <returns></returns>
    105. public string ReadStringBySiemens(SiemensS7Net siemens, string ip, int port, string point, ushort length)
    106. {
    107. if (ConnectSiemens(siemens, ip, port))
    108. {
    109. OperateResult<string> result = new OperateResult<string>();
    110. result = siemens.ReadString(point, length);
    111. string source = string.Empty;
    112. if (!string.IsNullOrEmpty(result.Content))
    113. {
    114. source = result.Content;
    115. }
    116. else
    117. {
    118. for (int i = 0; i < 3; i++)
    119. {
    120. Thread.Sleep(10);
    121. result = siemens.ReadString(point, length);
    122. if (!string.IsNullOrEmpty(result.Content))
    123. {
    124. source = result.Content;
    125. break;
    126. }
    127. }
    128. if (string.IsNullOrEmpty(result.Content))
    129. {
    130. return "未读取到PLC信息";
    131. }
    132. }
    133. siemens.ConnectClose();
    134. return source;
    135. }
    136. else
    137. {
    138. return "false";
    139. }
    140. }
    141. /// <summary>
    142. /// 清空西门子PLC点位中的值
    143. /// </summary>
    144. /// <param name="siemens"></param>
    145. /// <param name="ip"></param>
    146. /// <param name="port"></param>
    147. /// <param name="point"></param>
    148. /// <param name="length">写入的长度</param>
    149. /// <returns></returns>
    150. public bool ClearPlcPocketBySiemens(SiemensS7Net siemens, string ip, int port, string point, int length, string flag = " ")
    151. {
    152. if (ConnectSiemens(siemens, ip, port))
    153. {
    154. OperateResult result = siemens.Write(point, flag, length);
    155. siemens.ConnectClose();
    156. return result.IsSuccess;
    157. }
    158. else
    159. {
    160. return false;
    161. }
    162. }
    163. #endregion
    164. #region 连接欧姆龙PLC--OmronFinsNet
    165. /// <summary>
    166. /// 连接欧姆龙PLC--OmronFinsNet
    167. /// </summary>
    168. /// <param name="omron"></param>
    169. /// <param name="ip"></param>
    170. /// <param name="port"></param>
    171. /// <returns></returns>
    172. private bool ConnectOmron(OmronFinsNet omron, string ip, int port)
    173. {
    174. //OmronFinsUdp
    175. try
    176. {
    177. IPAddress ipaddress;
    178. bool flag = !IPAddress.TryParse(ip, out ipaddress);
    179. if (flag)
    180. {
    181. return false;
    182. }
    183. else
    184. {
    185. omron.IpAddress = ip;
    186. omron.Port = port;
    187. omron.SA1 = 239;
    188. //if (ip240.Contains(ip))
    189. //{
    190. // omron.SA1 = 240;
    191. //}
    192. //else
    193. //{
    194. // omron.SA1 = 239;
    195. //}
    196. //omron.DA1 = 24;
    197. OperateResult operateResult = omron.ConnectServer();
    198. if (!operateResult.IsSuccess)
    199. {
    200. for (int i = 0;i < 3;i++)
    201. {
    202. operateResult = omron.ConnectServer();
    203. if (operateResult.IsSuccess)
    204. {
    205. break;
    206. //return true;
    207. }
    208. }
    209. //SA1使用239连接不上,则采取240连接
    210. if (!operateResult.IsSuccess)
    211. {
    212. omron.SA1 = 240;
    213. for (int i = 0; i < 3; i++)
    214. {
    215. operateResult = omron.ConnectServer();
    216. if (operateResult.IsSuccess)
    217. {
    218. break;
    219. //return true;
    220. }
    221. }
    222. }
    223. //if (!isSuccess)
    224. //{
    225. // return false;
    226. //}
    227. }
    228. return operateResult.IsSuccess;
    229. }
    230. }
    231. catch (Exception ex)
    232. {
    233. LogHelper.WriteErrLog(ex.ToString());
    234. return false;
    235. }
    236. }
    237. /// <summary>
    238. /// 给欧姆龙PLC点位写信号
    239. /// </summary>
    240. /// <param name="siemens"></param>
    241. /// <param name="ip">IP地址</param>
    242. /// <param name="port">端口</param>
    243. /// <param name="point">PLC点位</param>
    244. /// <param name="flag">给点位传入的值</param>
    245. /// <returns></returns>
    246. public bool WriteShortByOmron(OmronFinsNet omron, string ip, int port, string point, short flag)
    247. {
    248. //if (ConnectOmron(omron, ip, port))
    249. //{
    250. OperateResult result = omron.Write(point, flag);
    251. if (!result.IsSuccess)
    252. {
    253. for (int i = 0;i < 3;i++)
    254. {
    255. result = omron.Write(point,flag);
    256. if (result.IsSuccess)
    257. {
    258. break;
    259. //return true;
    260. }
    261. }
    262. //if (!result.IsSuccess)
    263. //{
    264. // return false;
    265. //}
    266. }
    267. //omron.ConnectClose();
    268. return result.IsSuccess;
    269. //}
    270. //else
    271. //{
    272. // return false;
    273. //}
    274. }
    275. //写入float值
    276. public bool WriteFloatByOmron(OmronFinsNet omron, string ip, int port, string point, float flag)
    277. {
    278. //if (ConnectOmron(omron, ip, port))
    279. //{
    280. OperateResult result = omron.Write(point, flag);
    281. if (!result.IsSuccess)
    282. {
    283. for (int i = 0; i < 3; i++)
    284. {
    285. result = omron.Write(point, flag);
    286. if (result.IsSuccess)
    287. {
    288. break;
    289. //return true;
    290. }
    291. }
    292. //if (!result.IsSuccess)
    293. //{
    294. // return false;
    295. //}
    296. }
    297. //omron.ConnectClose();
    298. return result.IsSuccess;
    299. //}
    300. //else
    301. //{
    302. // return false;
    303. //}
    304. }
    305. public string WritePointByOmron(OmronFinsNet omron, string ip, int port, List<string> pointlst, List<string> dataTypelst, List<string> valuelst,string type,List<string> filedlst)
    306. {
    307. //int sucNum = 0;
    308. string errorFileds = "";
    309. try
    310. {
    311. if (type == "EDIT")
    312. {
    313. //return 0;
    314. return "";
    315. }
    316. //调用时以下6个点位不写入
    317. List<string> addNotWritePoint = new List<string>() { "D200", "D202", "D210", "D212", "D0", "D469" };
    318. if (ConnectOmron(omron, ip, port))
    319. {
    320. for (int i = 0; i < pointlst.Count; i++)
    321. {
    322. if (addNotWritePoint.Contains(pointlst[i]))
    323. {
    324. continue;
    325. }
    326. if (dataTypelst[i] == "FLOAT" && !string.IsNullOrEmpty(valuelst[i]))
    327. {
    328. float flag = Convert.ToSingle(valuelst[i]);
    329. bool result = WriteFloatByOmron(omron, ip, port, pointlst[i], flag);
    330. if (result)
    331. {
    332. //sucNum++;
    333. }
    334. else
    335. {
    336. if (errorFileds.Length > 0)
    337. {
    338. errorFileds += ",";
    339. }
    340. errorFileds += filedlst[i];
    341. LogHelper.WriteErrLog($"IP:{ip},端口:{port},点位:{pointlst[i]},值:{valuelst[i]}写入失败!");
    342. }
    343. }
    344. else if (dataTypelst[i] == "SHORT" && !string.IsNullOrEmpty(valuelst[i]))
    345. {
    346. short flag = Convert.ToInt16(valuelst[i]);
    347. bool result = WriteShortByOmron(omron, ip, port, pointlst[i], flag);
    348. if (result)
    349. {
    350. //sucNum++;
    351. }
    352. else
    353. {
    354. if (errorFileds.Length > 0)
    355. {
    356. errorFileds += ",";
    357. }
    358. errorFileds += filedlst[i];
    359. LogHelper.WriteErrLog($"IP:{ip},端口:{port},点位:{pointlst[i]},值:{valuelst[i]}写入失败!");
    360. }
    361. }
    362. }
    363. //return sucNum;
    364. }
    365. //else
    366. //{
    367. // return sucNum;
    368. //}
    369. }
    370. catch (Exception ex)
    371. {
    372. LogHelper.WriteErrLog(ex.ToString());
    373. }
    374. finally
    375. {
    376. omron.ConnectClose();
    377. }
    378. //return sucNum;
    379. return errorFileds;
    380. }
    381. /// <summary>
    382. /// 读取欧姆龙PLC的状态
    383. /// </summary>
    384. /// <param name="siemens"></param>
    385. /// <param name="ip">IP地址</param>
    386. /// <param name="port">端口</param>
    387. /// <param name="point">PLC点位</param>
    388. /// <returns></returns>
    389. public bool ReadBoolByOmron1(OmronFinsNet omron, string ip, int port, string point)
    390. {
    391. if (ConnectOmron(omron, ip, port))
    392. {
    393. OperateResult<bool> value = omron.ReadBool(point);
    394. omron.ConnectClose();
    395. return value.Content;
    396. }
    397. else
    398. {
    399. return false;
    400. }
    401. }
    402. //读取float型数据
    403. public float ReadFloatByOmron(OmronFinsNet omron, string ip, int port, string point)
    404. {
    405. //if (ConnectOmron(omron, ip, port))
    406. //{
    407. OperateResult<float> value = omron.ReadFloat(point);
    408. if (!value.IsSuccess)
    409. {
    410. for (int i = 0;i < 3;i++)
    411. {
    412. value = omron.ReadFloat(point);
    413. if (value.IsSuccess)
    414. {
    415. break;
    416. //return value.Content;
    417. }
    418. }
    419. //if (!value.IsSuccess)
    420. //{
    421. // return 0;
    422. //}
    423. }
    424. //omron.ConnectClose();
    425. if (value.IsSuccess)
    426. {
    427. return value.Content;
    428. }
    429. else
    430. {
    431. return 0;
    432. }
    433. //}
    434. //else
    435. //{
    436. // return 0;
    437. //}
    438. }
    439. //读取short型数据
    440. public short ReadShortByOmron(OmronFinsNet omron, string ip, int port, string point)
    441. {
    442. //if (ConnectOmron(omron, ip, port))
    443. //{
    444. OperateResult<short> value = omron.ReadInt16(point);
    445. if (!value.IsSuccess)
    446. {
    447. for (int i = 0; i < 3; i++)
    448. {
    449. value = omron.ReadInt16(point);
    450. if (value.IsSuccess)
    451. {
    452. break;
    453. //return value.Content;
    454. }
    455. }
    456. //if (!value.IsSuccess)
    457. //{
    458. // return 0;
    459. //}
    460. }
    461. //omron.ConnectClose();
    462. if (value.IsSuccess)
    463. {
    464. return value.Content;
    465. }
    466. else
    467. {
    468. return 0;
    469. }
    470. //}
    471. //else
    472. //{
    473. // return 0;
    474. //}
    475. }
    476. //读取Bool类型数据
    477. public bool ReadBoolByOmron(OmronFinsNet omron, string ip, int port, string point)
    478. {
    479. OperateResult<bool> value = omron.ReadBool(point);
    480. if (!value.IsSuccess)
    481. {
    482. for (int i = 0; i < 3; i++)
    483. {
    484. value = omron.ReadBool(point);
    485. if (value.IsSuccess)
    486. {
    487. break;
    488. }
    489. }
    490. }
    491. if (value.IsSuccess)
    492. {
    493. return value.Content;
    494. }
    495. else
    496. {
    497. return false;
    498. }
    499. }
    500. public string ReadPointByOmron(OmronFinsNet omron, string ip, int port, List<string> filedlst, List<string> pointlst, List<string> datatypelst)
    501. {
    502. string result = "0";
    503. JObject jObj = new JObject();
    504. try
    505. {
    506. if (ConnectOmron(omron, ip, port))
    507. {
    508. for (int i = 0; i < pointlst.Count; i++)
    509. {
    510. if (datatypelst[i] == "FLOAT")
    511. {
    512. result = ReadFloatByOmron(omron, ip, port, pointlst[i]).ToString();
    513. }
    514. else if (datatypelst[i] == "SHORT")
    515. {
    516. result = ReadShortByOmron(omron, ip, port, pointlst[i]).ToString();
    517. }
    518. else if (datatypelst[i] == "BOOL" && pointlst[i] == "H10")
    519. {
    520. //涂布单双面3个点位细分—00:单面,01:双面,0102:连续
    521. bool res = false;
    522. List<string> H10s = new List<string>() { "H10.00", "H10.01", "H10.02" };
    523. foreach (string h10 in H10s)
    524. {
    525. res = ReadBoolByOmron(omron, ip, port, h10);
    526. if (res)
    527. {
    528. result = h10.Substring(h10.Length - 1,1);
    529. break;
    530. }
    531. }
    532. }
    533. jObj.Add(new JProperty(filedlst[i], result));
    534. }
    535. }
    536. }
    537. catch (Exception ex)
    538. {
    539. LogHelper.WriteErrLog(ex.ToString());
    540. }
    541. finally
    542. {
    543. omron.ConnectClose();
    544. }
    545. return jObj.ToString();
    546. }
    547. /// <summary>
    548. /// 读取欧姆龙PLC的值
    549. /// </summary>
    550. /// <param name="siemens"></param>
    551. /// <param name="ip">IP地址</param>
    552. /// <param name="port">端口</param>
    553. /// <param name="point">PLC点位</param>
    554. /// <param name="length">读取长度</param>
    555. /// <returns></returns>
    556. public string ReadStringByOmron(OmronFinsNet omron, string ip, int port, string point, ushort length)
    557. {
    558. if (ConnectOmron(omron, ip, port))
    559. {
    560. OperateResult<string> result = new OperateResult<string>();
    561. result = omron.ReadString(point, length);
    562. string source = string.Empty;
    563. if (!string.IsNullOrEmpty(result.Content))
    564. {
    565. source = result.Content;
    566. }
    567. else
    568. {
    569. for (int i = 0; i < 3; i++)
    570. {
    571. Thread.Sleep(10);
    572. result = omron.ReadString(point, length);
    573. if (!string.IsNullOrEmpty(result.Content))
    574. {
    575. source = result.Content;
    576. break;
    577. }
    578. }
    579. if (string.IsNullOrEmpty(result.Content))
    580. {
    581. return "未读取到PLC信息";
    582. }
    583. }
    584. omron.ConnectClose();
    585. return source;
    586. }
    587. else
    588. {
    589. return "false";
    590. }
    591. }
    592. /// <summary>
    593. /// 清空欧姆龙PLC点位中的值
    594. /// </summary>
    595. /// <param name="siemens"></param>
    596. /// <param name="ip"></param>
    597. /// <param name="port"></param>
    598. /// <param name="point"></param>
    599. /// <param name="length">写入的长度</param>
    600. /// <returns></returns>
    601. public bool ClearPlcPocketByOmron(OmronFinsNet omron, string ip, int port, string point, int length, string flag = " ")
    602. {
    603. if (ConnectOmron(omron, ip, port))
    604. {
    605. OperateResult result = omron.Write(point, flag, length);
    606. omron.ConnectClose();
    607. return result.IsSuccess;
    608. }
    609. else
    610. {
    611. return false;
    612. }
    613. }
    614. #endregion
    615. #region 连接基恩士PLC--KeyenceMcNet
    616. /// <summary>
    617. /// 连接基恩士PLC--KeyenceMcNet
    618. /// </summary>
    619. /// <param name="omron"></param>
    620. /// <param name="ip"></param>
    621. /// <param name="port"></param>
    622. /// <returns></returns>
    623. private bool ConnectKeyence(KeyenceMcNet keyence, string ip, int port)
    624. {
    625. try
    626. {
    627. IPAddress ipaddress;
    628. bool flag = !IPAddress.TryParse(ip, out ipaddress);
    629. if (flag)
    630. {
    631. return false;
    632. }
    633. else
    634. {
    635. keyence.IpAddress = ip;
    636. keyence.Port = port;
    637. OperateResult operateResult = keyence.ConnectServer();
    638. bool isSuccess = operateResult.IsSuccess;
    639. if (isSuccess)
    640. {
    641. return true;
    642. }
    643. else
    644. {
    645. return false;
    646. }
    647. }
    648. }
    649. catch (Exception)
    650. {
    651. return false;
    652. }
    653. }
    654. /// <summary>
    655. /// 给基恩士PLC点位写信号
    656. /// </summary>
    657. /// <param name="siemens"></param>
    658. /// <param name="ip">IP地址</param>
    659. /// <param name="port">端口</param>
    660. /// <param name="point">PLC点位</param>
    661. /// <param name="flag">给点位传入的值</param>
    662. /// <returns></returns>
    663. public bool WriteFlagByKeyence(KeyenceMcNet keyence, string ip, int port, string point, short flag)
    664. {
    665. if (ConnectKeyence(keyence, ip, port))
    666. {
    667. OperateResult result = keyence.Write(point, flag);
    668. keyence.ConnectClose();
    669. return result.IsSuccess;
    670. }
    671. else
    672. {
    673. return false;
    674. }
    675. }
    676. /// <summary>
    677. /// 读取基恩士PLC的状态
    678. /// </summary>
    679. /// <param name="siemens"></param>
    680. /// <param name="ip">IP地址</param>
    681. /// <param name="port">端口</param>
    682. /// <param name="point">PLC点位</param>
    683. /// <returns></returns>
    684. public bool ReadBoolByKeyence(KeyenceMcNet keyence, string ip, int port, string point)
    685. {
    686. if (ConnectKeyence(keyence, ip, port))
    687. {
    688. OperateResult<bool> value = keyence.ReadBool(point);
    689. keyence.ConnectClose();
    690. return value.Content;
    691. }
    692. else
    693. {
    694. return false;
    695. }
    696. }
    697. /// <summary>
    698. /// 读取基恩士PLC的值
    699. /// </summary>
    700. /// <param name="siemens"></param>
    701. /// <param name="ip">IP地址</param>
    702. /// <param name="port">端口</param>
    703. /// <param name="point">PLC点位</param>
    704. /// <param name="length">读取长度</param>
    705. /// <returns></returns>
    706. public string ReadStringByKeyence(KeyenceMcNet keyence, string ip, int port, string point, ushort length)
    707. {
    708. if (ConnectKeyence(keyence, ip, port))
    709. {
    710. OperateResult<string> result = new OperateResult<string>();
    711. result = keyence.ReadString(point, length);
    712. string source = string.Empty;
    713. if (!string.IsNullOrEmpty(result.Content))
    714. {
    715. source = result.Content;
    716. }
    717. else
    718. {
    719. for (int i = 0; i < 3; i++)
    720. {
    721. Thread.Sleep(10);
    722. result = keyence.ReadString(point, length);
    723. if (!string.IsNullOrEmpty(result.Content))
    724. {
    725. source = result.Content;
    726. break;
    727. }
    728. }
    729. if (string.IsNullOrEmpty(result.Content))
    730. {
    731. return "未读取到PLC信息";
    732. }
    733. }
    734. keyence.ConnectClose();
    735. return source;
    736. }
    737. else
    738. {
    739. return "false";
    740. }
    741. }
    742. /// <summary>
    743. /// 清空基恩士PLC点位中的值
    744. /// </summary>
    745. /// <param name="siemens"></param>
    746. /// <param name="ip"></param>
    747. /// <param name="port"></param>
    748. /// <param name="point"></param>
    749. /// <param name="length">写入的长度</param>
    750. /// <returns></returns>
    751. public bool ClearPlcPocketByKeyence(KeyenceMcNet keyence, string ip, int port, string point, int length, string flag = " ")
    752. {
    753. if (ConnectKeyence(keyence, ip, port))
    754. {
    755. OperateResult result = keyence.Write(point, flag, length);
    756. keyence.ConnectClose();
    757. return result.IsSuccess;
    758. }
    759. else
    760. {
    761. return false;
    762. }
    763. }
    764. #endregion
    765. }
    766. }

  • 相关阅读:
    超纯水制备
    【unity实战】unity3D中的PRG库存系统和换装系统(附项目源码)
    [附源码]计算机毕业设计基于JEE平台springboot技术的订餐系统
    PLT hook 方案 PLT hook
    【java苍穹外卖项目实战三】nginx反向代理和负载均衡
    华为云云耀云服务器L实例评测|华为云云耀云服务器L实例开展性能评测
    时空智友企业信息管理系统任意文件读取漏洞复现
    7、使用Maven:IDEA环境
    非零基础自学Java (老师:韩顺平) 第5章 程序控制结构 5.7 for循环控制
    Pytorch单机多卡分布式训练
  • 原文地址:https://blog.csdn.net/weixin_50478033/article/details/133141855