终端一体化运控平台
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

FryingPanServer.cs 3.6 KiB

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