综合平台编程器项目的远程存储
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

54 lines
1.6 KiB

  1. #pragma once
  2. #include "plc_communication_gateway.h"
  3. #include <cstddef>
  4. #include <functional>
  5. #include <string>
  6. #include <vector>
  7. // 自动搜索正在尝试的串口参数和总体进度
  8. struct PlcDiscoveryProgress
  9. {
  10. PlcSerialConfiguration configuration;
  11. std::size_t currentAttempt = 0;
  12. std::size_t totalAttempts = 0;
  13. };
  14. // 自动搜索结束结果;found 和 cancelled 不会同时为 true
  15. struct PlcDiscoveryOutcome
  16. {
  17. bool found = false;
  18. bool cancelled = false;
  19. PlcSerialConfiguration configuration;
  20. std::string message;
  21. };
  22. /**
  23. * 按优先级生成搜索组合
  24. *
  25. * 站号和通信时序沿用界面当前值,只遍历可用端口及项目支持的串口参数
  26. */
  27. std::vector<PlcSerialConfiguration> buildPlcDiscoveryCandidates(
  28. const PlcSerialConfiguration &preferred,
  29. const std::vector<std::string> &available_ports);
  30. // UI 使用的异步 PLC 自动搜索契约,具体串口实现位于 infrastructure
  31. class PlcDiscoveryGateway
  32. {
  33. public:
  34. virtual ~PlcDiscoveryGateway() = default;
  35. // 开始搜索,实际进度和结果通过回调通知
  36. virtual PlcCommunicationResult startDiscovery(
  37. const PlcSerialConfiguration &preferred) = 0;
  38. // 取消当前搜索;串口释放后通过结束回调通知
  39. virtual void cancelDiscovery() = 0;
  40. // 返回当前是否正在搜索或等待释放搜索串口
  41. virtual bool isDiscovering() const = 0;
  42. // 替换进度和结束回调,传入空函数可取消通知
  43. virtual void setCallbacks(
  44. std::function<void(const PlcDiscoveryProgress &)> progress_changed,
  45. std::function<void(const PlcDiscoveryOutcome &)> discovery_finished) = 0;
  46. };