终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

164 lines
6.6 KiB

  1. using BPASmartClient.MorkCL.Model.Control;
  2. using MySqlConnector;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace BPASmartClient.MorkCL.Server
  9. {
  10. /// <summary>
  11. /// 炒锅服务类
  12. /// </summary>
  13. internal class FryingPanServer : FryingPanSet, IModbus
  14. {
  15. public FryingPanServer()
  16. {
  17. //MyModbus = new ModbusTcp();
  18. }
  19. public void Init(string IP = "", int Port = 502, string PortName = "")
  20. {
  21. //MyModbus = new ModbusTcp();
  22. CommHelper.CreateModbusTcp(IP, Port).OnSuccess(S =>
  23. {
  24. MyModbus = S.Content;
  25. TaskManage.GetInstance.StartLong(new Action(() =>
  26. {
  27. MyModbus.ReadCoil("LB100".ToModbusAdd(), 16).OnSuccess(s =>
  28. {
  29. InitComplete = s.Content[0];
  30. StatusMode = s.Content[1];
  31. EStop = s.Content[2];
  32. FeedingSeasoningLocFB = s.Content[3];
  33. for (byte i = 0; i < 3; i++) StirFryingLocFB[i] = s.Content[i + 4];
  34. DiningOutLocFB = s.Content[7];
  35. FeedingLocFB = s.Content[8];
  36. WashingPotLocFB = s.Content[9];
  37. for (byte i = 0; i < 3; i++) ChannelDisCom[i] = s.Content[i + 10];
  38. CleanFinish = s.Content[13];
  39. OutDinningFinsh = s.Content[14];
  40. OutDinningSlowDownFlag = s.Content[15];
  41. });
  42. Thread.Sleep(20);
  43. MyModbus.ReadHoldRegister<ushort[]>("LW20".ToModbusAdd(), 3).OnSuccess(s =>
  44. {
  45. CurrentTemperature = s.Content[0] * 10.0F;
  46. CurrentSpeed = s.Content[1];
  47. HeatingGear = s.Content[2];
  48. });
  49. Thread.Sleep(20);
  50. MyModbus.ReadHoldRegister<ushort[]>("LW30".ToModbusAdd(), 10).OnSuccess(s =>
  51. {
  52. StirMotorFreq = s.Content[0];
  53. StirMotorCurrent = s.Content[1];
  54. StirMotorVoltage = s.Content[2];
  55. StirMotorTemprature = s.Content[3];
  56. StirMotorErrorCode = MotorAlarm.AlarmDic[s.Content[4]];
  57. TurnMotorFreq = s.Content[5];
  58. TurnMotorCurrent = s.Content[6];
  59. TurnMotorVoltage = s.Content[7];
  60. TurnMotorTemprature = s.Content[8];
  61. TurnMotorErrorCode = MotorAlarm.AlarmDic[s.Content[9]];
  62. });
  63. Thread.Sleep(20);
  64. MyModbus.ReadHoldRegister<ushort>("LW49".ToModbusAdd()).OnSuccess(s =>
  65. {
  66. EStopAlarm = s.Content.GetBitValue(1);
  67. FryingPanFowardLimit = s.Content.GetBitValue(3);
  68. FryingPanReverseLimit = s.Content.GetBitValue(4);
  69. FryingPanEncoderCommError = s.Content.GetBitValue(5);
  70. StirMotorCommError = s.Content.GetBitValue(7);
  71. RollingMotorCommError = s.Content.GetBitValue(8);
  72. });
  73. Thread.Sleep(20);
  74. }), $"炒锅服务-{IP}", true);
  75. });
  76. //MyModbus.WithModbusTcp(IP, Port).UseConnected(() =>
  77. //{
  78. // ((ModbusTcp)MyModbus).master.Transport.ReadTimeout = 3000;
  79. // ((ModbusTcp)MyModbus).master.Transport.WriteTimeout = 3000;
  80. // TaskManage.GetInstance.StartLong(new Action(() =>
  81. // {
  82. // MyModbus.Read<bool[]>("LB100".ToModbusAdd(), 16).OnSuccess(s =>
  83. // {
  84. // InitComplete = s[0];
  85. // StatusMode = s[1];
  86. // EStop = s[2];
  87. // FeedingSeasoningLocFB = s[3];
  88. // for (byte i = 0; i < 3; i++) StirFryingLocFB[i] = s[i + 4];
  89. // DiningOutLocFB = s[7];
  90. // FeedingLocFB = s[8];
  91. // WashingPotLocFB = s[9];
  92. // for (byte i = 0; i < 3; i++) ChannelDisCom[i] = s[i + 10];
  93. // CleanFinish = s[13];
  94. // OutDinningFinsh = s[14];
  95. // OutDinningSlowDownFlag = s[15];
  96. // });
  97. // Thread.Sleep(20);
  98. // MyModbus.Read<ushort[]>("LW20".ToModbusAdd(), 3).OnSuccess(s =>
  99. // {
  100. // CurrentTemperature = s[0] * 10.0F;
  101. // CurrentSpeed = s[1];
  102. // HeatingGear = s[2];
  103. // });
  104. // Thread.Sleep(20);
  105. // MyModbus.Read<ushort[]>("LW30".ToModbusAdd(), 10).OnSuccess(s =>
  106. // {
  107. // StirMotorFreq = s[0];
  108. // StirMotorCurrent = s[1];
  109. // StirMotorVoltage = s[2];
  110. // StirMotorTemprature = s[3];
  111. // StirMotorErrorCode = MotorAlarm.AlarmDic[s[4]];
  112. // TurnMotorFreq = s[5];
  113. // TurnMotorCurrent = s[6];
  114. // TurnMotorVoltage = s[7];
  115. // TurnMotorTemprature = s[8];
  116. // TurnMotorErrorCode = MotorAlarm.AlarmDic[s[9]];
  117. // });
  118. // Thread.Sleep(20);
  119. // MyModbus.Read<ushort>("LW49".ToModbusAdd()).OnSuccess(s =>
  120. // {
  121. // EStopAlarm = s.GetBitValue(1);
  122. // FryingPanFowardLimit = s.GetBitValue(3);
  123. // FryingPanReverseLimit = s.GetBitValue(4);
  124. // FryingPanEncoderCommError = s.GetBitValue(5);
  125. // StirMotorCommError = s.GetBitValue(7);
  126. // RollingMotorCommError = s.GetBitValue(8);
  127. // });
  128. // Thread.Sleep(20);
  129. // }), $"炒锅服务-{IP}", true);
  130. //});
  131. }
  132. /// <summary>
  133. /// 手动写值
  134. /// </summary>
  135. /// <typeparam name="T">值类型</typeparam>
  136. /// <param name="address">地址</param>
  137. /// <param name="value">值</param>
  138. public void WriteValue<T>(string address, T value)
  139. {
  140. MyModbus?.Write<T>(address.ToModbusAdd(), value);
  141. }
  142. }
  143. }