DIOS.Dev.Machinery.Test.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. // DIOS.Device.Test.cpp : �������̨Ӧ�ó������ڵ㡣
  2. //
  3. #include "stdafx.h"
  4. #include <Windows.h>
  5. #include <assert.h>
  6. #include "DIOS.Dev.IODevice.hpp"
  7. #include "ResDataObject.h"
  8. #include "SimpleLog.hpp"
  9. namespace nsDEV = DIOS::Dev;
  10. static void OnNotify (int NotifyCode, std::string key, std::string context)
  11. {
  12. printf ("OnNotify : %s :%s \n", key.c_str (), context.c_str ());
  13. return;
  14. }
  15. //class Test
  16. //{
  17. //public:
  18. // void OnNotify (int NotifyCode, std::string key, std::string context);
  19. //};
  20. //void TestKV (nsDEV::IODevice * pDev);
  21. //void TestMA (nsDEV::IODevice* pDev, int techmode, std::string MAvalue);
  22. //void TestMS (nsDEV::IODevice* pDev, int techmode, std::string MSvalue);
  23. //void TestMAS (nsDEV::IODevice* pDev, int techmode, std::string MSvalue);
  24. //void TestAECFilm (nsDEV::IODevice* pDev, int techmode, int aecfilm);
  25. //void TestAECDensity (nsDEV::IODevice* pDev, int techmode, int aecfilm);
  26. //void TestAECField (nsDEV::IODevice* pDev, int techmode, int aecfilm);
  27. //void TestFocus(nsDEV::IODevice* pDev, int focus);
  28. //void TestAPR (nsDEV::IODevice* pDev, int nFO, int nET, int nAECFieldSel, int nAECFilmSel, float fAECDensity, float fKV, float fMA, float fMS, float fMAS);
  29. SimpleLog slog("Mition");
  30. SimpleLog slogtest("Test");
  31. #define TEST_INFO(format, ...) { slog.Info(format); }
  32. int _tmain ()
  33. {
  34. //slog.Open("Mition");
  35. auto libFN = L"DIOS.Dev.Machinery.Driver.ECOMX64.dll";
  36. for (int i = 0; i < 100; i++)
  37. {
  38. slog.Info("------log begin-----");
  39. slog.Info("Test {$} {$} {$} {$}", 1, 2.56, 4, "hello");
  40. slog.Info("Test, Para1: {$} {$}, para2: ({$},{$})", 1, 2.56, 4, "hello");
  41. slogtest.Info("[CArmResetMotionModel][ChangeStage]->[{$:d}]", 20);
  42. slogtest.Info("[CArmResetMotionModel][ChangeStage]->[{$}]", "test");
  43. slogtest.Info("[CArmResetMotionModel][ChangeStage]->[{0x$:X}]", 0x20);
  44. TEST_INFO("[CArmResetMotionModel][ChangeStage]->[ test {$}]", 0x20);
  45. if (i % 10 == 0)
  46. {
  47. int j = 0;
  48. }
  49. }
  50. getchar();
  51. slog.Close();
  52. slogtest.Close();
  53. auto h = LoadLibrary ((char*)libFN);
  54. if (! h)
  55. return 3;
  56. auto fun = GetProcAddress (h, "GetIODriver");
  57. if (!fun)
  58. return 5;
  59. auto pDriver = reinterpret_cast <nsDEV::IODriver*> (fun ());
  60. assert (pDriver);
  61. pDriver->EventCenter->OnNotify.Push (OnNotify);
  62. pDriver->DriverEntry (R"(D:\Devs\Dev_DIOS\DiosDriver_V2\NewDIOS\Deliver\Bin\ReleaseX64\DriverConfig\MachineryECOM.xml)");
  63. pDriver->Prepare ();
  64. string resResource = pDriver->GetResource ();
  65. printf ("GetDriverResource: %s \n", resResource.c_str ());
  66. pDriver->Connect ();
  67. auto bConnected = pDriver->isConnected ();
  68. if (! bConnected)
  69. return 9;
  70. bConnected = pDriver->isConnected ();
  71. bConnected = pDriver->isConnected ();
  72. bConnected = pDriver->isConnected ();
  73. bConnected = pDriver->isConnected ();
  74. bConnected = pDriver->isConnected ();
  75. bConnected = pDriver->isConnected ();
  76. bConnected = pDriver->isConnected ();
  77. auto pDevice = pDriver->CreateDevice (0);
  78. if (! bConnected)
  79. assert (! pDevice);
  80. else
  81. assert (pDevice);
  82. if (! pDevice)
  83. return 12;
  84. bool result=pDevice->Prepare();
  85. //TestAPR(pDevice.get(),0,0, 101, 0, 0, 40.0, 200.0, 10.0, 0);
  86. //puts("TestAPR end.Hit any key to continue");
  87. //getchar();
  88. //TestKV (pDevice.get ());
  89. //puts ("TestKV end.Hit any key to continue");
  90. //getchar ();
  91. //TestMA (pDevice.get (), 0, "22");
  92. //puts ("TestMA end.Hit any key to continue");
  93. //getchar();
  94. //TestMS (pDevice.get (), 0, "14");
  95. //puts ("TestMS end.Hit any key to continue");
  96. //getchar();
  97. //TestMAS(pDevice.get(), 1, "14");
  98. //puts("TestMAS end.Hit any key to continue");
  99. //getchar();
  100. //TestMAS(pDevice.get(), 1, "14");
  101. //puts("TestMAS end.Hit any key to continue");
  102. //getchar();
  103. //TestFocus(pDevice.get(), 1);
  104. //puts("TestMAS end.Hit any key to continue");
  105. //getchar();
  106. //puts ("Hit any key to quit");
  107. //getchar ();
  108. return 0;
  109. }
  110. void TestKV (nsDEV::IODevice* pDev)
  111. {
  112. std::string rsp;
  113. ResDataObject json;
  114. json.add ("P0", "50.0");
  115. auto rc0 = pDev->Action ("SetValue_KV", json.encode (), rsp);
  116. assert (rc0 == nsDEV::RET_STATUS::RET_SUCCEED);
  117. auto rc1 = pDev->Action ("IncParam_KV", "", rsp);
  118. assert (rc1 == nsDEV::RET_STATUS::RET_SUCCEED);
  119. auto rc3 = (int)pDev->Get ("KV",rsp);
  120. assert (rsp.length ());
  121. printf ("rsp= %s \n ", rsp.c_str ());
  122. auto rc2 = pDev->Action ("DecParam_KV", "", rsp);
  123. assert (rc2 == nsDEV::RET_STATUS::RET_SUCCEED);
  124. rc2 = pDev->Get ("KV", rsp);
  125. assert (rsp.length ());
  126. }
  127. void TestMA (nsDEV::IODevice* pDev, int techmode, std::string MAvalue)
  128. {
  129. std::string rsp;
  130. ResDataObject json;
  131. json.update ("P0", techmode);
  132. auto rc0 = pDev->Action ("SetValue_TECHMODE", json.encode (), rsp);
  133. assert (rc0 == nsDEV::RET_STATUS::RET_SUCCEED);
  134. Sleep(200);
  135. json.update ("P0", MAvalue.c_str ());
  136. auto rc5 = pDev->Action ("SetValue_MA", json.encode (), rsp);
  137. assert (rc5 == nsDEV::RET_STATUS::RET_SUCCEED);
  138. Sleep(200);
  139. auto rc1 = pDev->Action ("IncParam_MA", "", rsp);
  140. assert (rc1 == nsDEV::RET_STATUS::RET_SUCCEED);
  141. Sleep(200);
  142. pDev->Get ("MA", rsp);
  143. assert (rsp.length () != 0);
  144. printf ("rsp= %s \n ", rsp.c_str ());
  145. Sleep(200);
  146. auto rc2 = pDev->Action ("DecParam_MA", "", rsp);
  147. assert (rc2 == nsDEV::RET_STATUS::RET_SUCCEED);
  148. auto rc11 = pDev->Get ("MA", rsp);
  149. assert (rsp.length () != 0);
  150. }
  151. void TestMS (nsDEV::IODevice* pDev, int techmode, std::string MSvalue)
  152. {
  153. std::string rsp;
  154. ResDataObject json;
  155. json.update ("P0", techmode);
  156. auto rc0 = pDev->Action ("SetValue_TECHMODE", json.encode (), rsp);
  157. assert (rc0 == nsDEV::RET_STATUS::RET_SUCCEED);
  158. Sleep(200);
  159. json.update ("P0", MSvalue.c_str ());
  160. auto rc5 = pDev->Action ("SetValue_MS", json.encode (), rsp);
  161. assert (rc5 == nsDEV::RET_STATUS::RET_SUCCEED);
  162. Sleep(200);
  163. auto rc1 = pDev->Action ("IncParam_MS", "", rsp);
  164. assert (rc1 == nsDEV::RET_STATUS::RET_SUCCEED);
  165. Sleep(200);
  166. pDev->Get ("MS", rsp);
  167. assert (rsp.length () != 0);
  168. printf ("rsp= %s \n ", rsp.c_str ());
  169. auto rc2 = pDev->Action ("DecParam_MS", "", rsp);
  170. assert (rc2 == nsDEV::RET_STATUS::RET_SUCCEED);
  171. pDev->Get ("MS", rsp);
  172. assert (rsp.length () != 0);
  173. }
  174. void TestMAS (nsDEV::IODevice* pDev, int techmode, std::string MSvalue)
  175. {
  176. std::string rsp;
  177. ResDataObject json;
  178. json.update ("P0", techmode);
  179. auto rc0 = pDev->Action ("SetValue_TECHMODE", json.encode (), rsp);
  180. assert (rc0 == nsDEV::RET_STATUS::RET_SUCCEED);
  181. Sleep(200);
  182. json.update ("P0", MSvalue.c_str ());
  183. auto rc5 = pDev->Action ("SetValue_MAS", json.encode (), rsp);
  184. assert (rc5 == nsDEV::RET_STATUS::RET_SUCCEED);
  185. Sleep(200);
  186. auto rc1 = pDev->Action ("IncParam_MAS", "", rsp);
  187. assert (rc1 == nsDEV::RET_STATUS::RET_SUCCEED);
  188. Sleep(200);
  189. pDev->Get ("MAS", rsp);
  190. assert (rsp.length () != 0);
  191. printf ("rsp= %s \n", rsp.c_str ());
  192. auto rc2 = pDev->Action ("DecParam_MAS", "", rsp);
  193. assert (rc2 == nsDEV::RET_STATUS::RET_SUCCEED);
  194. Sleep(200);
  195. pDev->Get ("MAS", rsp);
  196. assert (rsp.length () != 0);
  197. }
  198. void TestAECFilm (nsDEV::IODevice* pDev, int techmode, int aecfilm)
  199. {
  200. std::string rsp;
  201. ResDataObject json;
  202. json.update ("P0", techmode);
  203. auto rc0 = pDev->Action ("SetValue_TECHMODE", json.encode (), rsp);
  204. assert (rc0 == nsDEV::RET_STATUS::RET_SUCCEED);
  205. Sleep(200);
  206. json.update ("P0", aecfilm);
  207. auto rc5 = pDev->Action ("SetValue_AECFILM", json.encode (), rsp);
  208. assert (rc5 == nsDEV::RET_STATUS::RET_SUCCEED);
  209. Sleep(200);
  210. pDev->Get ("AECFILM", rsp);
  211. printf ("rsp= %s \n", rsp.c_str ());
  212. assert (rsp.length () != 0);
  213. }
  214. void TestAECDensity (nsDEV::IODevice* pDev, int techmode, int aecfilm)
  215. {
  216. std::string rsp;
  217. ResDataObject json;
  218. json.update ("P0", techmode);
  219. auto rc0 = pDev->Action ("SetValue_TECHMODE", json.encode (), rsp);
  220. assert (rc0 == nsDEV::RET_STATUS::RET_SUCCEED);
  221. Sleep(200);
  222. json.update ("P0", aecfilm);
  223. auto rc5 = pDev->Action ("SetValue_AECDENSITY", json.encode (), rsp);
  224. assert (rc5 == nsDEV::RET_STATUS::RET_SUCCEED);
  225. Sleep(200);
  226. pDev->Get ("AECDENSITY", rsp);
  227. printf ("rsp= %s \n", rsp.c_str ());
  228. assert (rsp.length () != 0);
  229. }
  230. void TestAECField (nsDEV::IODevice* pDev, int techmode, int aecfilm)
  231. {
  232. std::string rsp;
  233. ResDataObject json;
  234. json.update ("P0", techmode);
  235. auto rc0 = pDev->Action ("SetValue_TECHMODE", json.encode (), rsp);
  236. assert (rc0 == nsDEV::RET_STATUS::RET_SUCCEED);
  237. Sleep(200);
  238. json.update ("P0", aecfilm);
  239. auto rc5 = pDev->Action ("SetValue_AECFIELD", json.encode (), rsp);
  240. assert (rc5 == nsDEV::RET_STATUS::RET_SUCCEED);
  241. Sleep(200);
  242. pDev->Get ("AECFIELD", rsp);
  243. printf ("rsp= %s \n", rsp.c_str ());
  244. assert (rsp.length () != 0);
  245. }
  246. void TestFocus(nsDEV::IODevice* pDev, int focus)
  247. {
  248. std::string rsp;
  249. ResDataObject json;
  250. json.update("P0", 1);
  251. auto rc0 = pDev->Action("SetValue_FOCUS", json.encode(), rsp);
  252. assert(rc0 == nsDEV::RET_STATUS::RET_SUCCEED);
  253. Sleep(200);
  254. json.update("P0", 0);
  255. auto rc5 = pDev->Action("SetValue_FOCUS", json.encode(), rsp);
  256. assert(rc5 == nsDEV::RET_STATUS::RET_SUCCEED);
  257. Sleep(200);
  258. pDev->Get("FOCUS", rsp);
  259. printf("rsp= %s \n", rsp.c_str());
  260. assert(rsp.length() != 0);
  261. }
  262. void TestAPR (nsDEV::IODevice* pDev, int nFO, int nET, int nAECFieldSel, int nAECFilmSel, float fAECDensity, float fKV, float fMA, float fMS, float fMAS)
  263. {
  264. char strvalue [20];
  265. ResDataObject json, param;
  266. sprintf_s (strvalue, "%d", nFO);
  267. param.add ("FOCUS", strvalue);
  268. sprintf_s (strvalue, "%d", nET);
  269. param.add ("TECHMODE", strvalue);
  270. sprintf_s (strvalue, "%d", nAECFieldSel);
  271. param.add ("AECFIELD", strvalue);
  272. sprintf_s (strvalue, "%d", nAECFilmSel);
  273. param.add ("AECFILM", strvalue);
  274. sprintf_s (strvalue, "%d", (int) fAECDensity);
  275. param.add ("AECDENSITY", strvalue);
  276. sprintf_s (strvalue, "%d", (int) fKV);
  277. param.add ("KV", strvalue);
  278. sprintf_s (strvalue, "%f", fMA);
  279. param.add ("MA", strvalue);
  280. sprintf_s (strvalue, "%f", fMS);
  281. param.add ("MS", strvalue);
  282. sprintf_s (strvalue, "%f", fMAS);
  283. param.add ("MAS", strvalue);
  284. param.add ("DOSE", "0.0");
  285. param.add ("FILTER", "0");
  286. param.add ("TUBELOAD", "0.0");
  287. json.update ("P0", param);
  288. std::string rsp;
  289. auto rc0 = pDev->Action ("SetAPR", json.encode (), rsp);
  290. assert (rc0 == nsDEV::RET_STATUS::RET_SUCCEED);
  291. }