IDeviceAdapterFactory.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using TeamAAS.Motion.Interfaces;
  7. using TeamAAS.Motion.Models;
  8. using TeamAAS.Motion.Motions;
  9. namespace TeamAAS.Motion.AdapterFactorys
  10. {
  11. public interface IDeviceAdapterFactory
  12. {
  13. /// <summary>
  14. /// 工厂的唯一标识符,必须与配置文件中的 AdapterKey 完全匹配
  15. /// </summary>
  16. string Key { get; }
  17. /// <summary>
  18. /// 根据配置创建设备实例
  19. /// </summary>
  20. IMotionControl Create(MotionDeviceConfig config);
  21. }
  22. // 仿真卡工厂
  23. public class SimulatedDeviceFactory : IDeviceAdapterFactory
  24. {
  25. public string Key => "Simulated";
  26. public IMotionControl Create(MotionDeviceConfig config)
  27. => new SimulatedMotionCard(config);
  28. }
  29. // 汇川卡工厂
  30. public class InovanceDeviceFactory : IDeviceAdapterFactory
  31. {
  32. public string Key => "Inovance";
  33. public IMotionControl Create(MotionDeviceConfig config)
  34. {
  35. // 实例化汇川卡,使用 config.ConnectionString 等参数
  36. return new InovanceMotionCard(config);
  37. }
  38. }
  39. // 雷赛卡工厂
  40. public class LeadshineDeviceFactory : IDeviceAdapterFactory
  41. {
  42. public string Key => "Leadshine";
  43. public IMotionControl Create(MotionDeviceConfig config)
  44. {
  45. // 实例化雷赛卡,使用 config.ConnectionString 等参数
  46. return new LeadshineMotionCard(config);
  47. }
  48. }
  49. }