TimerPort.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using System.Threading;
  2. using System;
  3. using SHJX.Service.Model.Control;
  4. using SHJX.Service.Common.ReadXML;
  5. using SHJX.Service.ServerClient.Interface;
  6. using SHJX.Service.ServerClient.TempController;
  7. using SHJX.Service.Common.Logging;
  8. using Microsoft.Extensions.Logging;
  9. namespace SHJX.Service.ServerClient.RS485Control
  10. {
  11. public class TimerPort : SerialPortImp, PortControlImp
  12. {
  13. private static readonly ILogger logger = LogFactory.BuildLogger(typeof(TimerPort));
  14. /// <summary>
  15. /// 计时器
  16. /// </summary>
  17. /// <param name="log">日志</param>
  18. /// <param name="config">配置</param>
  19. public TimerPort( ReadConfigUtil config)
  20. : base( config) { }
  21. public object Read(PortArgs args)
  22. {
  23. object res = null;
  24. switch (args.ReadWay)
  25. {
  26. case "Judge":
  27. res = JudgeStorage(args.NodeId)?[7].Equals('0');
  28. break;
  29. }
  30. return res;
  31. }
  32. public bool Write(PortArgs args)
  33. {
  34. var way = args.WriteWay switch
  35. {
  36. WriteWay.Start => "L",
  37. WriteWay.Stop => "H",
  38. _ => throw new ArgumentNullException()
  39. };
  40. return zMotorStorage(args, way);
  41. }
  42. private bool zMotorStorage(PortArgs args, string op)
  43. {
  44. string res1 = "";
  45. while (res1 != "0009\r" && res1 != "0209\r")
  46. {
  47. var storageRes = JudgeXYZMove(4);
  48. if (storageRes.Equals("")) return false;
  49. res1 = storageRes;
  50. Thread.Sleep(300);
  51. }
  52. return MotorStorage(args.NodeId, 4, op);
  53. }
  54. }
  55. }