Detector_CareRayDR.cpp 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534
  1. #include "stdafx.h"
  2. #include "Detector_CareRayDR.h"
  3. #include "CCOS.Dev.FPD.CareRayDR.h"
  4. #include "MyPingip.h"
  5. Detector_CareRayDR* g_pDetector = nullptr;
  6. extern Log4CPP::Logger* //mLog::gLogger;
  7. #define LOAD_PROC_ADDRESS(handle,func) \
  8. if ((API_##func = (Func_##func)GetProcAddress(handle, #func)) == NULL) { printf("Error occurs while loading entry point!!! \r\n'%s'\n", #func); }\
  9. #define RAD_HEADER_SIZE 65536
  10. const int nBuffSize = 1088 * 1088 * 64;
  11. const int FLUORO_IMAGE_HEADER_SIZE = 256;
  12. void __stdcall CREventCallback(int eventID, CrEvent * eventData)
  13. {
  14. if (nullptr != g_pDetector)
  15. {
  16. g_pDetector->ProcessCREvent(eventID, eventData);
  17. }
  18. }
  19. Detector_CareRayDR::Detector_CareRayDR()
  20. {
  21. m_pDPC2PanelID = new map<FPDDeviceCareRay*, int>();
  22. m_pPanelID2DPC = new map<int, FPDDeviceCareRay*>();
  23. m_nPanelCount = 0;
  24. m_nCurrentPanelID = 0;
  25. m_hCareRayDRModule = nullptr;
  26. m_nSyncMode = SYNC_SOFTWARE;
  27. m_nTriggerType = CR_RAD_EXT_SYNC;
  28. m_pRawImgBuffer = nullptr;
  29. m_pImgBuffer = nullptr;
  30. m_nImageWidth = 0;
  31. m_nImageHeight = 0;
  32. m_nWidthOffset = 0;
  33. m_nHeightOffset = 0;
  34. m_nRawImgWidth = 0;
  35. m_nRawImgHeight = 0;
  36. m_bSaveRaw = false;
  37. m_eCaliType = CCOS_CALIBRATION_TYPE_NONE;
  38. m_nCurrentLogicMode = AcqMode::RAD;
  39. m_nCalibrationMode = CCOS_CALIBRATION_MODE_ZSKK;
  40. m_pFluFrameData = nullptr;
  41. m_nCalibrationRounds = 0;
  42. m_nCalibCurrentCalibrationRound = 0;
  43. m_nCalibCurrentExposureIndex = 0;
  44. m_nExposureNumCurrentRound = 0;
  45. m_pZSKKCalib = nullptr;
  46. m_strDetectorType = "";
  47. m_bOnlyHaveFpd = false;
  48. m_nGainImg = 0;
  49. m_nGainExposureNum = 0;
  50. m_nDetectorNum = 1;
  51. m_hRespond = CreateEvent(NULL, FALSE, FALSE, NULL);
  52. m_hInitEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
  53. m_hExitEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
  54. m_hReConnectEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
  55. m_hSwitchEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
  56. m_hRadEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
  57. m_hDualEnergyEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
  58. m_hOffsetEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
  59. m_hGainEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
  60. m_hArrayEvent[0] = m_hInitEvent;
  61. m_hArrayEvent[1] = m_hExitEvent;
  62. m_hArrayEvent[2] = m_hReConnectEvent;
  63. m_hArrayEvent[3] = m_hSwitchEvent;
  64. m_hArrayEvent[4] = m_hRadEvent;
  65. m_hArrayEvent[5] = m_hDualEnergyEvent;
  66. m_hArrayEvent[6] = m_hOffsetEvent;
  67. m_hArrayEvent[7] = m_hGainEvent;
  68. m_hToggleEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
  69. InitSdkInterface();
  70. }
  71. void Detector_CareRayDR::InitSdkInterface()
  72. {
  73. API_CrInitializeLibrary = nullptr;
  74. API_CrDeinitializeLibrary = nullptr;
  75. API_CrGetLastIntlMsg = nullptr;
  76. API_CrGetConfigItemValue = nullptr;
  77. API_CrSetConfigItemValue = nullptr;
  78. API_CrRegisterEventCallbackFun = nullptr;
  79. API_CrGetDetectorIndexAndIPAddress = nullptr;
  80. API_CrConnect = nullptr;
  81. API_CrResetDetector = nullptr;
  82. API_CrDisconnect = nullptr;
  83. API_CrGetSystemInformation = nullptr;
  84. API_CrGetApplicationMode = nullptr;
  85. API_CrRegisterApplicationMode = nullptr;
  86. API_CrSetFrameFilter = nullptr;
  87. API_CrGetModeInfoByAppModeKey = nullptr;
  88. API_CrGetRegedInfoByAppModeKey = nullptr;
  89. API_CrGetModeInfoByModeId = nullptr;
  90. API_CrLoadReference = nullptr;
  91. API_CrUnloadReference = nullptr;
  92. API_CrStartAcquisition = nullptr;
  93. API_CrStartDarkAcquisition = nullptr;
  94. API_CrStartDarkAcquisitionWithCorrOpt = nullptr;
  95. API_CrStopAcquisition = nullptr;
  96. API_CrStartDarkCalibration = nullptr;
  97. API_CrStartGainCalibration = nullptr;
  98. API_CrStopCalibration = nullptr;
  99. API_CrGetAcquisitionStatInfo = nullptr;
  100. API_CrQueryCalibrationStatus = nullptr;
  101. API_CrQueryReferenceStatus = nullptr;
  102. API_CrGetDefectInfo = nullptr;
  103. API_CrGetPositionDefectInfo = nullptr;
  104. API_CrQueryAcquisitionStatus = nullptr;
  105. API_CrQueryAedExposureProgress = nullptr;
  106. API_CrPermitExposure = nullptr;
  107. API_CrRequestExposure = nullptr;
  108. API_CrGetImage = nullptr;
  109. API_CrGetNoHeaderImage = nullptr;
  110. API_CrGetDetrStatus = nullptr;
  111. API_CrGetConnectionStatus = nullptr;
  112. API_CrStartAcquisitionWithCorrOpt = nullptr;
  113. API_CrGetDaecActiveAreas = nullptr;
  114. API_CrSetDaecActiveAreas = nullptr;
  115. API_CrGetBatteryInfos = nullptr;
  116. API_CrGetWirelessStatus = nullptr;
  117. }
  118. Detector_CareRayDR::~Detector_CareRayDR()
  119. {
  120. CloseStatusMonitor();
  121. CloseDetectorScan();
  122. if (m_pRawImgBuffer)
  123. {
  124. delete[]m_pRawImgBuffer;
  125. m_pRawImgBuffer = nullptr;
  126. }
  127. if (m_pImgBuffer)
  128. {
  129. delete[]m_pImgBuffer;
  130. m_pImgBuffer = nullptr;
  131. }
  132. if (m_pDarkImage)
  133. {
  134. delete[]m_pDarkImage;
  135. m_pDarkImage = nullptr;
  136. }
  137. if (m_pFluFrameData)
  138. {
  139. delete[] m_pFluFrameData;
  140. m_pFluFrameData = nullptr;
  141. }
  142. if (m_pZSKKCalib)
  143. {
  144. delete m_pZSKKCalib;
  145. m_pZSKKCalib = nullptr;
  146. }
  147. }
  148. bool Detector_CareRayDR::DriverEntry(FPDDeviceCareRay* pDrvDPC, ResDataObject& Configuration)
  149. {
  150. printf("--Func-- DriverEntry %p\n", pDrvDPC);
  151. //mLog::Info("--Func-- DriverEntry {$}", pDrvDPC);
  152. map<FPDDeviceCareRay*, int>::iterator DPCsIter = m_pDPC2PanelID->find(pDrvDPC);
  153. if (DPCsIter != m_pDPC2PanelID->end())
  154. {
  155. printf("This DPC already exist\n");
  156. //mLog::Error("This DPC already exist");
  157. return false;
  158. }
  159. CPanelStatus* p = new CPanelStatus();
  160. m_pStPanelStatus[m_nPanelCount] = p;
  161. m_pDPC2PanelID->insert(pair<FPDDeviceCareRay*, int>(pDrvDPC, m_nPanelCount));
  162. m_pPanelID2DPC->insert(pair<int, FPDDeviceCareRay*>(m_nPanelCount, pDrvDPC));
  163. m_nPanelCount++;
  164. m_ModeConfig = Configuration; //记录配置 --目前只有一个平板,多板时应该分别存储
  165. //mLog::Info("Config: {$}", m_ModeConfig.encode());
  166. return true;
  167. }
  168. bool Detector_CareRayDR::Connect(FPDDeviceCareRay* pDrvDPC, const char* szWorkPath)
  169. {
  170. //mLog::Info("Connect detector begin");
  171. printf("Connect detector begin \r\n");
  172. if ((*m_pDPC2PanelID)[pDrvDPC] != m_nCurrentPanelID)
  173. {
  174. //mLog::Info("Not current DPC, return true");
  175. printf("Not current DPC, return true \r\n");
  176. return true;
  177. }
  178. if (!m_pZSKKCalib)
  179. {
  180. m_pZSKKCalib = new CZSKKCalibrationCtrl();
  181. }
  182. m_strWorkPath = szWorkPath;
  183. if (nullptr == m_hFPDScanThread)
  184. {
  185. unsigned uThreadId;
  186. _beginthreadex(NULL, 0, onFPDScanThread, this, 0, &uThreadId);
  187. m_hFPDScanThread = OpenThread(THREAD_ALL_ACCESS, TRUE, uThreadId);
  188. }
  189. SetEvent(m_hInitEvent);
  190. //mLog::Info("Connect over");
  191. printf("Connect over \r\n");
  192. return true;
  193. }
  194. bool Detector_CareRayDR::Disconnect()
  195. {
  196. int ret = CR_OK;
  197. //mLog::Info("Disconnect detector begin \r\n");
  198. SetEvent(m_hExitEvent); //关闭Scan线程
  199. DWORD result = WaitForSingleObject(m_hToggleEvent, 65000);
  200. if (result == WAIT_OBJECT_0)
  201. {
  202. //mLog::Info("Leave scan thread over");
  203. }
  204. else if (result == WAIT_TIMEOUT)
  205. {
  206. //mLog::Error("Till time out");
  207. }
  208. //mLog::Info("Call CrUnloadReference");
  209. ret = API_CrUnloadReference(m_nDetectorID, m_nAppModeKey);
  210. if (!TestError(ret))
  211. {
  212. //mLog::Error("Unload Calibration Data Failed");
  213. return false;
  214. }
  215. //mLog::Info("Call CrDisconnect");
  216. ret = API_CrDisconnect(m_nDetectorID);
  217. if (!TestError(ret))
  218. {
  219. //mLog::Error("disconnect detector fail!");
  220. return false;
  221. }
  222. //mLog::Info("Disconnect over");
  223. return true;
  224. }
  225. void Detector_CareRayDR::EnterExamMode(int nExamMode)
  226. {
  227. switch (nExamMode)
  228. {
  229. case APP_STATUS_WORK_BEGIN:
  230. //mLog::Info("Enter into Exam Windows");
  231. break;
  232. case APP_STATUS_WORK_END:
  233. //mLog::Info("Quit Exam Windows");
  234. break;
  235. case APP_STATUS_DETSHARE_BEGIN:
  236. //mLog::Info("Enter into Detector Share Windows");
  237. break;
  238. case APP_STATUS_DETSHAR_END:
  239. //mLog::Info("Quit Detector Share Windows");
  240. break;
  241. case APP_STATUS_CAL_BEGIN:
  242. //mLog::Info("Enter into Calibration Windows");
  243. break;
  244. case APP_STATUS_CAL_END:
  245. //mLog::Info("Quit Calibration Windows");
  246. break;
  247. case APP_STATUS_WORK_IN_SENSITIVITY:
  248. //mLog::Info("Enter into sensitivity test interface");
  249. break;
  250. default:
  251. break;
  252. }
  253. if (APP_STATUS_WORK_END == nExamMode || APP_STATUS_CAL_END == nExamMode)
  254. {
  255. }
  256. }
  257. /***
  258. ** 根据采集模式申请图像buffer
  259. ***/
  260. bool Detector_CareRayDR::SetAcqMode(int nMode)
  261. {
  262. //mLog::Info("Detector_CareRayDR::SetAcqMode mode:{$}", nMode);
  263. //if (m_nCurrentLogicMode == nMode)
  264. //{
  265. // //mLog::Info("Same acq mode,return");
  266. // return true;
  267. //}
  268. if (!m_pStPanelStatus[m_nCurrentPanelID]->bConnectState)
  269. {
  270. //mLog::Error("Detector not connected, return");
  271. return false;
  272. }
  273. try
  274. {
  275. int nModeCount = (int)m_ModeConfig["ModeTable"].GetKeyCount("DetectorMode");
  276. for (int i = 0; i < nModeCount; i++)
  277. {
  278. int nAppModeID = (int)m_ModeConfig["ModeTable"][i]["LogicMode"];
  279. if (nAppModeID == nMode)
  280. {
  281. //设置采集模式,根据不同的场景设置不同的采集模式
  282. m_nAppModeKey = (int)m_ModeConfig["ModeTable"][i]["AppModeKey"];
  283. m_nModeID = (int)m_ModeConfig["ModeTable"][i]["ModeID"];
  284. m_nFrameRate = (int)m_ModeConfig["ModeTable"][i]["FrameRate"];
  285. m_nExtIntegrationTime = (int)m_ModeConfig["ModeTable"][i]["ExtIntegrationTime"];
  286. m_nGainLevel = (int)m_ModeConfig["ModeTable"][i]["GainLevel"];
  287. m_nImageWidth = (int)m_ModeConfig["ModeTable"][i]["ImageWidth"];
  288. m_nImageHeight = (int)m_ModeConfig["ModeTable"][i]["ImageHeight"];
  289. m_nWidthOffset = (int)m_ModeConfig["ModeTable"][i]["WidthOffset"];
  290. m_nHeightOffset = (int)m_ModeConfig["ModeTable"][i]["HeightOffset"];
  291. //mLog::Info("After crop image width: {$}, height: {$}, WidthOffset: {$}, HeightOffset: {$}", m_nImageWidth, m_nImageHeight, m_nWidthOffset, m_nHeightOffset);
  292. m_nSyncMode = (int)m_ModeConfig["ModeTable"][i]["SyncType"];
  293. m_bSaveRaw = (int)m_ModeConfig["ModeTable"][i]["IsSaveRaw"];
  294. //mLog::Info("m_nSyncMode:{$},m_nSaveRaw:{$}", m_nSyncMode, m_bSaveRaw);
  295. GetTriggerType(m_nSyncMode);
  296. m_pStPanelStatus[m_nCurrentPanelID]->eSyncMode = (SYNC_MODE)m_nSyncMode;
  297. m_nCurrentLogicMode = nMode;
  298. if (m_nCurrentLogicMode == AcqMode::RAD)
  299. {
  300. if (nullptr != m_pImgBuffer)
  301. {
  302. delete[] m_pImgBuffer;
  303. m_pImgBuffer = nullptr;
  304. }
  305. m_pImgBuffer = new WORD[(size_t)m_nImageWidth * (size_t)m_nImageHeight];
  306. }
  307. else if (m_nCurrentLogicMode == AcqMode::DAEC)
  308. {
  309. if (nullptr != m_pImgBuffer)
  310. {
  311. delete[] m_pImgBuffer;
  312. m_pImgBuffer = nullptr;
  313. }
  314. m_pImgBuffer = new WORD[(size_t)m_nImageWidth * (size_t)m_nImageHeight];
  315. }
  316. else if (m_nCurrentLogicMode == AcqMode::DUAL_ENERGY)
  317. {
  318. if (nullptr != m_pImgBuffer)
  319. {
  320. delete[] m_pImgBuffer;
  321. m_pImgBuffer = nullptr;
  322. }
  323. m_pImgBuffer = new WORD[(size_t)m_nImageWidth * (size_t)m_nImageHeight];
  324. }
  325. else if (m_nCurrentLogicMode == DDR)
  326. {
  327. if (nullptr != m_pFluFrameData)
  328. {
  329. delete[] m_pFluFrameData;
  330. m_pFluFrameData = nullptr;
  331. }
  332. m_pFluFrameData = new WORD[(size_t)m_nImageWidth * (size_t)m_nImageHeight];
  333. memset(m_pFluFrameData, 0, (size_t)m_nImageWidth * (size_t)m_nImageHeight);
  334. }
  335. break;
  336. }
  337. }
  338. }
  339. catch (ResDataObjectExption& e)
  340. {
  341. //mLog::Error("Get config error: {$}", e.what());
  342. return false;
  343. }
  344. StatusFeedback(EVT_STATUS_PANEL, PANEL_SLEEP);
  345. return true;
  346. }
  347. bool Detector_CareRayDR::PrepareAcquisition(FPDDeviceCareRay* pDrvDPC)
  348. {
  349. //mLog::Info("PrepareAcquisition start");
  350. if ((*m_pDPC2PanelID)[pDrvDPC] != m_nCurrentPanelID)
  351. {
  352. printf("Not current DPC, return\n");
  353. //mLog::Error("Not current DPC, return");
  354. return false;
  355. }
  356. //未初始化、未连接 不执行
  357. if (!m_pStPanelStatus[m_nCurrentPanelID]->bConnectState)
  358. {
  359. //mLog::Error("Detector not connected, return");
  360. return false;
  361. }
  362. //mLog::Info("PrepareAcquisition m_nTriggerType:{$}", m_nTriggerType);
  363. if (!SetApplicationMode())
  364. {
  365. return false;
  366. }
  367. if (!ShowModeInfo())
  368. {
  369. return false;
  370. }
  371. //Careray not have Calibration for dual energy,so don't load Calibration File
  372. if (m_nCurrentLogicMode != AcqMode::DUAL_ENERGY)
  373. {
  374. //LoadCalibrationFiles();
  375. }
  376. int nRet = CR_OK;
  377. if (m_nCurrentLogicMode == AcqMode::RAD)
  378. {
  379. SetEvent(m_hRadEvent);
  380. }
  381. else if (m_nCurrentLogicMode == AcqMode::DAEC)
  382. {
  383. SetEvent(m_hRadEvent);
  384. }
  385. else if (m_nCurrentLogicMode == AcqMode::DUAL_ENERGY)
  386. {
  387. SetEvent(m_hDualEnergyEvent);
  388. }
  389. else if (m_nCurrentLogicMode == AcqMode::DDR)
  390. {
  391. if (m_nTriggerType == CrTrigType::CR_FLUORO_INT_SYNC)
  392. {
  393. //mLog::Info("DDR use flu mode of Inner Trigger");
  394. //mLog::Info("Call CrStartAcquisition");
  395. nRet = API_CrStartAcquisition(m_nDetectorID, m_nAppModeKey, -1);
  396. if (!TestError(nRet))
  397. {
  398. //mLog::Error("Failed to start DDR acquisition");
  399. return false;
  400. }
  401. }
  402. }
  403. Sleep(5000);
  404. StatusFeedback(EVT_STATUS_PANEL, PANEL_STANDBY);
  405. //mLog::Info("PrepareAcquisition end");
  406. return true;
  407. }
  408. bool Detector_CareRayDR::StartAcquisition(FPDDeviceCareRay* pDrvDPC)
  409. {
  410. int nRes = CR_OK;
  411. //mLog::Info("StartAcquisition start");
  412. if ((*m_pDPC2PanelID)[pDrvDPC] != m_nCurrentPanelID)
  413. {
  414. printf("Not current DPC, return\n");
  415. //mLog::Error("Not current DPC, return");
  416. return false;
  417. }
  418. //未初始化、未连接 不执行
  419. if (!m_pStPanelStatus[m_nCurrentPanelID]->bConnectState)
  420. {
  421. //mLog::Error("Detector not connected, return");
  422. return false;
  423. }
  424. if (m_nCurrentLogicMode == AcqMode::RAD && m_nTriggerType == CrTrigType::CR_RAD_SOFT_SYNC)
  425. {
  426. //mLog::Info("Rad Soft Trigger RequestExposure!!!!");
  427. StatusFeedback(EVT_STATUS_PANEL, PANEL_XWINDOW_ON);
  428. nRes = API_CrRequestExposure(m_nDetectorID);
  429. if (!TestError(nRes))
  430. {
  431. //mLog::Error("RequestExposure Failed");
  432. }
  433. }
  434. if (m_nCurrentLogicMode == AcqMode::DUAL_ENERGY)
  435. {
  436. //mLog::Info("Dual Energy RequestExposure!!!");
  437. StatusFeedback(EVT_STATUS_PANEL, PANEL_START_ACQ);
  438. int nRes = CR_OK;
  439. nRes = API_CrRequestExposure(m_nDetectorID);
  440. if (!TestError(nRes))
  441. {
  442. //mLog::Error("RequestExposure Failed");
  443. return false;
  444. }
  445. //mLog::Info("RequestExposure Successed!!");
  446. }
  447. //mLog::Info("StartAcquisition end");
  448. return true;
  449. }
  450. bool Detector_CareRayDR::StopAcquisition(FPDDeviceCareRay* pDrvDPC)
  451. {
  452. if ((*m_pDPC2PanelID)[pDrvDPC] != m_nCurrentPanelID)
  453. {
  454. printf("Not current DPC, return\n");
  455. //mLog::Error("Not current DPC, return");
  456. return false;
  457. }
  458. if (!m_pStPanelStatus[m_nCurrentPanelID]->bConnectState)
  459. {
  460. //mLog::Error("Detector not connected, return");
  461. return false;
  462. }
  463. //mLog::Info("## Stop Acquisition ##");
  464. int nRet = CR_OK;
  465. //mLog::Info("Call CrStopAcquisition");
  466. nRet = API_CrStopAcquisition(m_nDetectorID);
  467. if (!TestError(nRet))
  468. {
  469. //mLog::Error("Stop Acquisition Failed");
  470. return false;
  471. }
  472. SetCareRayDPCStatus(eDetStatus::DetStatus_Standby); //停止采集
  473. return true;
  474. }
  475. bool Detector_CareRayDR::RequestXray(FPDDeviceCareRay* pDrvDPC)
  476. {
  477. //mLog::Info("Dual Energy Request Exposure!!");
  478. int nRes = CR_OK;
  479. nRes = API_CrRequestExposure(m_nDetectorID);
  480. if (!TestError(nRes))
  481. {
  482. //mLog::Error("RequestExposure Failed");
  483. return false;
  484. }
  485. //mLog::Info("RequestExposure Successed!!");
  486. return true;
  487. }
  488. bool Detector_CareRayDR::ActiveCalibration(FPDDeviceCareRay* pDrvDPC, CCOS_CALIBRATION_TYPE eType)
  489. {
  490. if ((*m_pDPC2PanelID)[pDrvDPC] != m_nCurrentPanelID)
  491. {
  492. printf("Not current DPC, return\n");
  493. //mLog::Error("Not current DPC, return");
  494. return false;
  495. }
  496. if (!m_pStPanelStatus[m_nCurrentPanelID]->bConnectState)
  497. {
  498. //mLog::Error("Detector not connected, return");
  499. return false;
  500. }
  501. StatusFeedback(EVT_STATUS_CALIBRATIOIN, PANEL_EVENT_START);
  502. m_eCaliType = eType;
  503. m_nGainImg = 0;
  504. if (CCOS_CALIBRATION_TYPE_DARK == m_eCaliType)
  505. {
  506. //mLog::Info("Active Dark Calibration");
  507. }
  508. if (CCOS_CALIBRATION_TYPE_XRAY == m_eCaliType)
  509. {
  510. //mLog::Info("Active Xray Calibration");
  511. if (m_nCalibrationMode) //厂商校正
  512. {
  513. }
  514. else //ZSKK校正
  515. {
  516. if (!m_pZSKKCalib)
  517. {
  518. //mLog::Error("ZSKK Calibration object is undefined");
  519. }
  520. else
  521. {
  522. //反馈Dose信息
  523. DataFeedback(EVT_DATA_DOSEPARAM, NULL, 0, 2.5);
  524. //加载ZSKK的校正文件
  525. m_pZSKKCalib->m_strRawImgPath = m_strWorkPath + "\\rawdata\\";
  526. m_pZSKKCalib->m_strRefFilePath = m_strWorkPath + "\\references\\";
  527. m_pZSKKCalib->m_nFullImgWidth = m_nImageWidth;
  528. m_pZSKKCalib->m_nFullImgHeight = m_nImageHeight;
  529. m_pZSKKCalib->m_nReferenceNum = m_nCalibrationRounds;
  530. m_pZSKKCalib->m_nSaturationValue = 50000;
  531. m_pZSKKCalib->LoadZSKKGainMap(false, m_strDetectorType);
  532. m_pZSKKCalib->LoadZSKKPixelMap(false, m_strDetectorType);
  533. //mLog::Info("Load ZSKK Gain map success!");
  534. //mLog::Info("references file path: {$}", m_pZSKKCalib->m_strRefFilePath);
  535. }
  536. }
  537. }
  538. return true;
  539. }
  540. /***
  541. * 接受曝光图像
  542. ***/
  543. bool Detector_CareRayDR::AcceptCalibration()
  544. {
  545. //mLog::Info("Accept calibration exposure result");
  546. if (m_nCalibrationMode)//厂商校正
  547. {
  548. //不做处理
  549. }
  550. else //ZSKK校正
  551. {
  552. if (m_nCalibCurrentExposureIndex == 1)
  553. {
  554. m_pZSKKCalib->AddImageToPixMap(m_pImgBuffer);
  555. m_pZSKKCalib->AverageZSKKGainMap(m_pImgBuffer, m_nCalibCurrentCalibrationRound - 1, true);
  556. }
  557. else
  558. {
  559. m_pZSKKCalib->AverageZSKKGainMap(m_pImgBuffer, m_nCalibCurrentCalibrationRound - 1, false); //曝光第几轮
  560. }
  561. }
  562. return true;
  563. }
  564. /***
  565. * 拒绝曝光图像
  566. ***/
  567. bool Detector_CareRayDR::RejectCalibration()
  568. {
  569. //mLog::Info("Reject calibration exposure result");
  570. return true;
  571. }
  572. /***
  573. * 设置校正轮数
  574. ***/
  575. bool Detector_CareRayDR::SetCalibRounds(int nCalibRounds)
  576. {
  577. m_nCalibrationRounds = nCalibRounds;
  578. //mLog::Info("Set reference number: {$}", m_nCalibrationRounds);
  579. return true;
  580. }
  581. bool Detector_CareRayDR::GetCalibrationStep(int nCalibCurrentCalibrationRound, int nCalibrationRounds, int nCalibCurrentExposureIndex, int nExposureNumCurrentRound)
  582. {
  583. m_nCalibCurrentCalibrationRound = nCalibCurrentCalibrationRound;
  584. m_nCalibrationRounds = nCalibrationRounds;
  585. m_nCalibCurrentExposureIndex = nCalibCurrentExposureIndex;
  586. m_nExposureNumCurrentRound = nExposureNumCurrentRound;
  587. //mLog::Info("Calibration Step===Round: {$}/{$}, ExposureNum: {$}/{$}", nCalibCurrentCalibrationRound, nCalibrationRounds,
  588. nCalibCurrentExposureIndex, nExposureNumCurrentRound);
  589. return true;
  590. }
  591. //使探测器ready
  592. bool Detector_CareRayDR::PrepareCalibration(FPDDeviceCareRay* pDrvDPC)
  593. {
  594. if ((*m_pDPC2PanelID)[pDrvDPC] != m_nCurrentPanelID)
  595. {
  596. printf("Not current DPC, return\n");
  597. //mLog::Error("Not current DPC, return");
  598. return false;
  599. }
  600. if (!m_pStPanelStatus[m_nCurrentPanelID]->bConnectState)
  601. {
  602. //mLog::Error("Detector not connected, return");
  603. return false;
  604. }
  605. if (CCOS_CALIBRATION_TYPE_DARK == m_eCaliType)
  606. {
  607. //mLog::Info("PrepareCalibration CCOS_CALIBRATION_TYPE_DARK == m_eCaliType");
  608. //由于前端没有测试过暗场校正上图的情况,故此处不进行暗场上图
  609. //DarkAcquisition();
  610. }
  611. else if (CCOS_CALIBRATION_TYPE_XRAY == m_eCaliType)
  612. {
  613. //mLog::Info("PrepareCalibration CCOS_CALIBRATION_TYPE_XRAY == m_eCaliType");
  614. SetCareRayDPCStatus(eDetStatus::DetStatus_Standby);
  615. bool ret = PrepareAcquisition(pDrvDPC);
  616. if (ret)
  617. {
  618. //mLog::Info("PrepareCalibration PrepareAcquisition success!");
  619. }
  620. else
  621. {
  622. //mLog::Error("PrepareCalibration PrepareAcquisition fail!");
  623. return false;
  624. }
  625. }
  626. return true;
  627. }
  628. //软同步调用接口,其它同步模式没有动作
  629. bool Detector_CareRayDR::StartCalibration(FPDDeviceCareRay* pDrvDPC)
  630. {
  631. if ((*m_pDPC2PanelID)[pDrvDPC] != m_nCurrentPanelID)
  632. {
  633. printf("Not current DPC, return\n");
  634. //mLog::Error("Not current DPC, return");
  635. return false;
  636. }
  637. //未初始化、未连接 不执行
  638. if (!m_pStPanelStatus[m_nCurrentPanelID]->bConnectState)
  639. {
  640. //mLog::Error("Detector not connected, return");
  641. return false;
  642. }
  643. if (CCOS_CALIBRATION_TYPE_DARK == m_eCaliType)
  644. {
  645. //SetEvent(m_hDarkEvent);
  646. //mLog::Info("StartCalibration DARK");
  647. OnProcessDarkEnd();
  648. }
  649. else if (CCOS_CALIBRATION_TYPE_XRAY == m_eCaliType)
  650. {
  651. //mLog::Info("StartCalibration XRAY");
  652. SetEvent(m_hRadEvent); //StartCalibration
  653. }
  654. return true;
  655. }
  656. /***
  657. ** 说明:处理dark校正完成流程
  658. ***/
  659. void Detector_CareRayDR::OnProcessDarkEnd()
  660. {
  661. //mLog::Info("Refresh offset over");
  662. StatusFeedback(EVT_STATUS_CALIBRATIOIN, PANEL_EVENT_END_OK);
  663. }
  664. /***
  665. ** 说明:终止校正
  666. ***/
  667. RET_STATUS Detector_CareRayDR::AbortCalibration(FPDDeviceCareRay* pDrvDPC)
  668. {
  669. //mLog::Info("AbortCalibration");
  670. printf("AbortCalibration\n");
  671. m_eCaliType = CCOS_CALIBRATION_TYPE_NONE; //恢复初值
  672. RET_STATUS Ret = RET_STATUS::RET_FAILED;
  673. if (m_nCalibrationMode) //厂商校正
  674. {
  675. }
  676. else
  677. {
  678. //mLog::Info("Abort ZSKK calibration");
  679. m_pZSKKCalib->LoadZSKKGainMap(true, m_strDetectorType); //重新加载增益校正文件
  680. m_pZSKKCalib->AbortZSKKPixMap(m_strDetectorType); //放弃坏点校正并重新加载原来的坏点校正文件
  681. }
  682. //mLog::Info("AbortCalibration over");
  683. return RET_STATUS::RET_SUCCEED;
  684. }
  685. bool Detector_CareRayDR::StopCalibration(FPDDeviceCareRay* pDrvDPC)
  686. {
  687. if ((*m_pDPC2PanelID)[pDrvDPC] != m_nCurrentPanelID)
  688. {
  689. printf("Not current DPC, return\n");
  690. //mLog::Error("Not current DPC, return");
  691. return false;
  692. }
  693. if (!m_pStPanelStatus[m_nCurrentPanelID]->bConnectState)
  694. {
  695. //mLog::Error("Detector not connected, return");
  696. return false;
  697. }
  698. //mLog::Info("StopCalibration StopAcquisition");
  699. if (!StopAcquisition(pDrvDPC))
  700. {
  701. //mLog::Error("StopCalibration StopAcquisition failed");
  702. return false;
  703. }
  704. return true;
  705. }
  706. /***
  707. ** 说明:获取校正时间
  708. ** 连接成功后,校正完成后 获取
  709. ***/
  710. bool Detector_CareRayDR::GetCalibrationTime(int nDetectorID)
  711. {
  712. if (nDetectorID == -1)
  713. {
  714. nDetectorID = m_nCurrentPanelID;
  715. }
  716. else
  717. {
  718. InfoFeedback(EVT_INFO_CALIBRATIOIN_TIME, nDetectorID, 0, 0, "0");
  719. InfoFeedback(EVT_INFO_CALIBRATIOIN_TIMEL, nDetectorID, 0, 0, "0");
  720. }
  721. return true;
  722. }
  723. /***
  724. ** 说明:结束校正
  725. ** DPC处理完校正报告后调用,此处上传map、报告等文件
  726. ***/
  727. bool Detector_CareRayDR::CompleteCalibration(FPDDeviceCareRay* pDrvDPC)
  728. {
  729. //mLog::Info("CompleteCalibration calib type {$}", (int)m_eCaliType);
  730. if (m_eCaliType == CCOS_CALIBRATION_TYPE_DARK)
  731. {
  732. printf("DARK DARK Calib over \r\n");
  733. //mLog::Info("DARK Calib over");
  734. }
  735. else if (m_eCaliType == CCOS_CALIBRATION_TYPE_XRAY)
  736. {
  737. printf("XRAY Calib over \r\n");
  738. //mLog::Info("XRAY Calib over");
  739. GetCalibrationTime();
  740. StatusFeedback(EVT_STATUS_SAVECALIB, PANEL_EVENT_START);
  741. StatusFeedback(EVT_STATUS_SAVECALIB, PANEL_EVENT_END);
  742. }
  743. return true;
  744. }
  745. bool Detector_CareRayDR::SaveCalibrationFile()
  746. {
  747. //mLog::Info("Save Calibration File");
  748. if (m_nCalibrationMode)//厂商校正
  749. {
  750. //不做处理
  751. }
  752. else
  753. {
  754. //mLog::Info("Save ZSKK Calibration File");
  755. m_pZSKKCalib->StoreZSKKGainMap(m_strDetectorType);
  756. m_pZSKKCalib->StoreZSKKPixMap(m_strDetectorType);
  757. }
  758. //更新配置文件中校正日期和时间
  759. SYSTEMTIME stCurrentTime = { 0 };
  760. GetLocalTime(&stCurrentTime);
  761. //mLog::Info("Current time: {$04d}/{$02d}/{$02d} {$02d}:{$02d}:{$02d}:{$03d}",
  762. stCurrentTime.wYear, stCurrentTime.wMonth, stCurrentTime.wDay,
  763. stCurrentTime.wHour, stCurrentTime.wMinute, stCurrentTime.wSecond, stCurrentTime.wMilliseconds);
  764. //mLog::Info("Save Calibration File over");
  765. return true;
  766. }
  767. CCOS_CALIBRATION_TYPE Detector_CareRayDR::GetCalibType()
  768. {
  769. //mLog::Info("Get Calib Type {$}", (int)m_eCaliType);
  770. return m_eCaliType;
  771. }
  772. bool Detector_CareRayDR::ConfirmCalExposure()
  773. {
  774. bool bRet = false;
  775. return true;
  776. }
  777. void Detector_CareRayDR::RejectCalExposure()
  778. {
  779. //暂时什么都不处理
  780. }
  781. bool Detector_CareRayDR::LoadDll(string strWorkPath)
  782. {
  783. //mLog::Info("Start Load CareRay DLL");
  784. string strSDKPath = "";
  785. try
  786. {
  787. strSDKPath = (string)m_ModeConfig["SDKPath"];
  788. }
  789. catch (ResDataObjectExption& e)
  790. {
  791. //mLog::Error("Read configuration failed! reason: {$}", e.what());
  792. return false;
  793. }
  794. string workpath = strWorkPath + strSDKPath;
  795. string drvpath = workpath + "\\CareRayApi.dll";
  796. //mLog::Info("SDK path:{$}", drvpath);
  797. SetDllDirectory(workpath.c_str());
  798. m_hCareRayDRModule = LoadLibrary(drvpath.c_str());
  799. if (m_hCareRayDRModule == nullptr)
  800. {
  801. DWORD dw = GetLastError();
  802. //mLog::Error("Load {$} failed! error code: {$}", drvpath.c_str(), dw);
  803. return false;
  804. }
  805. LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrInitializeLibrary);
  806. LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrDeinitializeLibrary);
  807. LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrGetLastIntlMsg);
  808. LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrGetConfigItemValue);
  809. LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrSetConfigItemValue);
  810. LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrRegisterEventCallbackFun);
  811. LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrGetDetectorIndexAndIPAddress);
  812. LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrConnect);
  813. LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrResetDetector);
  814. LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrDisconnect);
  815. LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrGetSystemInformation);
  816. LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrGetApplicationMode);
  817. LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrRegisterApplicationMode);
  818. LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrSetFrameFilter);
  819. LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrGetModeInfoByAppModeKey);
  820. LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrGetRegedInfoByAppModeKey);
  821. LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrGetModeInfoByModeId);
  822. LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrLoadReference);
  823. LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrUnloadReference);
  824. LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrStartAcquisition);
  825. LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrStartDarkAcquisition);
  826. LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrStartDarkAcquisitionWithCorrOpt);
  827. LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrStopAcquisition);
  828. LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrStartDarkCalibration);
  829. LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrStartGainCalibration);
  830. LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrStopCalibration);
  831. LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrGetAcquisitionStatInfo);
  832. LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrQueryCalibrationStatus);
  833. LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrQueryReferenceStatus);
  834. LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrGetDefectInfo);
  835. LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrGetPositionDefectInfo);
  836. LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrQueryAcquisitionStatus);
  837. LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrQueryAedExposureProgress);
  838. LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrPermitExposure);
  839. LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrRequestExposure);
  840. LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrGetImage);
  841. LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrGetNoHeaderImage);
  842. LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrGetDetrStatus);
  843. LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrGetConnectionStatus);
  844. LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrStartAcquisitionWithCorrOpt);
  845. LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrGetDaecActiveAreas);
  846. LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrSetDaecActiveAreas);
  847. LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrGetBatteryInfos);
  848. LOAD_PROC_ADDRESS(m_hCareRayDRModule, CrGetWirelessStatus);
  849. //mLog::Info("Load CareRay API end");
  850. return true;
  851. }
  852. bool Detector_CareRayDR::ReleaseDll()
  853. {
  854. //mLog::Info("Release Careray dll");
  855. if (m_hCareRayDRModule != nullptr)
  856. {
  857. ::FreeLibrary(m_hCareRayDRModule);
  858. m_hCareRayDRModule = nullptr;
  859. }
  860. API_CrInitializeLibrary = nullptr;
  861. API_CrDeinitializeLibrary = nullptr;
  862. API_CrGetLastIntlMsg = nullptr;
  863. API_CrGetConfigItemValue = nullptr;
  864. API_CrSetConfigItemValue = nullptr;
  865. API_CrRegisterEventCallbackFun = nullptr;
  866. API_CrGetDetectorIndexAndIPAddress = nullptr;
  867. API_CrConnect = nullptr;
  868. API_CrResetDetector = nullptr;
  869. API_CrDisconnect = nullptr;
  870. API_CrGetSystemInformation = nullptr;
  871. API_CrGetApplicationMode = nullptr;
  872. API_CrRegisterApplicationMode = nullptr;
  873. API_CrSetFrameFilter = nullptr;
  874. API_CrGetModeInfoByAppModeKey = nullptr;
  875. API_CrGetRegedInfoByAppModeKey = nullptr;
  876. API_CrGetModeInfoByModeId = nullptr;
  877. API_CrLoadReference = nullptr;
  878. API_CrUnloadReference = nullptr;
  879. API_CrStartAcquisition = nullptr;
  880. API_CrStartDarkAcquisition = nullptr;
  881. API_CrStartDarkAcquisitionWithCorrOpt = nullptr;
  882. API_CrStopAcquisition = nullptr;
  883. API_CrStartDarkCalibration = nullptr;
  884. API_CrStartGainCalibration = nullptr;
  885. API_CrStopCalibration = nullptr;
  886. API_CrGetAcquisitionStatInfo = nullptr;
  887. API_CrQueryCalibrationStatus = nullptr;
  888. API_CrQueryReferenceStatus = nullptr;
  889. API_CrGetDefectInfo = nullptr;
  890. API_CrGetPositionDefectInfo = nullptr;
  891. API_CrQueryAcquisitionStatus = nullptr;
  892. API_CrQueryAedExposureProgress = nullptr;
  893. API_CrPermitExposure = nullptr;
  894. API_CrRequestExposure = nullptr;
  895. API_CrGetImage = nullptr;
  896. API_CrGetNoHeaderImage = nullptr;
  897. API_CrGetDetrStatus = nullptr;
  898. API_CrGetConnectionStatus = nullptr;
  899. API_CrStartAcquisitionWithCorrOpt = nullptr;
  900. API_CrGetDaecActiveAreas = nullptr;
  901. API_CrSetDaecActiveAreas = nullptr;
  902. API_CrGetBatteryInfos = nullptr;
  903. API_CrGetWirelessStatus = nullptr;
  904. return true;
  905. }
  906. /***
  907. ** 连接探测器
  908. ***/
  909. bool Detector_CareRayDR::OpenDetector()
  910. {
  911. //mLog::Info("OpenDetector start");
  912. int nRet = -1;
  913. CrDetrIdxAndIPAddr DetectorArray[8];
  914. int nValidDetectorNum = 0;
  915. int nActiveDetectorID = 0;
  916. //mLog::Info("Call CrGetDetectorIndexAndIPAddress");
  917. nRet = API_CrGetDetectorIndexAndIPAddress(DetectorArray, &nValidDetectorNum);
  918. if (!TestError(nRet))
  919. {
  920. //mLog::Error("Get detector index and IP address failed");
  921. }
  922. if (nValidDetectorNum <= 0)
  923. {
  924. //mLog::Info("System did not found detector");
  925. }
  926. //mLog::Info("System found detector number: {$}", nValidDetectorNum);
  927. m_nDetectorID = DetectorArray[0].index;
  928. //mLog::Info("DetectorArray[0].index : {$}", m_nDetectorID);
  929. int nDetectorIndex = m_nDetectorID - 1;
  930. //mLog::Info("API get detector number: {$}", nValidDetectorNum);
  931. //mLog::Info("Call CrConnect");
  932. nRet = API_CrConnect(m_nDetectorID);
  933. if (!TestError(nRet))
  934. {
  935. //mLog::Error("Connect Failed");
  936. return false;
  937. }
  938. m_pStPanelStatus[m_nCurrentPanelID]->bConnectState = true;
  939. //mLog::Info("m_pStPanelStatus[m_nCurrentPanelID]->bConnectState = true");
  940. StatusFeedback(EVT_STATUS_PANEL, PANEL_CONNECT);
  941. //mLog::Info("Connect detector({$}) success", m_nDetectorID);
  942. CrSystemInfo stSystemInfo;
  943. //mLog::Info("Call CrGetSystemInformation");
  944. nRet = API_CrGetSystemInformation(m_nDetectorID, &stSystemInfo);
  945. if (!TestError(nRet))
  946. {
  947. //mLog::Info("Get Detector Information Failed");
  948. }
  949. //mLog::Info("S/W version: {$}; F/W version: {$}; Detector SN: {$}; Machine ID: {$}; Raw image: [{$}, {$}]",
  950. stSystemInfo.software_version, stSystemInfo.firmware_version, stSystemInfo.serial_number, stSystemInfo.detr_machine_id,
  951. stSystemInfo.raw_img_height, stSystemInfo.raw_img_width);
  952. m_nRawImgHeight = stSystemInfo.raw_img_height;
  953. m_nRawImgWidth = stSystemInfo.raw_img_width;
  954. if (m_pRawImgBuffer == nullptr)
  955. {
  956. m_pRawImgBuffer = new WORD[(size_t)m_nRawImgHeight * (size_t)m_nRawImgWidth];
  957. }
  958. CrModeInfo AppModeInfo[8];
  959. int nModeNum = 0;
  960. //mLog::Info("Call CrGetApplicationMode");
  961. nRet = API_CrGetApplicationMode(m_nDetectorID, AppModeInfo, &nModeNum);
  962. if (!TestError(nRet))
  963. {
  964. //mLog::Error("Load Application Mode Failed");
  965. }
  966. for (int i = 0; i < nModeNum; i++)
  967. {
  968. //mLog::Info("AppMode({$}): mode_id({$}), max_frame_rate({$}), max_exp_time({$}), default_trig_type({$}), default_gain_level({$})",
  969. i, AppModeInfo[i].mode_id, AppModeInfo[i].max_frame_rate, AppModeInfo[i].max_exposure_time, AppModeInfo[i].default_trigger_type, AppModeInfo[i].default_gain_level);
  970. }
  971. OpenStatusMonitor();
  972. SetCareRayDPCStatus(eDetStatus::DetStatus_Standby);
  973. //mLog::Info("OpenDetector end");
  974. return true;
  975. }
  976. /***
  977. ** 初始化探测器
  978. ***/
  979. bool Detector_CareRayDR::InitDetector()
  980. {
  981. //mLog::Info("InitDetector start");
  982. int nRet = -1;
  983. //初始化时先reset,恢复缺省状态
  984. //mLog::Info("Call reset detector");
  985. nRet = API_CrResetDetector(m_nDetectorID, false);
  986. if (!TestError(nRet))
  987. {
  988. //mLog::Error("Reset detector failed");
  989. }
  990. //获取实际的探测器类型
  991. //mLog::Info("Call get detector type");
  992. //连接上探测器后获取gain校正曝光的总次数
  993. m_nGainExposureNum = ((FPDDeviceCareRay*)(*m_pPanelID2DPC)[m_nCurrentPanelID])->GetGainExposureNum();
  994. //mLog::Info("Gain Exposure Num:{$}", m_nGainExposureNum);
  995. m_bOnlyHaveFpd = ((FPDDeviceCareRay*)(*m_pPanelID2DPC)[m_nCurrentPanelID])->GetOnlyHaveFpd();
  996. if (m_bOnlyHaveFpd)
  997. {
  998. //mLog::Info("Current system only have FPD other is demo!");
  999. }
  1000. //mLog::Info("InitDetector end");
  1001. return true;
  1002. }
  1003. bool Detector_CareRayDR::OpenStatusMonitor()
  1004. {
  1005. //mLog::Info("---Open Status Monitor Thread---");
  1006. if (nullptr == m_hStatusMonitorThread)
  1007. {
  1008. unsigned uThreadId;
  1009. _beginthreadex(NULL, 0, CareRayStatusMonitorThread, this, 0, &uThreadId);
  1010. m_hStatusMonitorThread = OpenThread(THREAD_ALL_ACCESS, TRUE, uThreadId);
  1011. }
  1012. return false;
  1013. }
  1014. unsigned __stdcall Detector_CareRayDR::CareRayStatusMonitorThread(PVOID pvoid)
  1015. {
  1016. Detector_CareRayDR* pCurrentPanelOpr = (Detector_CareRayDR*)pvoid;
  1017. if (pCurrentPanelOpr == nullptr)
  1018. {
  1019. //mLog::Error("Careray Status Monitor parameter Error");
  1020. }
  1021. bool bExitFlag = false;
  1022. DWORD dwStatusCheckTime = 5000;
  1023. while (!bExitFlag)
  1024. {
  1025. DWORD dwRet = WaitForSingleObject(pCurrentPanelOpr->m_hExitStatusMonitorEvent, dwStatusCheckTime);
  1026. switch (dwRet)
  1027. {
  1028. case WAIT_OBJECT_0:
  1029. //mLog::Info("[Get ExitStatusMonitor Event]");
  1030. bExitFlag = true;
  1031. break;
  1032. case WAIT_TIMEOUT:
  1033. pCurrentPanelOpr->StatusMonitor();
  1034. break;
  1035. default:
  1036. break;
  1037. }
  1038. }
  1039. SetEvent(pCurrentPanelOpr->m_hStatusMonitorToggleEvent);
  1040. return 0;
  1041. }
  1042. bool Detector_CareRayDR::StatusMonitor()
  1043. {
  1044. int ret = CR_OK;
  1045. std::string strLog;
  1046. if (!m_pStPanelStatus[m_nCurrentPanelID]->bConnectState)
  1047. {
  1048. //mLog::Error("Detector not connected, return");
  1049. ErrorFeedback(EVT_ERR_COMMUNICATE, "true");
  1050. return false;
  1051. }
  1052. CrConnectionStatus stConnectionStatus;
  1053. ret = API_CrGetConnectionStatus(m_nDetectorID, &stConnectionStatus);
  1054. if (!TestError(ret))
  1055. {
  1056. //mLog::Warn("Get Detector connection status failed");
  1057. }
  1058. CrDetrStatus stDetectorStatus;
  1059. ret = API_CrGetDetrStatus(m_nDetectorID, &stDetectorStatus);
  1060. if (!TestError(ret))
  1061. {
  1062. //mLog::Warn("Get Detector Status Failed");
  1063. }
  1064. float fCPUTemperature = stDetectorStatus.detr_temperature.cpu - 20;
  1065. float fAverageTemperature = stDetectorStatus.detr_temperature.avg;
  1066. StatusFeedback(EVT_STATUS_TEMPERATURE, 0, "", m_nCurrentPanelID, fCPUTemperature);
  1067. CrBatteryInfo stDetectorBattery;
  1068. int batNum = 0;
  1069. ret = API_CrGetBatteryInfos(m_nDetectorID, &stDetectorBattery, &batNum);
  1070. if (!TestError(ret))
  1071. {
  1072. //mLog::Warn("Get Detector Battery Failed");
  1073. }
  1074. unsigned short BatteryStatus;
  1075. BatteryStatus = stDetectorBattery.relative_state_of_charge;
  1076. StatusFeedback(EVT_STATUS_BATTERY_VALUE, BatteryStatus * 100, "", m_nCurrentPanelID);
  1077. int WirelessStatus = 100;
  1078. CrWirelessStatus stDetectorWireless;
  1079. ret = API_CrGetWirelessStatus(m_nDetectorID, &stDetectorWireless);
  1080. if (!TestError(ret))
  1081. {
  1082. //mLog::Warn("Get Detector Wireless Failed");
  1083. }
  1084. WirelessStatus = stDetectorWireless.quality;
  1085. StatusFeedback(EVT_STATUS_WIFI, WirelessStatus, "", m_nCurrentPanelID);
  1086. return true;
  1087. }
  1088. bool Detector_CareRayDR::CloseStatusMonitor()
  1089. {
  1090. SetEvent(m_hExitStatusMonitorEvent);
  1091. DWORD dwResult = WaitForSingleObject(m_hStatusMonitorToggleEvent, 5000);
  1092. if (WAIT_TIMEOUT == dwResult)
  1093. {
  1094. ::TerminateThread(m_hStatusMonitorThread, 0);
  1095. //mLog::Warn("Kill Status Monitor Thread");
  1096. }
  1097. if (m_hExitStatusMonitorEvent != nullptr)
  1098. {
  1099. CloseHandle(m_hExitStatusMonitorEvent);
  1100. m_hExitStatusMonitorEvent = nullptr;
  1101. }
  1102. if (m_hStatusMonitorToggleEvent != nullptr)
  1103. {
  1104. CloseHandle(m_hStatusMonitorToggleEvent);
  1105. m_hStatusMonitorToggleEvent = nullptr;
  1106. }
  1107. m_hStatusMonitorThread = nullptr;
  1108. //mLog::Info("---Close Status Monitor Thread---");
  1109. return true;
  1110. }
  1111. bool Detector_CareRayDR::CloseDetectorScan()
  1112. {
  1113. SetEvent(m_hExitEvent);
  1114. DWORD dwResult = WaitForSingleObject(m_hDetectorScanToggleEvnet, 65000);
  1115. if (WAIT_TIMEOUT == dwResult)
  1116. {
  1117. //mLog::Error("Exit Scan Thread Failed. Time Out!");
  1118. }
  1119. else if (WAIT_OBJECT_0 == dwResult)
  1120. {
  1121. //mLog::Info("Exit Scan Thread Successful");
  1122. }
  1123. if (m_hInitEvent != nullptr)
  1124. {
  1125. CloseHandle(m_hInitEvent);
  1126. m_hInitEvent = nullptr;
  1127. }
  1128. if (m_hExitEvent != nullptr)
  1129. {
  1130. CloseHandle(m_hExitEvent);
  1131. m_hExitEvent = nullptr;
  1132. }
  1133. if (m_hReConnectEvent != nullptr)
  1134. {
  1135. CloseHandle(m_hReConnectEvent);
  1136. m_hReConnectEvent = nullptr;
  1137. }
  1138. if (m_hSwitchEvent != nullptr)
  1139. {
  1140. CloseHandle(m_hSwitchEvent);
  1141. m_hSwitchEvent = nullptr;
  1142. }
  1143. if (m_hRadEvent != nullptr)
  1144. {
  1145. CloseHandle(m_hRadEvent);
  1146. m_hRadEvent = nullptr;
  1147. }
  1148. if (m_hDualEnergyEvent != nullptr)
  1149. {
  1150. CloseHandle(m_hDualEnergyEvent);
  1151. m_hDualEnergyEvent = nullptr;
  1152. }
  1153. if (m_hOffsetEvent != nullptr)
  1154. {
  1155. CloseHandle(m_hOffsetEvent);
  1156. m_hOffsetEvent = nullptr;
  1157. }
  1158. if (m_hGainEvent != nullptr)
  1159. {
  1160. CloseHandle(m_hGainEvent);
  1161. m_hGainEvent = nullptr;
  1162. }
  1163. if (m_hDetectorScanToggleEvnet != nullptr)
  1164. {
  1165. CloseHandle(m_hDetectorScanToggleEvnet);
  1166. m_hDetectorScanToggleEvnet = nullptr;
  1167. }
  1168. return false;
  1169. }
  1170. /***
  1171. ** 显示当前采集模式的图像信息
  1172. ***/
  1173. int Detector_CareRayDR::ShowModeInfo()
  1174. {
  1175. CrModeInfo AppModeInfo[8];
  1176. int ret = CR_OK;
  1177. //mLog::Info("Call CrGetModeInfoByAppModeKey");
  1178. ret = API_CrGetModeInfoByAppModeKey(m_nDetectorID, m_nAppModeKey, AppModeInfo);
  1179. if (!TestError(ret))
  1180. {
  1181. //mLog::Error("Load application mode by key({$}) failed", m_nAppModeKey);
  1182. return false;
  1183. }
  1184. //mLog::Info("AppMode({$}): mode_id({$}), max_frame_rate({$}), max_exp_time({$}), default_trig_type({$}), default_gain_level({$})",
  1185. m_nAppModeKey, AppModeInfo[0].mode_id, AppModeInfo[0].max_frame_rate, AppModeInfo[0].max_exposure_time, AppModeInfo[0].default_trigger_type, AppModeInfo[0].default_gain_level);
  1186. return true;
  1187. }
  1188. /***
  1189. ** 设置同步模式、采集窗口
  1190. ***/
  1191. bool Detector_CareRayDR::SetApplicationMode()
  1192. {
  1193. //mLog::Info("SetApplicationMode");
  1194. int ret = CR_OK;
  1195. //mLog::Info("Set Application Mode: AppModeKey({$}), AppModeID({$}), frame_rate({$}), exposure_time({$}), trigger_type({$}), gain_level({$})",
  1196. m_nAppModeKey, m_nModeID, m_nFrameRate, m_nExtIntegrationTime, m_nTriggerType, m_nGainLevel);
  1197. //mLog::Info("Call CrStopAcquisition");
  1198. ret = API_CrStopAcquisition(m_nDetectorID);
  1199. if (!TestError(ret))
  1200. {
  1201. //mLog::Error("Stop Acquisition Failed");
  1202. return false;
  1203. }
  1204. //mLog::Info("Call CrRegisterApplicationMode");
  1205. float temp_FrameRate = (float)m_nFrameRate;
  1206. float temp_ExposureTime = (float)m_nExtIntegrationTime;
  1207. ret = API_CrRegisterApplicationMode(m_nDetectorID, m_nAppModeKey, m_nModeID, &temp_FrameRate, &temp_ExposureTime, m_nTriggerType, m_nGainLevel, 0, 0);
  1208. if (!TestError(ret))
  1209. {
  1210. //mLog::Error("Register application mode failed");
  1211. return false;
  1212. }
  1213. //mLog::Info("Register application mode successful");
  1214. return true;
  1215. }
  1216. bool Detector_CareRayDR::LoadCalibrationFiles()
  1217. {
  1218. //mLog::Info("## LoadCalibrationFiles ##");
  1219. int ret = CR_OK;
  1220. //mLog::Info("Call CrLoadReference");
  1221. ret = API_CrLoadReference(m_nDetectorID, m_nAppModeKey);
  1222. if (!TestError(ret))
  1223. {
  1224. //mLog::Error("Load Reference failed");
  1225. return false;
  1226. }
  1227. return true;
  1228. }
  1229. unsigned __stdcall Detector_CareRayDR::onFPDScanThread(PVOID pvoid)
  1230. {
  1231. Detector_CareRayDR* pOpr = (Detector_CareRayDR*)pvoid;
  1232. //mLog::Info("Enter scan thread");
  1233. printf("Enter scan thread \r\n");
  1234. bool bExit = false;
  1235. DWORD dwTimeOut = INFINITE;
  1236. while (!bExit)
  1237. {
  1238. ////mLog::Info("Waiting for signal...");
  1239. DWORD dwRet = WaitForMultipleObjects(8, pOpr->m_hArrayEvent, FALSE, dwTimeOut);
  1240. if (WAIT_OBJECT_0 == dwRet) //m_hInitEvent
  1241. {
  1242. pOpr->OnProcessInitFPD();
  1243. }
  1244. else if (WAIT_OBJECT_0 + 1 == dwRet) //m_hExitEvent
  1245. {
  1246. bExit = true;
  1247. }
  1248. else if (WAIT_OBJECT_0 + 2 == dwRet) //m_hReConnectEvent
  1249. {
  1250. }
  1251. else if (WAIT_OBJECT_0 + 3 == dwRet) //m_hSwitchEvent
  1252. {
  1253. }
  1254. else if (WAIT_OBJECT_0 + 4 == dwRet) //m_hRadEvent
  1255. {
  1256. //mLog::Info("[Get Rad Event]");
  1257. pOpr->OpenRadAcquisition();
  1258. }
  1259. else if (WAIT_OBJECT_0 + 5 == dwRet) //m_hDualEnergyEvent
  1260. {
  1261. //mLog::Info("[Get Dual Energy Event]");
  1262. pOpr->OpenDualEnergyAcquisition();
  1263. }
  1264. else if (WAIT_OBJECT_0 + 6 == dwRet) //
  1265. {
  1266. }
  1267. else if (WAIT_TIMEOUT == dwRet)
  1268. {
  1269. pOpr->OnReconnectFPD();
  1270. }
  1271. }
  1272. SetEvent(pOpr->m_hToggleEvent);
  1273. //mLog::Info("Leave scan thread");
  1274. printf("Leave scan thread \r\n");
  1275. return 0;
  1276. }
  1277. void Detector_CareRayDR::OnStartDarkCalibration()
  1278. {
  1279. //mLog::Info("dark calibration start");
  1280. int nRet = -1;
  1281. //mLog::Info("Call stop cal procedure(FALSE)");
  1282. //mLog::Info("dark calibration end");
  1283. }
  1284. void Detector_CareRayDR::OnAcquireGainImage()
  1285. {
  1286. //mLog::Info("OnAcquireGainImage start");
  1287. //mLog::Info("OnAcquireGainImage end");
  1288. }
  1289. void Detector_CareRayDR::OnProcessInitFPD()
  1290. {
  1291. int ret;
  1292. //mLog::Info("OnProcessInitFPD start");
  1293. StatusFeedback(EVT_STATUS_INIT, PANEL_EVENT_START);
  1294. if (!LoadDll(m_strWorkPath))
  1295. {
  1296. ErrorFeedback(EVT_ERR_INIT_FAILED, "true");
  1297. StatusFeedback(EVT_STATUS_INIT, PANEL_EVENT_END_ERROR); //初始化失败
  1298. return;
  1299. }
  1300. //mLog::Info("Call CrRegisterEventCallbackFun");
  1301. ret = API_CrRegisterEventCallbackFun(CREventCallback);
  1302. if (!TestError(ret))
  1303. {
  1304. ErrorFeedback(EVT_ERR_INIT_FAILED, "true");
  1305. StatusFeedback(EVT_STATUS_INIT, PANEL_EVENT_END_ERROR);
  1306. }
  1307. if (!OpenDetector())
  1308. {
  1309. printf("Open detector failed, Connect failed \r\n");
  1310. //mLog::Info("Open detector failed, Connect failed");
  1311. ErrorFeedback(EVT_ERR_COMMUNICATE, "true");
  1312. StatusFeedback(EVT_STATUS_INIT, PANEL_EVENT_END); //初始化时连接失败
  1313. }
  1314. else
  1315. {
  1316. m_pStPanelStatus[m_nCurrentPanelID]->bInitOver = true;
  1317. StatusFeedback(EVT_STATUS_INIT, PANEL_EVENT_END_OK);
  1318. }
  1319. //mLog::Info("OnProcessInitFPD end");
  1320. }
  1321. void Detector_CareRayDR::OnReconnectFPD()
  1322. {
  1323. //mLog::Info("OnReconnectFPD start");
  1324. //初始化完成后
  1325. if (!m_pStPanelStatus[m_nCurrentPanelID]->bInitOver)
  1326. {
  1327. string strIP = "";
  1328. try
  1329. {
  1330. strIP = (string)m_ModeConfig["connections"]["WiredIP"];
  1331. }
  1332. catch (ResDataObjectExption& e)
  1333. {
  1334. //mLog::Error("Read configuration failed, Error code: {$}", e.what());
  1335. return;
  1336. }
  1337. if (IsConnected(strIP))
  1338. {
  1339. StatusFeedback(EVT_STATUS_INIT, PANEL_EVENT_START);
  1340. if (OpenDetector())
  1341. {
  1342. if (InitDetector())
  1343. {
  1344. m_pStPanelStatus[m_nCurrentPanelID]->bInitOver = true;
  1345. ErrorFeedback(EVT_ERR_COMMUNICATE, "false");
  1346. StatusFeedback(EVT_STATUS_INIT, PANEL_EVENT_END_OK);
  1347. }
  1348. else
  1349. {
  1350. ErrorFeedback(EVT_ERR_INIT_FAILED, "true");
  1351. StatusFeedback(EVT_STATUS_INIT, PANEL_EVENT_END_ERROR); //重新初始化失败
  1352. }
  1353. }
  1354. else
  1355. {
  1356. StatusFeedback(EVT_STATUS_INIT, PANEL_EVENT_END); //重新初始化时连接失败
  1357. }
  1358. }
  1359. }
  1360. //mLog::Info("OnReconnectFPD end");
  1361. }
  1362. /***
  1363. ** 获取一帧暗场图
  1364. ***/
  1365. int Detector_CareRayDR::DarkAcquisition()
  1366. {
  1367. int nRet = -1;
  1368. int printOver = 0, awaitOver = 0;
  1369. //mLog::Info("Call set normal power");
  1370. return nRet;
  1371. }
  1372. /***
  1373. ** 轮询Manual(SDK的半aed模式)、aed模式采集状态
  1374. ***/
  1375. int Detector_CareRayDR::QueryAutoProgInfo(bool bIsAED)
  1376. {
  1377. //mLog::Info("Begin query auto exposure progress info");
  1378. return CR_NO_ERR;
  1379. }
  1380. /***
  1381. ** 轮询硬同步模式采集状态
  1382. ***/
  1383. int Detector_CareRayDR::QueryRadProgInfo()
  1384. {
  1385. //mLog::Info("Begin query rad exposure progress info");
  1386. return CR_NO_ERR;
  1387. }
  1388. void Detector_CareRayDR::SaveRawFunc(WORD* pInImg, int nImgWidth, int nImgHeight, string strFrameID)
  1389. {
  1390. FILE* fp;
  1391. string strFileName = "";
  1392. if (strFrameID == "")
  1393. {
  1394. strFileName = m_strWorkPath + "\\Image\\Raw.raw";
  1395. }
  1396. else
  1397. {
  1398. strFileName = m_strWorkPath + "\\Image\\Frame" + strFrameID + ".raw";
  1399. }
  1400. //mLog::Info("image file name:{$}", strFileName);
  1401. if ((fp = fopen(strFileName.c_str(), "wb")) == NULL)
  1402. {
  1403. DWORD dw = GetLastError();
  1404. //mLog::Error("fopen {$} failed, error code:{$}", strFileName, dw);
  1405. return;
  1406. }
  1407. fwrite(pInImg, sizeof(WORD), (size_t)nImgWidth * (size_t)nImgHeight, fp);
  1408. fclose(fp);
  1409. //mLog::Info("Save image over");
  1410. }
  1411. /***
  1412. ** 裁剪图像
  1413. ** pOutImg: 裁剪后图像; pInImg: 裁剪前图像; nInWidth: 裁剪前图像宽度
  1414. ***/
  1415. bool Detector_CareRayDR::GetEffectiveImage(WORD* pOutImg, WORD* pInImg, int nInWidth)
  1416. {
  1417. if (pOutImg == NULL || pInImg == NULL || nInWidth < 0)
  1418. {
  1419. //mLog::Error("Illegal parameter, can not get effective image");
  1420. return false;
  1421. }
  1422. try
  1423. {
  1424. for (int i = 0; i < m_nImageHeight; i++)
  1425. {
  1426. memcpy(pOutImg + i * m_nImageWidth, pInImg + (i + m_nHeightOffset) * nInWidth + m_nWidthOffset, m_nImageWidth * sizeof(WORD));
  1427. }
  1428. }
  1429. catch (...)
  1430. {
  1431. //mLog::Error("Get effective image crashed");
  1432. return false;
  1433. }
  1434. return true;
  1435. }
  1436. //设置校正选项,选择是否加载校正文件
  1437. bool Detector_CareRayDR::SetUserCorrection(bool bLoad)
  1438. {
  1439. return true;
  1440. }
  1441. /***
  1442. ** 计算一键校正曝光的图像灰度
  1443. ***/
  1444. double Detector_CareRayDR::GetMean(WORD* imgNoHeader, int pixelNum)
  1445. {
  1446. double imgMean = 0;
  1447. for (int i = 0; i < pixelNum; i++)
  1448. {
  1449. imgMean += imgNoHeader[i];
  1450. }
  1451. imgMean = imgMean / pixelNum;
  1452. return imgMean;
  1453. }
  1454. Detector_CareRayDR::eDetStatus Detector_CareRayDR::GetCareRayDPCStatus(int nDetectorIndex)
  1455. {
  1456. if (-1 == nDetectorIndex)
  1457. {
  1458. nDetectorIndex = m_nCurrentPanelID;
  1459. }
  1460. string strStatus = "Unknown";
  1461. switch (m_pStPanelStatus[nDetectorIndex]->eFPDStatus)
  1462. {
  1463. case eDetStatus::DetStatus_NotIni:
  1464. strStatus = "NotIni";
  1465. break;
  1466. case eDetStatus::DetStatus_NotConn:
  1467. strStatus = "NotConn";
  1468. break;
  1469. case eDetStatus::DetStatus_Sleep:
  1470. strStatus = "Sleep";
  1471. break;
  1472. case eDetStatus::DetStatus_Standby:
  1473. strStatus = "Standby";
  1474. break;
  1475. case eDetStatus::DetStatus_Work:
  1476. strStatus = "Work";
  1477. break;
  1478. case eDetStatus::DetStatus_Acquire:
  1479. strStatus = "Acquire";
  1480. break;
  1481. case eDetStatus::DetStatus_Offset:
  1482. strStatus = "Offset";
  1483. break;
  1484. case eDetStatus::DetStatus_XrayCalibration:
  1485. strStatus = "XrayCalibration";
  1486. break;
  1487. default:
  1488. break;
  1489. }
  1490. //mLog::Info("Driver status: {$}", strStatus.c_str());
  1491. return m_pStPanelStatus[nDetectorIndex]->eFPDStatus;
  1492. }
  1493. bool Detector_CareRayDR::SetCareRayDPCStatus(eDetStatus status, int nDetectorIndex)
  1494. {
  1495. if (-1 == nDetectorIndex)
  1496. {
  1497. nDetectorIndex = m_nCurrentPanelID;
  1498. }
  1499. string strStatus = "Unknown";
  1500. bool bSetStatus = true;
  1501. switch (status)
  1502. {
  1503. case eDetStatus::DetStatus_NotIni:
  1504. strStatus = "NotIni";
  1505. break;
  1506. case eDetStatus::DetStatus_NotConn:
  1507. strStatus = "NotConn";
  1508. break;
  1509. case eDetStatus::DetStatus_Sleep:
  1510. strStatus = "Sleep";
  1511. break;
  1512. case eDetStatus::DetStatus_Standby:
  1513. strStatus = "Standby";
  1514. break;
  1515. case eDetStatus::DetStatus_Work:
  1516. strStatus = "Work";
  1517. break;
  1518. case eDetStatus::DetStatus_Acquire:
  1519. strStatus = "Acquire";
  1520. break;
  1521. case eDetStatus::DetStatus_Offset:
  1522. strStatus = "Offset";
  1523. break;
  1524. case eDetStatus::DetStatus_XrayCalibration:
  1525. strStatus = "XrayCalibration";
  1526. break;
  1527. default:
  1528. bSetStatus = false;
  1529. break;
  1530. }
  1531. if (bSetStatus)
  1532. {
  1533. m_pStPanelStatus[nDetectorIndex]->eFPDStatus = status;
  1534. //mLog::Info("Set driver status: {$}", strStatus.c_str());
  1535. }
  1536. else
  1537. {
  1538. //mLog::Error("{$} {$} is a illegal status", strStatus, (int)status);
  1539. }
  1540. return bSetStatus;
  1541. }
  1542. bool Detector_CareRayDR::IsConnected(string strIP)
  1543. {
  1544. //mLog::Info("Check ping {$}", strIP);
  1545. CMyPingip obPingIp;
  1546. //StatusFeedback(EVT_STATUS_PING, 0, "true");
  1547. if (!obPingIp.PingFunction(strIP.c_str()))
  1548. {
  1549. //mLog::Info("ping {$} Failed", strIP);
  1550. //StatusFeedback(EVT_STATUS_PING, 0, "false");
  1551. return false;
  1552. }
  1553. return true;
  1554. }
  1555. bool Detector_CareRayDR::GetTriggerType(int nTriggerModeID)
  1556. {
  1557. //mLog::Info("Get TriggerType");
  1558. switch (nTriggerModeID)
  1559. {
  1560. case 0:
  1561. m_nTriggerType = CrTrigType::CR_RAD_MANUAL_SYNC;
  1562. //mLog::Info("TriggerType is CR_RAD_MANUAL_SYNC");
  1563. break;
  1564. case 1:
  1565. m_nTriggerType = CrTrigType::CR_RAD_SOFT_SYNC;
  1566. //mLog::Info("TriggerType is CR_RAD_SOFT_SYNC");
  1567. break;
  1568. case 2:
  1569. m_nTriggerType = CrTrigType::CR_RAD_EXT_SYNC;
  1570. //mLog::Info("TriggerType is CR_RAD_EXT_SYNC");
  1571. break;
  1572. case 3:
  1573. m_nTriggerType = CrTrigType::CR_RAD_AED_SYNC;
  1574. //mLog::Info("TriggerType is CR_RAD_AED_SYNC");
  1575. break;
  1576. case 4:
  1577. m_nTriggerType = CrTrigType::CR_RAD_AUTO_SYNC;
  1578. //mLog::Info("TriggerType is CR_RAD_AUTO_SYNC");
  1579. break;
  1580. case 5:
  1581. m_nTriggerType = CrTrigType::CR_RAD_DAEC_SYNC;
  1582. //mLog::Info("TriggerType is CR_RAD_DAEC_SYNC");
  1583. break;
  1584. case 6:
  1585. m_nTriggerType = CrTrigType::CR_RAD_DAEC_FLIP_SYNC;
  1586. //mLog::Info("TriggerType is CR_RAD_DAEC_FLIP_SYNC");
  1587. break;
  1588. case 7:
  1589. m_nTriggerType = CrTrigType::CR_FLUORO_EXT_SYNC;
  1590. //mLog::Info("TriggerType is CR_FLUORO_EXT_SYNC");
  1591. break;
  1592. case 8:
  1593. m_nTriggerType = CrTrigType::CR_FLUORO_INT_SYNC;
  1594. //mLog::Info("TriggerType is CR_FLUORO_INT_SYNC");
  1595. break;
  1596. default:
  1597. break;
  1598. }
  1599. return true;
  1600. }
  1601. bool Detector_CareRayDR::CheckConnection()
  1602. {
  1603. return false;
  1604. }
  1605. bool Detector_CareRayDR::ReConnectFPD()
  1606. {
  1607. CloseStatusMonitor();
  1608. return true;
  1609. }
  1610. bool Detector_CareRayDR::OpenRadAcquisition()
  1611. {
  1612. //mLog::Info("---Begin Rad Acquisition Thread---");
  1613. m_bExitRadAcqStatus = false;
  1614. if (nullptr == m_hRadAcquisitionThread)
  1615. {
  1616. unsigned uThreadId;
  1617. _beginthreadex(NULL, 0, RadAcquisitionThread, this, 0, &uThreadId);
  1618. m_hRadAcquisitionThread = OpenThread(THREAD_ALL_ACCESS, TRUE, uThreadId);
  1619. }
  1620. return true;
  1621. }
  1622. UINT Detector_CareRayDR::RadAcquisitionThread(LPVOID pParam)
  1623. {
  1624. Detector_CareRayDR* pCurrentPanelOpr = reinterpret_cast<Detector_CareRayDR*>(pParam);
  1625. if (pCurrentPanelOpr == nullptr)
  1626. {
  1627. //mLog::Error("Query Acq Status Thread parameter error");
  1628. }
  1629. pCurrentPanelOpr->PerformRadAcquisition();
  1630. pCurrentPanelOpr->CloseRadAcquisition();
  1631. return 0;
  1632. }
  1633. bool Detector_CareRayDR::PerformRadAcquisition()
  1634. {
  1635. //mLog::Info("## PerformRadAcquisition ##");
  1636. int nRes = CR_OK;
  1637. int nWaitPermissionHint = 0;
  1638. //mLog::Info("Call CrStartAcquisition");
  1639. //mLog::Info("DetectorID: {$}, AppModeKey: {$}", m_nDetectorID, m_nAppModeKey);
  1640. nRes = API_CrStartAcquisition(m_nDetectorID, m_nAppModeKey, 0);
  1641. if (!TestError(nRes))
  1642. {
  1643. //mLog::Error("Failed to start Acquisition");
  1644. return false;
  1645. }
  1646. //if (m_nTriggerType != CR_RAD_SOFT_SYNC || m_nTriggerType != CR_RAD_AED_SYNC)
  1647. //{
  1648. // StatusFeedback(EVT_STATUS_PANEL, PANEL_XWINDOW_ON);
  1649. //}
  1650. CrExpProgress progress;
  1651. memset(&progress, 0, sizeof(progress));
  1652. bool bRepeatReady = false;
  1653. bool bRepeatXWindowOn = false;
  1654. bool bRepeatInit = false;
  1655. bool bPromptPressHandSwitch = true;
  1656. while (true)
  1657. {
  1658. if (m_nTriggerType != CR_RAD_AED_SYNC)
  1659. {
  1660. nRes = API_CrQueryAcquisitionStatus(m_nDetectorID, &progress);
  1661. if (!TestError(nRes))
  1662. {
  1663. //mLog::Error("Query acquisition status failed");
  1664. break;
  1665. }
  1666. switch (progress.exposure_status)
  1667. {
  1668. case CR_EXP_ERROR:
  1669. //mLog::Error("Acquisition status: exposure error");
  1670. m_bExitRadAcqStatus = true;
  1671. break;
  1672. case CR_EXP_INIT:
  1673. if (!bRepeatInit)
  1674. {
  1675. //mLog::Info("Acquisition status: init");
  1676. bRepeatInit = true;
  1677. }
  1678. break;
  1679. case CR_EXP_READY:
  1680. if (!bRepeatReady)
  1681. {
  1682. StatusFeedback(EVT_STATUS_PANEL, PANEL_READY_EXP);
  1683. //mLog::Info("Acquisition status: ready");
  1684. bRepeatReady = true;
  1685. }
  1686. if (!bRepeatXWindowOn)
  1687. {
  1688. //mLog::Info("Acquisition status: expose");
  1689. bRepeatXWindowOn = true;
  1690. }
  1691. case CR_EXP_WAIT_PERMISSION:
  1692. if (m_nTriggerType == CrTrigType::CR_RAD_EXT_SYNC)
  1693. {
  1694. //mLog::Info("Acquisition status: wait permission");
  1695. if (0 == nWaitPermissionHint)
  1696. {
  1697. nRes = API_CrPermitExposure(m_nDetectorID);
  1698. //mLog::Info("CrPermitExposure Result: {$}", nRes);
  1699. if (nRes != CR_OK)
  1700. {
  1701. break;
  1702. }
  1703. nWaitPermissionHint++;
  1704. }
  1705. }
  1706. break;
  1707. case CR_EXP_PERMITTED:
  1708. //mLog::Info("Acquisition status: permitted");
  1709. break;
  1710. case CR_EXP_EXPOSE:
  1711. if (!bRepeatXWindowOn)
  1712. {
  1713. //mLog::Info("Acquisition status: expose");
  1714. bRepeatXWindowOn = true;
  1715. }
  1716. break;
  1717. case CR_EXP_COMPLETE:
  1718. //mLog::Info("Acquisition status: complete");
  1719. break;
  1720. default:
  1721. break;
  1722. }
  1723. if (progress.is_fetchable)
  1724. {
  1725. //mLog::Info("Image Arrive");
  1726. if (m_nTriggerType == CR_RAD_SOFT_SYNC)
  1727. {
  1728. StatusFeedback(EVT_STATUS_PANEL, PANEL_XWINDOW_OFF);
  1729. }
  1730. StatusFeedback(EVT_STATUS_PANEL, PANEL_START_TRANSMIT);
  1731. //mLog::Info("## Get Image ##");
  1732. int ret = CR_OK;
  1733. //mLog::Info("Call CrGetNoHeaderImage, DetectorID: {$}, width: {$}, height: {$}", m_nDetectorID, m_nRawImgWidth, m_nRawImgHeight);
  1734. ret = API_CrGetNoHeaderImage(m_nDetectorID, (char*)m_pImgBuffer, m_nRawImgHeight * m_nRawImgWidth * 2, 9000);
  1735. if (!TestError(ret))
  1736. {
  1737. //mLog::Error("Get image raw data failed");
  1738. }
  1739. if (m_bSaveRaw)
  1740. {
  1741. std::string strFileName = m_strWorkPath + "\\rawdata";
  1742. strFileName += "\\Image.raw";
  1743. std::filesystem::path file_path{ strFileName.c_str() };
  1744. std::ofstream file_stream(file_path, std::ios::binary);
  1745. if (!file_stream.is_open())
  1746. {
  1747. //mLog::Error("Open Save File Failed");
  1748. }
  1749. unsigned int nTempSize = m_nRawImgHeight * m_nRawImgWidth * 2;
  1750. file_stream.write(reinterpret_cast<const char*>(m_pImgBuffer), nTempSize);
  1751. file_stream.close();
  1752. }
  1753. DataFeedback(EVT_DATA_RAW_IMAGE, m_pImgBuffer);
  1754. m_bExitRadAcqStatus = true;
  1755. }
  1756. if (m_bExitRadAcqStatus)
  1757. {
  1758. //mLog::Info("Exit Rad Acq Status");
  1759. int nRes = CR_OK;
  1760. //mLog::Info("Call CrStopAcquisition");
  1761. nRes = API_CrStopAcquisition(m_nDetectorID);
  1762. if (!TestError(nRes))
  1763. {
  1764. //mLog::Error("Stop Acquisition Failed");
  1765. }
  1766. StatusFeedback(EVT_STATUS_PANEL, PANEL_STANDBY);
  1767. break;
  1768. }
  1769. }
  1770. else
  1771. {
  1772. nRes = API_CrQueryAcquisitionStatus(m_nDetectorID, &progress);
  1773. if (!TestError(nRes))
  1774. {
  1775. //mLog::Error("Query acquisition status failed");
  1776. break;
  1777. }
  1778. if (CR_EXP_READY == progress.exposure_status)
  1779. {
  1780. if (bPromptPressHandSwitch)
  1781. {
  1782. //mLog::Info("Press hand switch now!");
  1783. StatusFeedback(EVT_STATUS_PANEL, PANEL_READY_EXP);
  1784. bPromptPressHandSwitch = false;
  1785. }
  1786. }
  1787. else
  1788. {
  1789. if (!bPromptPressHandSwitch)
  1790. {
  1791. //mLog::Info("Don't press hand switch now!");
  1792. bPromptPressHandSwitch = true;
  1793. }
  1794. }
  1795. if (progress.is_fetchable)
  1796. {
  1797. //mLog::Info("Radiographic image is available now");
  1798. StatusFeedback(EVT_STATUS_PANEL, PANEL_XWINDOW_ON);
  1799. StatusFeedback(EVT_STATUS_PANEL, PANEL_START_TRANSMIT);
  1800. //mLog::Info("## Get Image ##");
  1801. int ret = CR_OK;
  1802. //mLog::Info("Call CrGetNoHeaderImage, DetectorID: {$}, width: {$}, height: {$}", m_nDetectorID, m_nRawImgWidth, m_nRawImgHeight);
  1803. ret = API_CrGetNoHeaderImage(m_nDetectorID, (char*)m_pImgBuffer, m_nRawImgHeight * m_nRawImgWidth * 2, 9000);
  1804. if (!TestError(ret))
  1805. {
  1806. //mLog::Error("Get image raw data failed");
  1807. }
  1808. if (m_bSaveRaw)
  1809. {
  1810. std::string strFileName = m_strWorkPath + "\\rawdata";
  1811. strFileName += "\\Image.raw";
  1812. std::filesystem::path file_path{ strFileName.c_str() };
  1813. std::ofstream file_stream(file_path, std::ios::binary);
  1814. if (!file_stream.is_open())
  1815. {
  1816. //mLog::Error("Open Save File Failed");
  1817. }
  1818. unsigned int nTempSize = m_nRawImgHeight * m_nRawImgWidth * 2;
  1819. file_stream.write(reinterpret_cast<const char*>(m_pImgBuffer), nTempSize);
  1820. file_stream.close();
  1821. }
  1822. DataFeedback(EVT_DATA_RAW_IMAGE, m_pImgBuffer);
  1823. m_bExitRadAcqStatus = true;
  1824. }
  1825. if (m_bExitRadAcqStatus)
  1826. {
  1827. //mLog::Info("Exit Rad Acq Status");
  1828. int nRes = CR_OK;
  1829. //mLog::Info("Call CrStopAcquisition");
  1830. nRes = API_CrStopAcquisition(m_nDetectorID);
  1831. if (!TestError(nRes))
  1832. {
  1833. //mLog::Error("Stop Acquisition Failed");
  1834. }
  1835. StatusFeedback(EVT_STATUS_PANEL, PANEL_STANDBY);
  1836. break;
  1837. }
  1838. }
  1839. }
  1840. SetEvent(m_hExitRadAcqStatus);
  1841. //mLog::Info("PerformRadAcquisition Over");
  1842. return true;
  1843. }
  1844. bool Detector_CareRayDR::CloseRadAcquisition()
  1845. {
  1846. m_bExitRadAcqStatus = true;
  1847. DWORD dwResult = WaitForSingleObject(m_hExitRadAcqStatus, 1000);
  1848. if (dwResult == WAIT_OBJECT_0)
  1849. {
  1850. //mLog::Info("[Get ExitRadAcqStatus Event]");
  1851. }
  1852. else if (dwResult == WAIT_TIMEOUT)
  1853. {
  1854. ::TerminateThread(m_hRadAcquisitionThread, 0);
  1855. //mLog::Warn("Kill QueryAcqStatus Thread");
  1856. }
  1857. if (m_hExitRadAcqStatus != nullptr)
  1858. {
  1859. CloseHandle(m_hExitRadAcqStatus);
  1860. m_hExitRadAcqStatus = nullptr;
  1861. }
  1862. m_hRadAcquisitionThread = nullptr;
  1863. //mLog::Info("---Exit Rad Acq Status Thread---");
  1864. return true;
  1865. }
  1866. bool Detector_CareRayDR::OpenDualEnergyAcquisition()
  1867. {
  1868. //mLog::Info("---Begin DualEnergy Acquisition Thread---");
  1869. m_bExitDualAcqStatus = false;
  1870. if (nullptr == m_hDualEnergyAcquisitionThread)
  1871. {
  1872. unsigned uThreadId;
  1873. _beginthreadex(NULL, 0, DualEnergyAcquisitionThread, this, 0, &uThreadId);
  1874. m_hDualEnergyAcquisitionThread = OpenThread(THREAD_ALL_ACCESS, TRUE, uThreadId);
  1875. }
  1876. return true;
  1877. }
  1878. UINT Detector_CareRayDR::DualEnergyAcquisitionThread(LPVOID pParam)
  1879. {
  1880. Detector_CareRayDR* pCurrentPanelOpr = reinterpret_cast<Detector_CareRayDR*>(pParam);
  1881. if (pCurrentPanelOpr == nullptr)
  1882. {
  1883. //mLog::Error("Query Acq Status Thread parameter error");
  1884. }
  1885. pCurrentPanelOpr->PerformDualEnergyAcquisition();
  1886. pCurrentPanelOpr->CloseDualEnergyAcquisition();
  1887. return 0;
  1888. }
  1889. bool Detector_CareRayDR::PerformDualEnergyAcquisition()
  1890. {
  1891. //mLog::Info("[PerformDualEnergyAcquisition]");
  1892. int nDualEnergyExpNum = 0;
  1893. int nDualEnergyExp = 0;
  1894. m_bDualEnergyFirstExpEnableDone = false;
  1895. m_bDualEnergySecondExpEnable = false;
  1896. int nRet = CR_OK;
  1897. int nWaitPermissionHint = 0;
  1898. int nLoop = 0;
  1899. int nDualFlag = 0;
  1900. //mLog::Info("Call CrStartAcquisition");
  1901. nRet = API_CrStartAcquisition(m_nDetectorID, m_nAppModeKey, 0);
  1902. //mLog::Info("m_nDetectorID: {$}, m_nAppModeKey: {$}", m_nDetectorID, m_nAppModeKey);
  1903. if (!TestError(nRet))
  1904. {
  1905. //mLog::Error("Failed to start acquisition");
  1906. }
  1907. CrExpProgress progress;
  1908. memset(&progress, 0, sizeof(progress));
  1909. bool bRepeatReady = false;
  1910. bool bRepeatXWindowOn = false;
  1911. bool bRepeatInit = false;
  1912. while (true)
  1913. {
  1914. nRet = API_CrQueryAcquisitionStatus(m_nDetectorID, &progress);
  1915. if (!TestError(nRet))
  1916. {
  1917. //mLog::Error("Query acquisition status failed");
  1918. break;
  1919. }
  1920. switch (progress.exposure_status)
  1921. {
  1922. case CR_EXP_ERROR:
  1923. //mLog::Error("Acquisition status: exposure error");
  1924. m_bExitRadAcqStatus = true;
  1925. case CR_EXP_INIT:
  1926. if (!bRepeatInit)
  1927. {
  1928. //mLog::Info("Acquisition status: init");
  1929. bRepeatInit = true;
  1930. }
  1931. break;
  1932. case CR_EXP_READY:
  1933. if (nDualEnergyExpNum == 0 && CR_RAD_SOFT_SYNC == m_nTriggerType)
  1934. {
  1935. //mLog::Info("Detector is ready for dual energy Acquisition, press x-ray hand switch now...");
  1936. if (!bRepeatReady)
  1937. {
  1938. //StatusFeedback(EVT_STATUS_PANEL, PANEL_START_ACQ);
  1939. //StatusFeedback(EVT_STATUS_PANEL, PANEL_READY_EXP);
  1940. //mLog::Info("Acquisition status: ready");
  1941. bRepeatReady = true;
  1942. }
  1943. nDualEnergyExpNum++;
  1944. }
  1945. break;
  1946. case CR_EXP_EXPOSE:
  1947. if (nDualEnergyExp == 0)
  1948. {
  1949. //mLog::Info("exp expose");
  1950. //mLog::Info("Status Polled >> Detector is in EXPOSE state, emit X-Ray now...");
  1951. StatusFeedback(EVT_STATUS_PANEL, PANEL_XWINDOW_ON);
  1952. int nRes = CR_OK;
  1953. nRes = API_CrRequestExposure(m_nDetectorID);
  1954. if (!TestError(nRes))
  1955. {
  1956. //mLog::Error("RequestExposure Failed");
  1957. return false;
  1958. }
  1959. nDualEnergyExp++;
  1960. nDualFlag++;
  1961. nLoop = 0;
  1962. }
  1963. break;
  1964. case CR_EXP_COMPLETE:
  1965. if (nLoop < 1)
  1966. {
  1967. //mLog::Info("exp complete");
  1968. bRepeatReady = false;
  1969. StatusFeedback(EVT_STATUS_PANEL, PANEL_XWINDOW_OFF);
  1970. nLoop++;
  1971. }
  1972. nDualEnergyExp = 0;
  1973. break;
  1974. default:
  1975. break;
  1976. }
  1977. if (progress.is_fetchable && nDualFlag == 2)
  1978. {
  1979. //mLog::Info("Image Arrive");
  1980. StatusFeedback(EVT_STATUS_PANEL, PANEL_START_TRANSMIT);
  1981. for (size_t i = 0; i < 2; i++)
  1982. {
  1983. //mLog::Info("Call CrGetNoHeaderImage, DetectorID: {$}, width:{$}, height: {$}", m_nDetectorID, m_nRawImgWidth, m_nRawImgHeight);
  1984. nRet = API_CrGetNoHeaderImage(m_nDetectorID, (char*)m_pRawImgBuffer, m_nRawImgHeight * m_nRawImgWidth * 2, 9000);
  1985. if (!TestError(nRet))
  1986. {
  1987. //mLog::Error("Get Image Raw Data Failed");
  1988. }
  1989. if (m_bSaveRaw)
  1990. {
  1991. char szTemp[30] = { 0 };
  1992. std::string strFileName = m_strWorkPath + "\\rawdata";
  1993. sprintf_s(szTemp, "\\DualImage_%d.raw", i + 1);
  1994. strFileName += szTemp;
  1995. std::filesystem::path file_path{ strFileName.c_str() };
  1996. std::ofstream file_stream(file_path, std::ios::binary);
  1997. if (!file_stream.is_open())
  1998. {
  1999. //mLog::Error("Open Save File Failed");
  2000. }
  2001. unsigned int nTempSize = m_nRawImgHeight * m_nRawImgWidth * 2;
  2002. file_stream.write(reinterpret_cast<const char*>(m_pRawImgBuffer), nTempSize);
  2003. file_stream.close();
  2004. }
  2005. DataFeedback(EVT_DATA_RAW_IMAGE, m_pRawImgBuffer);
  2006. if (i == 1)
  2007. {
  2008. m_bExitDualAcqStatus = true;
  2009. }
  2010. if (i == 0)
  2011. {
  2012. Sleep(5000);
  2013. }
  2014. }
  2015. }
  2016. if (m_bExitDualAcqStatus)
  2017. {
  2018. //mLog::Info("Exit Dual Acq Status");
  2019. int nRes = CR_OK;
  2020. //mLog::Info("Call CrStopAcquisition");
  2021. nRes = API_CrStopAcquisition(m_nDetectorID);
  2022. if (!TestError(nRes))
  2023. {
  2024. //mLog::Error("Stop Acquisition Failed");
  2025. }
  2026. StatusFeedback(EVT_STATUS_PANEL, PANEL_STANDBY);
  2027. break;
  2028. }
  2029. }
  2030. SetEvent(m_hExitDualAcqStatus);
  2031. //mLog::Info("PerformDualAcquisition Over");
  2032. return true;
  2033. }
  2034. bool Detector_CareRayDR::CloseDualEnergyAcquisition()
  2035. {
  2036. m_bExitDualAcqStatus = true;
  2037. DWORD dwResult = WaitForSingleObject(m_hExitDualAcqStatus, 1000);
  2038. if (dwResult == WAIT_OBJECT_0)
  2039. {
  2040. //mLog::Info("[Get ExitDualAcqStatus Event]");
  2041. }
  2042. else if (dwResult == WAIT_TIMEOUT)
  2043. {
  2044. ::TerminateThread(m_hDualEnergyAcquisitionThread, 0);
  2045. //mLog::Warn("Kill DualEnergyAcquisition Thread");
  2046. }
  2047. if (m_hExitDualAcqStatus != nullptr)
  2048. {
  2049. CloseHandle(m_hExitDualAcqStatus);
  2050. m_hExitDualAcqStatus = nullptr;
  2051. }
  2052. m_hDualEnergyAcquisitionThread = nullptr;
  2053. //mLog::Info("---Exit Dual Acq Status Thread---");
  2054. return true;
  2055. }
  2056. /***
  2057. ** 等待探测器操作执行完毕
  2058. ***/
  2059. bool Detector_CareRayDR::WaitRespond(int nTimeOut, const char* szAction)
  2060. {
  2061. //mLog::Info("--- WaitRespond({$}), {$}ms ---", szAction, nTimeOut);
  2062. DWORD dwRet = WaitForSingleObject(m_hRespond, nTimeOut);
  2063. if (dwRet == WAIT_TIMEOUT)
  2064. {
  2065. //mLog::Error("time out in wait response, action:{$}", szAction);
  2066. return false;
  2067. }
  2068. return true;
  2069. }
  2070. void Detector_CareRayDR::StopWaiting(const char* szAction)
  2071. {
  2072. //mLog::Info("--- Stop waiting respond, {$} ---", szAction);
  2073. SetEvent(m_hRespond);
  2074. }
  2075. /***
  2076. ** 检测接口是否有错误,true:有错;false:没错
  2077. ***/
  2078. bool Detector_CareRayDR::TestError(int nErrorCode)
  2079. {
  2080. if (nErrorCode == CR_OK)
  2081. {
  2082. return true;
  2083. }
  2084. else
  2085. {
  2086. std::string strLog;
  2087. char szMsgBuf[256];
  2088. API_CrGetLastIntlMsg(szMsgBuf, 256);
  2089. //mLog::Info("ErrorCode : {$}, Description: {$}", nErrorCode, szMsgBuf);
  2090. return false;
  2091. }
  2092. }
  2093. void Detector_CareRayDR::ProcessCREvent(int eventID, CrEvent* eventData)
  2094. {
  2095. switch (eventID)
  2096. {
  2097. case CR_EVT_NEW_FRAME:
  2098. //mLog::Info("Flu Mode New Frame");
  2099. memcpy(m_pFluFrameData, (reinterpret_cast<char*>(eventData->data) + 256), m_nImageWidth * m_nImageHeight * 2);
  2100. DataFeedback(EVT_DATA_RAW_IMAGE, m_pFluFrameData);
  2101. break;
  2102. case CR_EVT_CALIBRATION_IN_PROGRESS:
  2103. {
  2104. //mLog::Info("Get CR_EVT_CALIBRATION_IN_PROGRESS");
  2105. CrCalibrationInfo* calib_info = reinterpret_cast<CrCalibrationInfo*>(eventData->data);
  2106. if (0 == calib_info->total_frame_num)
  2107. {
  2108. //mLog::Info("Callback >> Calibration is in the PRECHECK state.");
  2109. }
  2110. else
  2111. {
  2112. //mLog::Info("Callback >> calibration progress: {$} / {$}, current frame mean = {$}", calib_info->current_frame_num, calib_info->total_frame_num,
  2113. calib_info->current_frame_mean);
  2114. switch (calib_info->exposure_status)
  2115. {
  2116. case CR_EXP_READY:
  2117. //mLog::Info("Callback >> Now you can press x-ray hand switch...");
  2118. break;
  2119. case CR_EXP_WAIT_PERMISSION:
  2120. //mLog::Info("Callback >> Detector is waiting for exposure permission...");
  2121. break;
  2122. default:
  2123. //mLog::Info("Callback >> Now you can't press x-ray hand switch...");
  2124. break;
  2125. }
  2126. }
  2127. break;
  2128. }
  2129. case CR_EVT_CALIBRATION_FINISHED:
  2130. {
  2131. //mLog::Info("Get CR_EVT_CALIBRATION_FINISHED");
  2132. CrCalibrationInfo* calib_info = reinterpret_cast<CrCalibrationInfo*>(eventData->data);
  2133. //mLog::Info("Calibration progress: {$} / {$}, current frame mean: {$}", calib_info->current_frame_num, calib_info->total_frame_num, calib_info->current_frame_mean);
  2134. //mLog::Info("Calibration result: {$}", calib_info->result);
  2135. break;
  2136. }
  2137. case CR_EVT_ACQ_STAT_INFO:
  2138. {
  2139. CrAcquisitionStatInfo* stat_info = reinterpret_cast<CrAcquisitionStatInfo*>(eventData->data);
  2140. //mLog::Info("Total frame: {$}", stat_info->total_frame_num);
  2141. break;
  2142. }
  2143. case CR_EVT_RAD_ACQ_IN_PROGRESS:
  2144. //mLog::Info("Get CR_EVT_RAD_ACQ_IN_PROGRESS");
  2145. break;
  2146. case CR_EVT_DETR_DISCONNECTED:
  2147. break;
  2148. default:
  2149. //mLog::Error("not support current event ID:{$}", eventID);
  2150. break;
  2151. }
  2152. }
  2153. void Detector_CareRayDR::ConfFeedback(int nEventID, int nDetectorID, const char* pszMsg, int nParam1, float fParam2, int nPtrParamLen, void* pParam)
  2154. {
  2155. if (-1 == nDetectorID)
  2156. {
  2157. nDetectorID = m_nCurrentPanelID;
  2158. }
  2159. ((FPDDeviceCareRay*)(*m_pPanelID2DPC)[nDetectorID])->OnFPDCallback(nDetectorID,
  2160. nEventID, EVT_LEVEL_CONFIGURATION, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
  2161. }
  2162. void Detector_CareRayDR::InfoFeedback(int nEventID, int nDetectorID, int nParam1, float fParam2, const char* pszMsg, int nPtrParamLen, void* pParam)
  2163. {
  2164. if (-1 == nDetectorID)
  2165. {
  2166. nDetectorID = m_nCurrentPanelID;
  2167. }
  2168. ((FPDDeviceCareRay*)(*m_pPanelID2DPC)[nDetectorID])->OnFPDCallback(nDetectorID,
  2169. nEventID, EVT_LEVEL_INFORMATOION, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
  2170. }
  2171. void Detector_CareRayDR::StatusFeedback(int nEventID, int nParam1, const char* pszMsg, int nDetectorID, float fParam2, int nPtrParamLen, void* pParam)
  2172. {
  2173. if (-1 == nDetectorID)
  2174. {
  2175. nDetectorID = m_nCurrentPanelID;
  2176. }
  2177. ((FPDDeviceCareRay*)(*m_pPanelID2DPC)[nDetectorID])->OnFPDCallback(nDetectorID,
  2178. nEventID, EVT_LEVEL_STATUS, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
  2179. }
  2180. void Detector_CareRayDR::DataFeedback(int nEventID, void* pParam, int nParam1, float fParam2, const char* pszMsg, int nPtrParamLen, int nDetectorID)
  2181. {
  2182. if (-1 == nDetectorID)
  2183. {
  2184. nDetectorID = m_nCurrentPanelID;
  2185. }
  2186. ((FPDDeviceCareRay*)(*m_pPanelID2DPC)[nDetectorID])->OnFPDCallback(nDetectorID,
  2187. nEventID, EVT_LEVEL_DATA, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
  2188. }
  2189. void Detector_CareRayDR::WarnFeedback(int nEventID, const char* pszMsg, int nParam1, float fParam2, int nPtrParamLen, void* pParam, int nDetectorID)
  2190. {
  2191. if (-1 == nDetectorID)
  2192. {
  2193. nDetectorID = m_nCurrentPanelID;
  2194. }
  2195. ((FPDDeviceCareRay*)(*m_pPanelID2DPC)[nDetectorID])->OnFPDCallback(nDetectorID,
  2196. nEventID, EVT_LEVEL_WARNING, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
  2197. }
  2198. void Detector_CareRayDR::ErrorFeedback(int nEventID, const char* pszMsg, int nDetectorID, int nParam1, float fParam2, int nPtrParamLen, void* pParam)
  2199. {
  2200. if (-1 == nDetectorID)
  2201. {
  2202. nDetectorID = m_nCurrentPanelID;
  2203. }
  2204. ((FPDDeviceCareRay*)(*m_pPanelID2DPC)[nDetectorID])->OnFPDCallback(nDetectorID,
  2205. nEventID, EVT_LEVEL_ERROR, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
  2206. }