// DIOS.Device.Test.cpp : �������̨Ӧ�ó������ڵ㡣 // #include "stdafx.h" #include #include #include "DIOS.Dev.IODevice.hpp" #include "ResDataObject.h" #include "SimpleLog.hpp" namespace nsDEV = DIOS::Dev; static void OnNotify (int NotifyCode, std::string key, std::string context) { printf ("OnNotify : %s :%s \n", key.c_str (), context.c_str ()); return; } //class Test //{ //public: // void OnNotify (int NotifyCode, std::string key, std::string context); //}; //void TestKV (nsDEV::IODevice * pDev); //void TestMA (nsDEV::IODevice* pDev, int techmode, std::string MAvalue); //void TestMS (nsDEV::IODevice* pDev, int techmode, std::string MSvalue); //void TestMAS (nsDEV::IODevice* pDev, int techmode, std::string MSvalue); //void TestAECFilm (nsDEV::IODevice* pDev, int techmode, int aecfilm); //void TestAECDensity (nsDEV::IODevice* pDev, int techmode, int aecfilm); //void TestAECField (nsDEV::IODevice* pDev, int techmode, int aecfilm); //void TestFocus(nsDEV::IODevice* pDev, int focus); //void TestAPR (nsDEV::IODevice* pDev, int nFO, int nET, int nAECFieldSel, int nAECFilmSel, float fAECDensity, float fKV, float fMA, float fMS, float fMAS); SimpleLog slog("Mition"); SimpleLog slogtest("Test"); #define TEST_INFO(format, ...) { slog.Info(format); } int _tmain () { //slog.Open("Mition"); auto libFN = L"DIOS.Dev.Machinery.Driver.ECOMX64.dll"; for (int i = 0; i < 100; i++) { slog.Info("------log begin-----"); slog.Info("Test {$} {$} {$} {$}", 1, 2.56, 4, "hello"); slog.Info("Test, Para1: {$} {$}, para2: ({$},{$})", 1, 2.56, 4, "hello"); slogtest.Info("[CArmResetMotionModel][ChangeStage]->[{$:d}]", 20); slogtest.Info("[CArmResetMotionModel][ChangeStage]->[{$}]", "test"); slogtest.Info("[CArmResetMotionModel][ChangeStage]->[{0x$:X}]", 0x20); TEST_INFO("[CArmResetMotionModel][ChangeStage]->[ test {$}]", 0x20); if (i % 10 == 0) { int j = 0; } } getchar(); slog.Close(); slogtest.Close(); auto h = LoadLibrary ((char*)libFN); if (! h) return 3; auto fun = GetProcAddress (h, "GetIODriver"); if (!fun) return 5; auto pDriver = reinterpret_cast (fun ()); assert (pDriver); pDriver->EventCenter->OnNotify.Push (OnNotify); pDriver->DriverEntry (R"(D:\Devs\Dev_DIOS\DiosDriver_V2\NewDIOS\Deliver\Bin\ReleaseX64\DriverConfig\MachineryECOM.xml)"); pDriver->Prepare (); string resResource = pDriver->GetResource (); printf ("GetDriverResource: %s \n", resResource.c_str ()); pDriver->Connect (); auto bConnected = pDriver->isConnected (); if (! bConnected) return 9; bConnected = pDriver->isConnected (); bConnected = pDriver->isConnected (); bConnected = pDriver->isConnected (); bConnected = pDriver->isConnected (); bConnected = pDriver->isConnected (); bConnected = pDriver->isConnected (); bConnected = pDriver->isConnected (); auto pDevice = pDriver->CreateDevice (0); if (! bConnected) assert (! pDevice); else assert (pDevice); if (! pDevice) return 12; bool result=pDevice->Prepare(); //TestAPR(pDevice.get(),0,0, 101, 0, 0, 40.0, 200.0, 10.0, 0); //puts("TestAPR end.Hit any key to continue"); //getchar(); //TestKV (pDevice.get ()); //puts ("TestKV end.Hit any key to continue"); //getchar (); //TestMA (pDevice.get (), 0, "22"); //puts ("TestMA end.Hit any key to continue"); //getchar(); //TestMS (pDevice.get (), 0, "14"); //puts ("TestMS end.Hit any key to continue"); //getchar(); //TestMAS(pDevice.get(), 1, "14"); //puts("TestMAS end.Hit any key to continue"); //getchar(); //TestMAS(pDevice.get(), 1, "14"); //puts("TestMAS end.Hit any key to continue"); //getchar(); //TestFocus(pDevice.get(), 1); //puts("TestMAS end.Hit any key to continue"); //getchar(); //puts ("Hit any key to quit"); //getchar (); return 0; } void TestKV (nsDEV::IODevice* pDev) { std::string rsp; ResDataObject json; json.add ("P0", "50.0"); auto rc0 = pDev->Action ("SetValue_KV", json.encode (), rsp); assert (rc0 == nsDEV::RET_STATUS::RET_SUCCEED); auto rc1 = pDev->Action ("IncParam_KV", "", rsp); assert (rc1 == nsDEV::RET_STATUS::RET_SUCCEED); auto rc3 = (int)pDev->Get ("KV",rsp); assert (rsp.length ()); printf ("rsp= %s \n ", rsp.c_str ()); auto rc2 = pDev->Action ("DecParam_KV", "", rsp); assert (rc2 == nsDEV::RET_STATUS::RET_SUCCEED); rc2 = pDev->Get ("KV", rsp); assert (rsp.length ()); } void TestMA (nsDEV::IODevice* pDev, int techmode, std::string MAvalue) { std::string rsp; ResDataObject json; json.update ("P0", techmode); auto rc0 = pDev->Action ("SetValue_TECHMODE", json.encode (), rsp); assert (rc0 == nsDEV::RET_STATUS::RET_SUCCEED); Sleep(200); json.update ("P0", MAvalue.c_str ()); auto rc5 = pDev->Action ("SetValue_MA", json.encode (), rsp); assert (rc5 == nsDEV::RET_STATUS::RET_SUCCEED); Sleep(200); auto rc1 = pDev->Action ("IncParam_MA", "", rsp); assert (rc1 == nsDEV::RET_STATUS::RET_SUCCEED); Sleep(200); pDev->Get ("MA", rsp); assert (rsp.length () != 0); printf ("rsp= %s \n ", rsp.c_str ()); Sleep(200); auto rc2 = pDev->Action ("DecParam_MA", "", rsp); assert (rc2 == nsDEV::RET_STATUS::RET_SUCCEED); auto rc11 = pDev->Get ("MA", rsp); assert (rsp.length () != 0); } void TestMS (nsDEV::IODevice* pDev, int techmode, std::string MSvalue) { std::string rsp; ResDataObject json; json.update ("P0", techmode); auto rc0 = pDev->Action ("SetValue_TECHMODE", json.encode (), rsp); assert (rc0 == nsDEV::RET_STATUS::RET_SUCCEED); Sleep(200); json.update ("P0", MSvalue.c_str ()); auto rc5 = pDev->Action ("SetValue_MS", json.encode (), rsp); assert (rc5 == nsDEV::RET_STATUS::RET_SUCCEED); Sleep(200); auto rc1 = pDev->Action ("IncParam_MS", "", rsp); assert (rc1 == nsDEV::RET_STATUS::RET_SUCCEED); Sleep(200); pDev->Get ("MS", rsp); assert (rsp.length () != 0); printf ("rsp= %s \n ", rsp.c_str ()); auto rc2 = pDev->Action ("DecParam_MS", "", rsp); assert (rc2 == nsDEV::RET_STATUS::RET_SUCCEED); pDev->Get ("MS", rsp); assert (rsp.length () != 0); } void TestMAS (nsDEV::IODevice* pDev, int techmode, std::string MSvalue) { std::string rsp; ResDataObject json; json.update ("P0", techmode); auto rc0 = pDev->Action ("SetValue_TECHMODE", json.encode (), rsp); assert (rc0 == nsDEV::RET_STATUS::RET_SUCCEED); Sleep(200); json.update ("P0", MSvalue.c_str ()); auto rc5 = pDev->Action ("SetValue_MAS", json.encode (), rsp); assert (rc5 == nsDEV::RET_STATUS::RET_SUCCEED); Sleep(200); auto rc1 = pDev->Action ("IncParam_MAS", "", rsp); assert (rc1 == nsDEV::RET_STATUS::RET_SUCCEED); Sleep(200); pDev->Get ("MAS", rsp); assert (rsp.length () != 0); printf ("rsp= %s \n", rsp.c_str ()); auto rc2 = pDev->Action ("DecParam_MAS", "", rsp); assert (rc2 == nsDEV::RET_STATUS::RET_SUCCEED); Sleep(200); pDev->Get ("MAS", rsp); assert (rsp.length () != 0); } void TestAECFilm (nsDEV::IODevice* pDev, int techmode, int aecfilm) { std::string rsp; ResDataObject json; json.update ("P0", techmode); auto rc0 = pDev->Action ("SetValue_TECHMODE", json.encode (), rsp); assert (rc0 == nsDEV::RET_STATUS::RET_SUCCEED); Sleep(200); json.update ("P0", aecfilm); auto rc5 = pDev->Action ("SetValue_AECFILM", json.encode (), rsp); assert (rc5 == nsDEV::RET_STATUS::RET_SUCCEED); Sleep(200); pDev->Get ("AECFILM", rsp); printf ("rsp= %s \n", rsp.c_str ()); assert (rsp.length () != 0); } void TestAECDensity (nsDEV::IODevice* pDev, int techmode, int aecfilm) { std::string rsp; ResDataObject json; json.update ("P0", techmode); auto rc0 = pDev->Action ("SetValue_TECHMODE", json.encode (), rsp); assert (rc0 == nsDEV::RET_STATUS::RET_SUCCEED); Sleep(200); json.update ("P0", aecfilm); auto rc5 = pDev->Action ("SetValue_AECDENSITY", json.encode (), rsp); assert (rc5 == nsDEV::RET_STATUS::RET_SUCCEED); Sleep(200); pDev->Get ("AECDENSITY", rsp); printf ("rsp= %s \n", rsp.c_str ()); assert (rsp.length () != 0); } void TestAECField (nsDEV::IODevice* pDev, int techmode, int aecfilm) { std::string rsp; ResDataObject json; json.update ("P0", techmode); auto rc0 = pDev->Action ("SetValue_TECHMODE", json.encode (), rsp); assert (rc0 == nsDEV::RET_STATUS::RET_SUCCEED); Sleep(200); json.update ("P0", aecfilm); auto rc5 = pDev->Action ("SetValue_AECFIELD", json.encode (), rsp); assert (rc5 == nsDEV::RET_STATUS::RET_SUCCEED); Sleep(200); pDev->Get ("AECFIELD", rsp); printf ("rsp= %s \n", rsp.c_str ()); assert (rsp.length () != 0); } void TestFocus(nsDEV::IODevice* pDev, int focus) { std::string rsp; ResDataObject json; json.update("P0", 1); auto rc0 = pDev->Action("SetValue_FOCUS", json.encode(), rsp); assert(rc0 == nsDEV::RET_STATUS::RET_SUCCEED); Sleep(200); json.update("P0", 0); auto rc5 = pDev->Action("SetValue_FOCUS", json.encode(), rsp); assert(rc5 == nsDEV::RET_STATUS::RET_SUCCEED); Sleep(200); pDev->Get("FOCUS", rsp); printf("rsp= %s \n", rsp.c_str()); assert(rsp.length() != 0); } void TestAPR (nsDEV::IODevice* pDev, int nFO, int nET, int nAECFieldSel, int nAECFilmSel, float fAECDensity, float fKV, float fMA, float fMS, float fMAS) { char strvalue [20]; ResDataObject json, param; sprintf_s (strvalue, "%d", nFO); param.add ("FOCUS", strvalue); sprintf_s (strvalue, "%d", nET); param.add ("TECHMODE", strvalue); sprintf_s (strvalue, "%d", nAECFieldSel); param.add ("AECFIELD", strvalue); sprintf_s (strvalue, "%d", nAECFilmSel); param.add ("AECFILM", strvalue); sprintf_s (strvalue, "%d", (int) fAECDensity); param.add ("AECDENSITY", strvalue); sprintf_s (strvalue, "%d", (int) fKV); param.add ("KV", strvalue); sprintf_s (strvalue, "%f", fMA); param.add ("MA", strvalue); sprintf_s (strvalue, "%f", fMS); param.add ("MS", strvalue); sprintf_s (strvalue, "%f", fMAS); param.add ("MAS", strvalue); param.add ("DOSE", "0.0"); param.add ("FILTER", "0"); param.add ("TUBELOAD", "0.0"); json.update ("P0", param); std::string rsp; auto rc0 = pDev->Action ("SetAPR", json.encode (), rsp); assert (rc0 == nsDEV::RET_STATUS::RET_SUCCEED); }