FanucServer.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. using FANUC;
  2. using fanuc采集;
  3. using HttpServer;
  4. using RequestServer.HttpServer;
  5. using ResponseServer.HttpServer;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using static fanuc采集.ConDevice;
  12. using static HttpServer.Form1;
  13. namespace Fanuc_HttpServer.fanuc
  14. {
  15. class FanucServer
  16. {
  17. private static string ON_LINE_STATE = "在线";
  18. public static ResponseBody requestHttpServer(RequestBody requestBody)
  19. {
  20. string ip = requestBody.serverUrl;
  21. string port = requestBody.port;
  22. string fun = requestBody.type;
  23. int ret = 0;
  24. ConDevice CIF = new ConDevice();
  25. ResponseBody responseBody = new ResponseBody();
  26. if (fun == ActionTypeEnum.Collect.ToString())
  27. {
  28. ConDevice2 CIF2 = new ConDevice2(ip, port);
  29. if (CIF2.h > 0)
  30. {
  31. responseBody.mainProg = CIF2.MainProg();
  32. responseBody.actFeed = CIF2.FeedSpeed();
  33. responseBody.actSpindle = CIF2.ActSpindle();
  34. responseBody.spindleMagnification = CIF2.spindleMagnification();
  35. responseBody.powerOnTime = CIF2.PowerOnTime();
  36. responseBody.deviceState = ON_LINE_STATE;
  37. CIF2.freehand();
  38. }
  39. else
  40. {
  41. responseBody.msg = "调用失败";
  42. }
  43. }
  44. else if (fun == ActionTypeEnum.Upload.ToString())
  45. {
  46. try
  47. {
  48. string prgname = requestBody.prgName;
  49. YG.Log.Instance.WriteLogAdd(">>>===上传文件名 : >>>>===" + prgname);
  50. ret = CIF.UploadNcProg(ip, port, prgname);
  51. if (ret == Fanuc.EW_OK)
  52. {
  53. responseBody.deviceState = ON_LINE_STATE;
  54. }
  55. else
  56. {
  57. responseBody.msg = "上传文件名失败,错误码:" + ret;
  58. }
  59. }
  60. catch (Exception uploadex)
  61. {
  62. responseBody.msg = "上传文件名" + uploadex.Message;
  63. }
  64. }
  65. else if (fun == ActionTypeEnum.StartNcProgram.ToString())
  66. {
  67. try
  68. {
  69. string prgname = requestBody.prgName;
  70. ret = CIF.ReadPmcMarco(ip, port, prgname);
  71. if (ret == Fanuc.EW_OK)
  72. {
  73. responseBody.deviceState = ON_LINE_STATE;
  74. }
  75. else
  76. {
  77. responseBody.msg = "调用失败";
  78. }
  79. }
  80. catch (Exception uploadex)
  81. {
  82. responseBody.msg = "调用失败" + uploadex.Message;
  83. }
  84. }
  85. else if (fun == ActionTypeEnum.AlmInfo.ToString())
  86. {
  87. try
  88. {
  89. List<ConDevice.AlmInfo> allAlmList = new List<AlmInfo>();
  90. ConDevice2 con2 = new ConDevice2(ip, port);
  91. //实时报警
  92. List<ConDevice.AlmInfo> alms = con2.operationAlarm();
  93. //信息履历
  94. List<ConDevice.AlmInfo> almLL = con2.rdalmhistry5();
  95. if (alms != null && alms.Count() > 0)
  96. {
  97. allAlmList.AddRange(alms);
  98. }
  99. if (almLL != null && almLL.Count() > 0)
  100. {
  101. allAlmList.AddRange(almLL);
  102. }
  103. responseBody.deviceState = ON_LINE_STATE;
  104. con2.freehand();
  105. }
  106. catch (Exception ex)
  107. {
  108. responseBody.msg = "获取报警失败:" + ex.Message;
  109. }
  110. }
  111. return responseBody;
  112. }
  113. }
  114. }