using System; using System.Threading; using SHJX.Service.Common.Extend; using SHJX.Service.Common.ReadXML; using SHJX.Service.Model.Control; using SHJX.Service.ServerClient.Interface; using SHJX.Service.ServerClient.TempController; using SHJX.Service.Common.Logging; using Microsoft.Extensions.Logging; namespace SHJX.Service.ServerClient.RS485Control { /// /// Y轴操作 /// public class MotorYPort : SerialPortImp, PortControlImp { private static readonly ILogger logger = LogFactory.BuildLogger(typeof(MotorYPort)); /// /// Y轴 /// /// 日志 /// 配置 /// public MotorYPort( ReadConfigUtil config) : base( config) { config.GetSpeed.ForEach(item=> { if (item.NodeName == "MotorY") speedY = item.Speed; }); } private double speedY = 0; public object Read(PortArgs args) { object obj = args.ReadWay switch { "OriginalPosition" => ReadOriginalPosition(args.NodeId), _ => JudgeStorage(args.NodeId), }; return obj; } private bool ReadOriginalPosition(byte NodeId) { var res = JudgeStorage(NodeId); if (res is null or { Length: 0 }) return false; return res[7].Equals('0'); } public bool Write(PortArgs args) { var res = args.WriteWay switch { WriteWay.Move => yMove(args), WriteWay.GoBack => yMotorGoBack(args), WriteWay.Stop => MotorStop(args.NodeId), WriteWay.Speed => MotorSpeed(args.NodeId, args.Distance), WriteWay.AcSpeed => MotorAcSpeed(args.NodeId, args.Distance), WriteWay.DeSpeed => MotorDeSpeed(args.NodeId, args.Distance), _ => throw new ArgumentNullException(args.WriteWay.GetEnumDesc()), }; return res; } private bool yMove(PortArgs args) { bool res = true; //var judgeRes = JudgeStorage(3); //if (judgeRes is null || judgeRes.Length < 1) // return false; //if (!judgeRes[3 - 1].Equals('0')) //{ // res = MotorGoBack(3, 3); //} return res && Move(args.NodeId, args.Distance, 50, speedY); } private bool yMotorGoBack(PortArgs args) { bool res = true; //var judgeRes = JudgeStorage(3); //if (judgeRes is null || judgeRes.Length < 1) // return false; //if (!judgeRes[3 - 1].Equals('0')) //{ // res = MotorGoBack(3, 3); //} return res && MotorGoBack(args.NodeId, 8); } } }