COTSHardwareMgr.cpp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. #include "stdafx.h"
  2. #include "COTSHardwareMgr.h"
  3. #include "Bruker\OTSSEMBruker.h"
  4. #include "Simulate\OTSSemSim.h"
  5. #include "Simulate\OTSEDSSim.h"
  6. #include "Simulate\OTSScanSim.h"
  7. #include "Bruker\OTSEDSBrucker.h"
  8. #include "Bruker\OTSScanBrucker.h"
  9. #include "Oxford\OTSEDSOxford.h"
  10. #include "Oxford\OTSScanOxford.h"
  11. #include "Oxford\OTSSEMOxford.h"
  12. namespace OTSController {
  13. //using namespace COTSXmlFileDll;
  14. //Registry Path And KeyName
  15. const CString cssSubKeyRegeditPath = "SOFTWARE\\OTSDevName";
  16. const CString csKey_DevName = "SEMName";
  17. const CString csKey_EDSName = "EDSName";
  18. //
  19. char* lpSemName[] = { "OffLine","Bruker","ESEM","ZEISS" ,"Oxford"};
  20. char* lpEdsName[] = { "OffLine","Bruker" ,"Oxford"};
  21. //XMLÎļþÃû
  22. const CString szXMLFileName = "./Config/ProData/HardwareConfig.xml";
  23. CString szSemName=_T(""), szEdsName= _T("");
  24. typedef enum class SemDevID
  25. {
  26. Invalid = -1,
  27. OFFLINE = 0,
  28. BRUKER = 1,
  29. ESEM = 2,
  30. ZEISS = 3,
  31. OXFORD = 4,
  32. }SEM_DEV_ID;
  33. typedef enum class EDSDevID
  34. {
  35. Invalid = -1,
  36. OFFLINE = 0,
  37. BRUKER = 1,
  38. OXFORD = 2,
  39. }EDS_DEV_ID;
  40. COTSHardwareMgr::COTSHardwareMgr()
  41. {
  42. m_SemBasePtr = nullptr;
  43. m_EDSPtr = nullptr;
  44. m_SCanPtr = nullptr;
  45. }
  46. COTSHardwareMgr::~COTSHardwareMgr()
  47. {
  48. }
  49. CSemBasePtr COTSHardwareMgr::GetSemControllerMgrPtr()// this is the same as the constructor of singleton.So we cann't put expensive operation in it,such as the "connect" operation
  50. {
  51. if (nullptr == m_SemBasePtr)
  52. {
  53. int iDevID = -1;
  54. if (szSemName == _T(""))
  55. {
  56. if (!this->GetXMLVal(szXMLFileName, szSemName, szEdsName))
  57. {
  58. return nullptr;
  59. }
  60. }
  61. LogTrace(__FILE__, __LINE__, "(COTSHardwareMgr::GetSemControllerMgrPtr) SemName = %s, EdsName = %s", szSemName, szEdsName);
  62. iDevID = this->GetSemControllerID(szSemName);
  63. switch (iDevID)
  64. {
  65. case (int)SEM_DEV_ID::BRUKER:
  66. {
  67. m_SemBasePtr = CSemBasePtr(new COTSSEMBruker());
  68. //LogInfoTrace(__FILE__, __LINE__, "(COTSHardwareMgr::GetSemControllerMgrPtr) new COTSSEMBruker() ");
  69. break;
  70. }
  71. case (int)SEM_DEV_ID::OFFLINE:
  72. {
  73. m_SemBasePtr = CSemBasePtr(new COTSSemSim());
  74. //LogInfoTrace(__FILE__, __LINE__, "(COTSHardwareMgr::GetSemControllerMgrPtr) new COTSSemSim() ");
  75. break;
  76. }
  77. case (int)SEM_DEV_ID::OXFORD:
  78. {
  79. m_SemBasePtr = CSemBasePtr(new COTSSEMOxford());
  80. //LogInfoTrace(__FILE__, __LINE__, "(COTSHardwareMgr::GetSemControllerMgrPtr) new COTSSEMOxford() ");
  81. break;
  82. }
  83. default:
  84. break;
  85. }
  86. }
  87. return m_SemBasePtr;
  88. }
  89. COTSEDSBasePtr COTSHardwareMgr::GetEDSControllerPtr()
  90. {
  91. if (nullptr == m_EDSPtr)
  92. {
  93. int iDevID = -1;
  94. if (szEdsName == _T(""))
  95. {
  96. if (!this->GetXMLVal(szXMLFileName, szSemName, szEdsName))
  97. {
  98. return nullptr;
  99. }
  100. }
  101. //LogInfoTrace(__FILE__, __LINE__, "(COTSHardwareMgr::GetEDSControllerPtr) szSemName = %s, szEdsName = %s", szSemName, szEdsName);
  102. iDevID = this->GetEDSControllerID(szEdsName);
  103. switch (iDevID)
  104. {
  105. case (int)EDS_DEV_ID::BRUKER:
  106. {
  107. m_EDSPtr = COTSEDSBasePtr(new COTSEDSBrucker());
  108. //LogInfoTrace(__FILE__, __LINE__, "(COTSHardwareMgr::GetEDSControllerPtr) new COTSEDSBrucker() ");
  109. break;
  110. }
  111. case (int)EDS_DEV_ID::OFFLINE:
  112. {
  113. m_EDSPtr = COTSEDSBasePtr(new COTSEDSSim());
  114. //LogInfoTrace(__FILE__, __LINE__, "(COTSHardwareMgr::GetEDSControllerPtr) new COTSEDSSim() ");
  115. break;
  116. }
  117. case (int)EDS_DEV_ID::OXFORD:
  118. {
  119. m_EDSPtr = COTSEDSBasePtr(new COTSEDSOxford());
  120. //LogInfoTrace(__FILE__, __LINE__, "(COTSHardwareMgr::GetEDSControllerPtr) new COTSEDSOxford() ");
  121. break;
  122. }
  123. default:
  124. break;
  125. }
  126. }
  127. return m_EDSPtr;
  128. }
  129. COTSScanBasePtr COTSHardwareMgr::GetScanControllerPtr()
  130. {
  131. if (nullptr == m_SCanPtr)
  132. {
  133. int iDevID = -1;
  134. if (szEdsName == _T(""))
  135. {
  136. if (!this->GetXMLVal(szXMLFileName, szSemName, szEdsName))
  137. {
  138. return nullptr;
  139. }
  140. }
  141. //LogInfoTrace(__FILE__, __LINE__, "(COTSHardwareMgr::GetScanControllerPtr) szSemName = %s, szEdsName = %s", szSemName, szEdsName);
  142. iDevID = this->GetEDSControllerID(szEdsName);
  143. switch (iDevID)
  144. {
  145. case (int)EDS_DEV_ID::BRUKER:
  146. {
  147. m_SCanPtr = COTSScanBasePtr(new COTSScanBrucker());
  148. //LogInfoTrace(__FILE__, __LINE__, "(COTSHardwareMgr::GetScanControllerPtr) new COTSScanBrucker() ");
  149. break;
  150. }
  151. case (int)EDS_DEV_ID::OFFLINE:
  152. {
  153. m_SCanPtr = COTSScanBasePtr(new COTSScanSim());
  154. //LogInfoTrace(__FILE__, __LINE__, "(COTSHardwareMgr::GetScanControllerPtr) new COTSScanSim() ");
  155. break;
  156. }
  157. case (int)EDS_DEV_ID::OXFORD:
  158. {
  159. m_SCanPtr = COTSScanBasePtr(new COTSScanOxford());
  160. //LogInfoTrace(__FILE__, __LINE__, "(COTSHardwareMgr::GetScanControllerPtr) new COTSScanSim() ");
  161. break;
  162. }
  163. default:
  164. break;
  165. }
  166. }
  167. return m_SCanPtr;
  168. }
  169. BOOL COTSHardwareMgr::GetXMLVal(const CString& szXmlFileName, CString& szSemName, CString& szEdsName)
  170. {
  171. tinyxml2::XMLDocument doc;
  172. doc.LoadFile(szXMLFileName);//ÔØÈëxmlÎļþ
  173. xmls::xString szS;
  174. xmls::xString szE;
  175. xmls::Slo subClass;
  176. xmls::Slo subClass1;
  177. subClass.Register("Value", &szS);
  178. subClass1.Register ("Value",&szE);
  179. subClass.Register("SemControllerName", &subClass);
  180. subClass.Register("EDSName", &subClass1);
  181. tinyxml2::XMLElement *rootNode;
  182. rootNode = doc.FirstChildElement(RootClassName);
  183. subClass.Serialize(false, &doc, rootNode);
  184. szSemName = szS.value().c_str();
  185. szEdsName = szE.value().c_str();
  186. return true;
  187. }
  188. //return array Index when ControllerName match for name in array
  189. int COTSHardwareMgr::GetSemControllerID(const CString& SemControllerName)
  190. {
  191. int iLen = sizeof(lpSemName) /sizeof(*lpSemName);
  192. int i = 0;
  193. for (i=0; i<iLen; i++)
  194. {
  195. if (0 == strcmp(lpSemName[i], SemControllerName))
  196. {
  197. return i;
  198. }
  199. }
  200. //LogErrorTrace(__FILE__, __LINE__, "GetSemControllerID:: SEMControllerName is Valied, ControllerName =%s ", SemControllerName);
  201. return -1;
  202. }
  203. //return array Index when ControllerName match for name in array
  204. int COTSHardwareMgr::GetEDSControllerID(const CString& EDSControllerName)
  205. {
  206. int iLen = sizeof(lpEdsName) / sizeof(*lpEdsName);
  207. int i = 0;
  208. for (i = 0; i < iLen; i++)
  209. {
  210. if (0 == strcmp(lpEdsName[i], EDSControllerName))
  211. {
  212. return i;
  213. }
  214. }
  215. //LogErrorTrace(__FILE__, __LINE__, "GetEDSControllerID:: EDSControllerName is Valied, ControllerName =%s ", EDSControllerName);
  216. return -1;
  217. }
  218. }