| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- 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
- {
- /// <summary>
- /// Y轴操作
- /// </summary>
- public class MotorYPort : SerialPortImp, PortControlImp
- {
- private static readonly ILogger logger = LogFactory.BuildLogger(typeof(MotorYPort));
- /// <summary>
- /// Y轴
- /// </summary>
- /// <param name="log">日志</param>
- /// <param name="config">配置</param>
- ///
- 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<WriteWay>()),
- };
- 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);
- }
- }
- }
|