SensorADController.cpp 992 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include "stdafx.h"
  2. #include "SensorADController.h"
  3. #include "ICommunicateEntity.h"
  4. using namespace DIOS::Dev::Detail::MachineryECOM;
  5. SensorADController::SensorADController()
  6. :m_communicate(nullptr)
  7. {
  8. }
  9. SensorADController::~SensorADController()
  10. {
  11. }
  12. std::string SensorADController::CLASSID()
  13. {
  14. return "B6193C55-C668-4ADA-88F0-13124D9025AD";
  15. }
  16. void SensorADController::Initialize(const std::string &name)
  17. {
  18. SetName(name);
  19. }
  20. void SensorADController::OnCommunicationEstablished(ICommunicateEntity *communicate)
  21. {
  22. m_communicate = communicate;
  23. }
  24. int SensorADController::GetCurrentADValue()
  25. {
  26. if (!m_communicate || m_communicateInterfaceID < 0)
  27. {
  28. return INVALID_AD_VALUE;
  29. }
  30. int retry = 0;
  31. AD_PARAM params;
  32. while (retry++ < 5)
  33. {
  34. m_communicate->AD_Ctrl(OP_READ, (AD_ID)m_communicateInterfaceID, AD_ATTR_NONE, params);
  35. if (params.ad_value.ad_value_short > 0)
  36. {
  37. break;
  38. }
  39. }
  40. return params.ad_value.ad_value_short;
  41. }