using BPASmartClient.MorkCL.Model.Control; using MySqlConnector; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace BPASmartClient.MorkCL.Server { /// /// 炒锅服务类 /// internal class FryingPanServer : FryingPanSet, IModbus { public void Init(string IP = "", int Port = 502, string PortName = "") { MyModbus = new ModbusTcp(); MyModbus.WithModbusTcp(IP, Port).UseConnected(() => { TaskManage.GetInstance.StartLong(new Action(() => { MyModbus.Read("LB100".ToModbusAdd(), 16).OnSuccess(s => { InitComplete = s[0]; StatusMode = s[1]; EStop = s[2]; FeedingSeasoningLocFB = s[3]; for (byte i = 0; i < 3; i++) StirFryingLocFB[i] = s[i + 4]; DiningOutLocFB = s[7]; FeedingLocFB = s[8]; WashingPotLocFB = s[9]; for (byte i = 0; i < 3; i++) ChannelDisCom[i] = s[i + 10]; CleanFinish = s[13]; OutDinningFinsh = s[14]; OutDinningSlowDownFlag = s[15]; }); MyModbus.Read("LW20".ToModbusAdd(), 3).OnSuccess(s => { CurrentTemperature = s[0] * 10.0F; CurrentSpeed = s[1]; HeatingGear = s[2]; }); MyModbus.Read("LW30".ToModbusAdd(), 10).OnSuccess(s => { StirMotorFreq = s[0]; StirMotorCurrent = s[1]; StirMotorVoltage = s[2]; StirMotorTemprature = s[3]; StirMotorErrorCode = MotorAlarm.AlarmDic[s[4]]; TurnMotorFreq = s[5]; TurnMotorCurrent = s[6]; TurnMotorVoltage = s[7]; TurnMotorTemprature = s[8]; TurnMotorErrorCode = MotorAlarm.AlarmDic[s[9]]; }); MyModbus.Read("LW49".ToModbusAdd()).OnSuccess(s => { EStopAlarm = s.GetBitValue(1); FryingPanFowardLimit=s.GetBitValue(3); FryingPanReverseLimit=s.GetBitValue(4); FryingPanEncoderCommError=s.GetBitValue(5); StirMotorCommError=s.GetBitValue(7); RollingMotorCommError = s.GetBitValue(8); }); Thread.Sleep(100); }), $"炒锅服务-{IP}", true); }); } /// /// 手动写值 /// /// 值类型 /// 地址 /// 值 public void WriteValue (string address, T value) { MyModbus?.Write(address.ToModbusAdd(), value); } } }