ManiPort.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using System;
  2. using System.Threading;
  3. using SHJX.Service.Model.Control;
  4. using SHJX.Service.Common.Extend;
  5. using SHJX.Service.Common.ReadXML;
  6. using SHJX.Service.ServerClient.Interface;
  7. using SHJX.Service.ServerClient.TempController;
  8. using SHJX.Service.Common.Logging;
  9. using Microsoft.Extensions.Logging;
  10. namespace SHJX.Service.ServerClient.RS485Control
  11. {
  12. /// <summary>
  13. /// 机械手操作
  14. /// </summary>
  15. public class ManiPort : SerialPortImp, PortControlImp
  16. {
  17. private static readonly ILogger logger = LogFactory.BuildLogger(typeof(ManiPort));
  18. /// <summary>
  19. /// 机械手
  20. /// </summary>
  21. /// <param name="log">日志</param>
  22. /// <param name="config">配置</param>
  23. public ManiPort(ReadConfigUtil config)
  24. : base(config) { }
  25. public bool Write(PortArgs args)
  26. {
  27. var res = args.WriteWay switch
  28. {
  29. WriteWay.Normotopia => zMotorStorage(args, "H"),
  30. WriteWay.Antiposition => zMotorStorage(args, "L"),
  31. _ => throw new ArgumentNullException(args.WriteWay.GetEnumDesc<WriteWay>())
  32. };
  33. Thread.Sleep(500);
  34. return res;
  35. }
  36. public object Read(PortArgs args)
  37. {
  38. object obj = args.ReadWay switch
  39. {
  40. "Judge" => GetJudge(args),
  41. "OriginalPosition" => JudgeStorage(args.NodeId),
  42. _ => throw new ArgumentNullException(args.ReadWay),
  43. };
  44. return obj;
  45. }
  46. public bool GetJudge(PortArgs args)
  47. {
  48. var storageRes = JudgeStorage(args.NodeId);
  49. if (storageRes is null) return false;
  50. var res = storageRes[4].Equals('0');
  51. return res;
  52. }
  53. private bool zMotorStorage(PortArgs args,string op)
  54. {
  55. string res1 = "";
  56. while (res1 != "0009\r" && res1 != "0209\r")
  57. {
  58. var storageRes = JudgeXYZMove(3); //抓手动之前Z轴要静止
  59. if (storageRes.Equals("")) return false;
  60. res1 = storageRes;
  61. Thread.Sleep(300);
  62. }
  63. return MotorStorage(args.NodeId, 1, op);
  64. }
  65. }
  66. }