C++ Instrument Catalog
MFCController.h
Go to the documentation of this file.
1 
6 #pragma once
7 
8 // Standard includes
9 #include <string>
10 // Personal includes
11 #include "InstrumentCatalog.h"
12 #include "VISAInstrument.h"
13 #include "MFCDevice.h"
14 #include "Helpers.h"
15 #include "ThreadedMailbox.h"
16 #include "MFCManagerCatalog.h"
17 
18 using namespace MTL;
19 using namespace MTL::Instrument;
20 using namespace MTL::ThreadedMailbox;
21 
22 namespace MTL {
23 
24  //--------------------------------------------------------------------------//
25  // MFC CONTROLLER
26  //--------------------------------------------------------------------------//
28  enum eMsgType { kTimerEvent } MsgType;
30  : MsgType(kTimerEvent) {}
32  : MsgType(MT) {}
33  };
34  class CMFCController : private CThreadedMailBox<sMFCControllerMailBoxMsg>
35  {
36  //--------------------------------------------------------------------------//
37  // Friend class
38  //--------------------------------------------------------------------------//
39  private:
40  friend class CMFC2x46Device;
41  friend class CMFC3045Device;
42 
43  //--------------------------------------------------------------------------//
44  // Attributes
45  //--------------------------------------------------------------------------//
46  private:
47  CMFCControllerInterface m_ContCat; // Controller catalog
48  CTimer m_Timer;
49  std::atomic<CMFCManagerCatalog::eControllerState> m_ControllerState;
50  CVISAResourceManager * m_pRsrcManager = nullptr;
51  CMFCDevice * m_pMFCDevice = nullptr;
54  std::string m_DefaultPAConfScriptFilePath; // Path of the default PA configuration script (if no specific file exists)
55  std::string m_CustomPAConfScriptDirectory; // Directory containing PA specific configuration scripts
56  // Constants
57  const int RSRC_POLLING_PERIOD_MS = 200;
58  const int PA_POLLING_PERIOD_MS = 200;
59 
60  //--------------------------------------------------------------------------//
61  // Management
62  //--------------------------------------------------------------------------//
63  private:
64  void l_SendLogMessage(const std::string & rMessage, const CInstrumentCatalog::eLogLevel & rLevel, const std::string & rContext, const std::string & rLocation);
65  void l_SendErrorMessage(const CMFCDevice::sMFCDeviceError & rErrorMessage);
66  void l_SendSearchProgress(const U8 & rSearcHprogress);
67  void l_SendSearchResult(const CInstrumentCatalog::sSearchResult & rSearchResults);
68  void l_SendMeasResult(const CInstrumentCatalog::sMeasurementResults & rMeasRes);
69  bool l_IsAbortRequested();
70  void l_CheckConnectionOnWarning(const CMFCDevice::sMFCDeviceError & rOriginError, CMFCDevice::sMFCDeviceError & rErrorOut);
71 
72  //--------------------------------------------------------------------------//
73  // Internal Operations
74  //--------------------------------------------------------------------------//
75  // Lives in the timer thread.
76  private:
77  void l_PostTimerEvent(); // Called when timer elapses. Adds timer event to queue.
78  // Lives in the Controller thread.
79  private:
80  // Thread task
81  void l_ThreadTask(CThreadedMailBox::eEventType EvtType, sMFCControllerMailBoxMsg * pMsg);
82  // Mail box event handlers
83  void l_TimerEventHandler();
84  // Internal operations
85  void l_AbortInstrument();
86  void l_ScanResources();
87  void l_GetRemoteBoxButtonStatus();
88  bool l_ScanPA();
89  void l_OperateWithInstrument();
90 
91  //--------------------------------------------------------------------------//
92  // Utilities
93  //--------------------------------------------------------------------------//
94  // Lives in the Controller thread.
95  private:
96  void l_RequestSelfAbort();
97 
98  //--------------------------------------------------------------------------//
99  // Constructor / Destructor
100  //--------------------------------------------------------------------------//
101  // Lives in the caller thread.
102  public:
103  CMFCController(CMFCManagerCatalog & rCatInstance, const std::string & rDefaultPAConfScriptFilePath, const std::string & rCustomPAConfScriptDir);
104  virtual ~CMFCController();
105 
106  //--------------------------------------------------------------------------//
107  // Available Operations
108  //--------------------------------------------------------------------------//
109  public:
110  // Lives in the caller thread.
111  void Operate();
112  void Terminate(); // Blocks while the Controller thread did not stopped working.
113  void ScanInstruments(CVISAResourceManager * pRsrcManager);
114  void ScanPA(CMFCDevice * pMFCDevice);
115  void SetInstrumentState(CMFCDevice * pMFCDevice, CInstrumentCatalog::sInstrumentState InsState);
116  void UpdateNormalizationDate();
117  }; // class
118 
119 } // namespace MTL
MFCManagerCatalog.h
MTL::CMFCControllerInterface
Definition: MFCManagerCatalog.h:98
MTL::sMFCControllerMailBoxMsg::sMFCControllerMailBoxMsg
sMFCControllerMailBoxMsg()
Definition: MFCController.h:29
MTL::CMFC3045Device
Definition: MFC3045Device.h:50
MTL::CInstrumentCatalog::sMeasurementResults
Definition: InstrumentCatalog.h:267
MTL::CInstrumentCatalog::sSearchResult
Definition: InstrumentCatalog.h:250
MTL::ThreadedMailbox::CThreadedMailBox
Definition: ThreadedMailbox.h:222
MTL::sMFCControllerMailBoxMsg::eMsgType
eMsgType
Definition: MFCController.h:28
MTL::ThreadedMailbox::CThreadedMailBox::eEventType
eEventType
Definition: ThreadedMailbox.h:228
ThreadedMailbox.h
Helpers.h
Collection of utility macros for error messages.
MTL::CInstrumentCatalog::sInstrumentState
Definition: InstrumentCatalog.h:212
MTL::CInstrumentCatalog::eLogLevel
eLogLevel
Definition: InstrumentCatalog.h:317
MTL::CMFCDevice::sMFCDeviceError
Definition: MFCDevice.h:30
MTL
Definition: CPT2026PeripheralROM.h:19
MTL::Instrument
Definition: MFC3045.h:25
MTL::CMFCDevice
Definition: MFCDevice.h:24
MTL::CInstrumentCatalog::sProbeArrayInformation
Definition: InstrumentCatalog.h:145
InstrumentCatalog.h
MTL::sMFCControllerMailBoxMsg::sMFCControllerMailBoxMsg
sMFCControllerMailBoxMsg(eMsgType MT)
Definition: MFCController.h:31
MTL::sMFCControllerMailBoxMsg
Definition: MFCController.h:27
MTL::ThreadedMailbox
Definition: ThreadedMailbox.h:17
MTL::ThreadedMailbox::CTimer
Definition: ThreadedMailbox.h:126
MTL::CMFCController
Definition: MFCController.h:34
MTL::CMFC2x46Device
Definition: MFC2x46Device.h:28
MTL::CMFCManagerCatalog
Definition: MFCManagerCatalog.h:19
VISAInstrument.h
C++ wrapper for NI-VISA: interface definition.
MTL::Instrument::CVISAResourceManager
VISA Resource Manager class.
Definition: VISAInstrument.h:35
MFCDevice.h