FanucServer.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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.feedRateOvr = CIF2.GetFeedrate();
  37. responseBody.deviceState = ON_LINE_STATE;
  38. CIF2.freehand();
  39. }
  40. else
  41. {
  42. responseBody.msg = "调用失败";
  43. }
  44. }
  45. else if (fun == ActionTypeEnum.Upload.ToString())
  46. {
  47. try
  48. {
  49. string prgname = requestBody.prgName;
  50. YG.Log.Instance.WriteLogAdd(">>>===上传文件名 : >>>>===" + prgname);
  51. ret = CIF.UploadNcProg(ip, port, prgname);
  52. if (ret == Fanuc.EW_OK)
  53. {
  54. responseBody.deviceState = ON_LINE_STATE;
  55. }
  56. else
  57. {
  58. responseBody.msg = "上传文件名失败,错误码:" + ret;
  59. }
  60. }
  61. catch (Exception uploadex)
  62. {
  63. responseBody.msg = "上传文件名" + uploadex.Message;
  64. }
  65. }
  66. else if (fun == ActionTypeEnum.StartNcProgram.ToString())
  67. {
  68. try
  69. {
  70. string prgname = requestBody.prgName;
  71. ret = CIF.ReadPmcMarco(ip, port, prgname);
  72. if (ret == Fanuc.EW_OK)
  73. {
  74. responseBody.deviceState = ON_LINE_STATE;
  75. }
  76. else
  77. {
  78. responseBody.msg = "调用失败";
  79. }
  80. }
  81. catch (Exception uploadex)
  82. {
  83. responseBody.msg = "调用失败" + uploadex.Message;
  84. }
  85. }
  86. else if (fun == ActionTypeEnum.AlmInfo.ToString())
  87. {
  88. try
  89. {
  90. List<ConDevice.AlmInfo> allAlmList = new List<AlmInfo>();
  91. ConDevice2 con2 = new ConDevice2(ip, port);
  92. //实时报警
  93. List<ConDevice.AlmInfo> alms = con2.operationAlarm();
  94. //信息履历
  95. List<ConDevice.AlmInfo> almLL = con2.rdalmhistry5();
  96. if (alms != null && alms.Count() > 0)
  97. {
  98. allAlmList.AddRange(alms);
  99. }
  100. if (almLL != null && almLL.Count() > 0)
  101. {
  102. allAlmList.AddRange(almLL);
  103. }
  104. responseBody.deviceState = ON_LINE_STATE;
  105. con2.freehand();
  106. }
  107. catch (Exception ex)
  108. {
  109. responseBody.msg = "获取报警失败:" + ex.Message;
  110. }
  111. }
  112. return responseBody;
  113. }
  114. }
  115. }