|
- 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
- {
- /// <summary>
- /// 炒锅服务类
- /// </summary>
- internal class FryingPanServer : FryingPanSet, IModbus
- {
- public FryingPanServer()
- {
- //MyModbus = new ModbusTcp();
- }
- public void Init(string IP = "", int Port = 502, string PortName = "")
- {
- //MyModbus = new ModbusTcp();
-
- CommHelper.CreateModbusTcp(IP, Port).OnSuccess(S =>
- {
- MyModbus = S.Content;
- TaskManage.GetInstance.StartLong(new Action(() =>
- {
- MyModbus.ReadCoil("LB100".ToModbusAdd(), 16).OnSuccess(s =>
- {
- InitComplete = s.Content[0];
- StatusMode = s.Content[1];
- EStop = s.Content[2];
- FeedingSeasoningLocFB = s.Content[3];
- for (byte i = 0; i < 3; i++) StirFryingLocFB[i] = s.Content[i + 4];
-
- DiningOutLocFB = s.Content[7];
- FeedingLocFB = s.Content[8];
- WashingPotLocFB = s.Content[9];
-
- for (byte i = 0; i < 3; i++) ChannelDisCom[i] = s.Content[i + 10];
-
- CleanFinish = s.Content[13];
- OutDinningFinsh = s.Content[14];
- OutDinningSlowDownFlag = s.Content[15];
- });
-
- Thread.Sleep(20);
- MyModbus.ReadHoldRegister<ushort[]>("LW20".ToModbusAdd(), 3).OnSuccess(s =>
- {
- CurrentTemperature = s.Content[0] * 10.0F;
- CurrentSpeed = s.Content[1];
- HeatingGear = s.Content[2];
- });
- Thread.Sleep(20);
- MyModbus.ReadHoldRegister<ushort[]>("LW30".ToModbusAdd(), 10).OnSuccess(s =>
- {
- StirMotorFreq = s.Content[0];
- StirMotorCurrent = s.Content[1];
- StirMotorVoltage = s.Content[2];
- StirMotorTemprature = s.Content[3];
- StirMotorErrorCode = MotorAlarm.AlarmDic[s.Content[4]];
-
- TurnMotorFreq = s.Content[5];
- TurnMotorCurrent = s.Content[6];
- TurnMotorVoltage = s.Content[7];
- TurnMotorTemprature = s.Content[8];
- TurnMotorErrorCode = MotorAlarm.AlarmDic[s.Content[9]];
-
- });
- Thread.Sleep(20);
- MyModbus.ReadHoldRegister<ushort>("LW49".ToModbusAdd()).OnSuccess(s =>
- {
- EStopAlarm = s.Content.GetBitValue(1);
-
- FryingPanFowardLimit = s.Content.GetBitValue(3);
- FryingPanReverseLimit = s.Content.GetBitValue(4);
- FryingPanEncoderCommError = s.Content.GetBitValue(5);
-
- StirMotorCommError = s.Content.GetBitValue(7);
- RollingMotorCommError = s.Content.GetBitValue(8);
- });
- Thread.Sleep(20);
- }), $"炒锅服务-{IP}", true);
- });
-
-
- //MyModbus.WithModbusTcp(IP, Port).UseConnected(() =>
- //{
- // ((ModbusTcp)MyModbus).master.Transport.ReadTimeout = 3000;
- // ((ModbusTcp)MyModbus).master.Transport.WriteTimeout = 3000;
- // TaskManage.GetInstance.StartLong(new Action(() =>
- // {
- // MyModbus.Read<bool[]>("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];
- // });
-
- // Thread.Sleep(20);
- // MyModbus.Read<ushort[]>("LW20".ToModbusAdd(), 3).OnSuccess(s =>
- // {
- // CurrentTemperature = s[0] * 10.0F;
- // CurrentSpeed = s[1];
- // HeatingGear = s[2];
- // });
- // Thread.Sleep(20);
- // MyModbus.Read<ushort[]>("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]];
-
- // });
- // Thread.Sleep(20);
- // MyModbus.Read<ushort>("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(20);
- // }), $"炒锅服务-{IP}", true);
- //});
- }
- /// <summary>
- /// 手动写值
- /// </summary>
- /// <typeparam name="T">值类型</typeparam>
- /// <param name="address">地址</param>
- /// <param name="value">值</param>
- public void WriteValue<T>(string address, T value)
- {
- MyModbus?.Write<T>(address.ToModbusAdd(), value);
- }
- }
- }
|