终端一体化运控平台
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.
 
 
 

93 lines
3.3 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 void Init(string IP = "", int Port = 502, string PortName = "")
  16. {
  17. MyModbus = new ModbusTcp();
  18. MyModbus.WithModbusTcp(IP, Port).UseConnected(() =>
  19. {
  20. TaskManage.GetInstance.StartLong(new Action(() =>
  21. {
  22. MyModbus.Read<bool[]>("LB100".ToModbusAdd(), 16).OnSuccess(s =>
  23. {
  24. InitComplete = s[0];
  25. StatusMode = s[1];
  26. EStop = s[2];
  27. FeedingSeasoningLocFB = s[3];
  28. for (byte i = 0; i < 3; i++) StirFryingLocFB[i] = s[i + 4];
  29. DiningOutLocFB = s[7];
  30. FeedingLocFB = s[8];
  31. WashingPotLocFB = s[9];
  32. for (byte i = 0; i < 3; i++) ChannelDisCom[i] = s[i + 10];
  33. CleanFinish = s[13];
  34. OutDinningFinsh = s[14];
  35. OutDinningSlowDownFlag = s[15];
  36. });
  37. MyModbus.Read<ushort[]>("LW20".ToModbusAdd(), 3).OnSuccess(s =>
  38. {
  39. CurrentTemperature = s[0] * 10.0F;
  40. CurrentSpeed = s[1];
  41. HeatingGear = s[2];
  42. });
  43. MyModbus.Read<ushort[]>("LW30".ToModbusAdd(), 10).OnSuccess(s =>
  44. {
  45. StirMotorFreq = s[0];
  46. StirMotorCurrent = s[1];
  47. StirMotorVoltage = s[2];
  48. StirMotorTemprature = s[3];
  49. StirMotorErrorCode = MotorAlarm.AlarmDic[s[4]];
  50. TurnMotorFreq = s[5];
  51. TurnMotorCurrent = s[6];
  52. TurnMotorVoltage = s[7];
  53. TurnMotorTemprature = s[8];
  54. TurnMotorErrorCode = MotorAlarm.AlarmDic[s[9]];
  55. });
  56. MyModbus.Read<ushort>("LW49".ToModbusAdd()).OnSuccess(s =>
  57. {
  58. EStopAlarm = s.GetBitValue(1);
  59. FryingPanFowardLimit=s.GetBitValue(3);
  60. FryingPanReverseLimit=s.GetBitValue(4);
  61. FryingPanEncoderCommError=s.GetBitValue(5);
  62. StirMotorCommError=s.GetBitValue(7);
  63. RollingMotorCommError = s.GetBitValue(8);
  64. });
  65. Thread.Sleep(100);
  66. }), $"炒锅服务-{IP}", true);
  67. });
  68. }
  69. /// <summary>
  70. /// 手动写值
  71. /// </summary>
  72. /// <typeparam name="T">值类型</typeparam>
  73. /// <param name="address">地址</param>
  74. /// <param name="value">值</param>
  75. public void WriteValue<T> (string address, T value)
  76. {
  77. MyModbus?.Write<T>(address.ToModbusAdd(), value);
  78. }
  79. }
  80. }