CagePort.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System;
  2. using System.Threading;
  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. /// <summary>
  12. /// 升降台
  13. /// </summary>
  14. public class CagePort : SerialPortImp, PortControlImp
  15. {
  16. private static readonly ILogger logger = LogFactory.BuildLogger(typeof(CagePort));
  17. /// <summary>
  18. /// 升降台
  19. /// </summary>
  20. /// <param name="log">日志</param>
  21. /// <param name="config">配置</param>
  22. public CagePort( ReadConfigUtil config)
  23. : base( config) { }
  24. public object Read(PortArgs args)
  25. {
  26. object obj = args.ReadWay switch
  27. {
  28. "OriginalPosition" => JudgeStorage(args.NodeId),
  29. _ => throw new ArgumentNullException(args.ReadWay),
  30. };
  31. return obj;
  32. }
  33. public bool Write(PortArgs args)
  34. {
  35. (int address, string way)[] values = args.WriteWay switch
  36. {
  37. WriteWay.Normotopia => new[] { (1, "L"), (2, "H"), (3, "L") },
  38. WriteWay.Antiposition => new[] { (1, "L"), (3, "H"), (2, "L") },
  39. _ => throw new ArgumentNullException("None")
  40. };
  41. var result = true;
  42. for (var i = 0; i < values.Length; i++)
  43. {
  44. var res = MotorStorage(args.NodeId, values[i].address, values[i].way);
  45. result = result && res;
  46. }
  47. Thread.Sleep(5 * 1000);
  48. return result;
  49. }
  50. }
  51. }