|
- 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();
-
- 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);
- }
- }
- }
|