OptCommand.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. namespace SHJX.Service.PortClient
  2. {
  3. public class OptCommand
  4. {
  5. private static readonly ConcurrentDictionary<ArgType, IPortCommand> _commands = new();
  6. public OptCommand() { }
  7. public IPortCommand Factory(ArgType way)
  8. {
  9. if (_commands.TryGetValue(way, out IPortCommand currentclient))
  10. {
  11. return currentclient;
  12. }
  13. IPortCommand port = way switch
  14. {
  15. ArgType.Move => new MovePortCommand(),
  16. ArgType.GoBack => new GoBackPortCommand(),
  17. ArgType.Stop => new StopPortCommand(),
  18. ArgType.Inversion => new InversionPortCommand(),
  19. ArgType.Speed => new SpeedPortCommand(),
  20. ArgType.AcSpeed => new AcSpeedPortCommand(),
  21. ArgType.DeSpeed => new DeSpeedPortCommand(),
  22. ArgType.Open => new OpenPortCommand(),
  23. ArgType.Close => new ClosePortCommand(),
  24. ArgType.Read => new ReadPortCommand(),
  25. ArgType.HeatRead => new HeatingReadPortCommand(),
  26. ArgType.Pid => new PidPortCommand(),
  27. ArgType.Temp => new TemperaturePortCommand(),
  28. ArgType.Humiture => new HumiturePortCommand(),
  29. ArgType.Ratio => new RatioPortCommand(),
  30. ArgType.Integral => new IntegralPortCommand(),
  31. ArgType.Differential => new DifferentialPortCommand(),
  32. ArgType.IntegralDeafult => new IntegralDeafultPortCommand(),
  33. _ => throw new ArgumentException("未找到对应的枚举")
  34. };
  35. _commands.TryAdd(way, port);
  36. return port;
  37. }
  38. }
  39. }