// #include "stdafx.h" #include #include "ResDataObject.h" #include "Helper.JSON.hpp" #include "DIOS.Dev.SYNBOX.Mould.hpp" #include "EasyJSONEncoder.hpp" using namespace DIOS::Dev::Detail::SYNBOX; namespace nsSYN = DIOS::Dev::Detail::SYNBOX; //template //inline _Container& operator << (_Container& ar, const T& t) //{ // ar.push_back(t); // return ar; //} string nsSYN::GetProcessDirectory() { string ret = ""; char szFilename[MAX_PATH] = { 0 }; DWORD res = GetModuleFileNameA(0, szFilename, MAX_PATH); if (res == 0) { return ret; } string fullpath = szFilename; string::size_type firstHit = fullpath.find_last_of('\\'); if (firstHit == string::npos || firstHit == 0) { return ret; } ret = fullpath.substr(0, firstHit);//kick last \ return ret; } //获取配置文件中指定模块的版本号 bool nsSYN::GetVersion(string& version, HMODULE hMyModule) { try { char filename[MAX_PATH + 1] = { 0 }; if (GetModuleFileName(hMyModule, filename, MAX_PATH) == 0) { printf("dll HMODULEis null\n"); //mLog::Error("dll HMODULEis null\n"); return false; } printf("get SYNBox path:{$}\n", filename); //mLog::Info("get SYNBox path:{$}\n", filename); DWORD dummy; DWORD size = GetFileVersionInfoSize(filename, &dummy); if (size == 0) { return false; } auto data = make_unique(size); if (!GetFileVersionInfo(filename, 0, size, &data[0])) { return false; } UINT32 len = 0; VS_FIXEDFILEINFO* fixed_file_info = 0; if (!VerQueryValue(&data[0], TEXT("\\"), reinterpret_cast(&fixed_file_info), &len)) { return false; } // version 为版本号 UINT32 vBitNumber = 0; vBitNumber = HIWORD(fixed_file_info->dwProductVersionMS); version += to_string(vBitNumber); version += "."; vBitNumber = LOWORD(fixed_file_info->dwProductVersionMS); version += to_string(vBitNumber); version += "."; vBitNumber = HIWORD(fixed_file_info->dwProductVersionLS); version += to_string(vBitNumber); version += "."; vBitNumber = LOWORD(fixed_file_info->dwProductVersionLS); version += to_string(vBitNumber); return true; } catch (...) { printf("get SYNBox Mould version failed"); //mLog::Error("get SYNBox Mould version failed\n"); } return false; } bool nsSYN::GetVersion(string& version, ResDataObject& config) { try { string procdir = ""; char filename[MAX_PATH + 1] = { 0 }; procdir = nsSYN::GetProcessDirectory(); if (procdir.empty()) { if (GetModuleFileName(nullptr, filename, MAX_PATH) == 0) { return false; } } else { string oemdrvpath = (const char*)config["oemdriver"]; { string keystr = "%ROOT%"; string::size_type pos = 0; string::size_type keylen = keystr.size(); string::size_type replen = procdir.size(); while ((pos = oemdrvpath.find(keystr, pos)) != string::npos) { oemdrvpath.replace(pos, keylen, procdir); pos += replen; } } strncpy_s(filename, oemdrvpath.c_str(), MAX_PATH); } printf("get SYNBox path:{$}\n", filename); //mLog::Info("get SYNBox path:{$}\n", filename); DWORD dummy; DWORD size = GetFileVersionInfoSize(filename, &dummy); if (size == 0) { return false; } auto data = make_unique(size); if (!GetFileVersionInfo(filename, 0, size, &data[0])) { return false; } UINT32 len = 0; VS_FIXEDFILEINFO* fixed_file_info = 0; if (!VerQueryValue(&data[0], TEXT("\\"), reinterpret_cast(&fixed_file_info), &len)) { return false; } // version 为版本号 UINT32 vBitNumber = 0; vBitNumber = HIWORD(fixed_file_info->dwProductVersionMS); version += to_string(vBitNumber); version += "."; vBitNumber = LOWORD(fixed_file_info->dwProductVersionMS); version += to_string(vBitNumber); version += "."; vBitNumber = HIWORD(fixed_file_info->dwProductVersionLS); version += to_string(vBitNumber); version += "."; vBitNumber = LOWORD(fixed_file_info->dwProductVersionLS); version += to_string(vBitNumber); return true; } catch (...) { printf("get SYNBox Mould version failed"); //mLog::Error("get SYNBox Mould version failed\n"); } return false; } bool nsSYN::GetVersion(string& version) { try { char filename[MAX_PATH + 1] = { 0 }; if (GetModuleFileName(nullptr, filename, MAX_PATH) == 0) { return false; } printf("get SYNBox path:{$}\n", filename); //mLog::Info("get SYNBox path:{$}\n", filename); DWORD dummy; DWORD size = GetFileVersionInfoSize(filename, &dummy); if (size == 0) { return false; } auto data = make_unique(size); if (!GetFileVersionInfo(filename, 0, size, &data[0])) { return false; } UINT32 len = 0; VS_FIXEDFILEINFO* fixed_file_info = 0; if (!VerQueryValue(&data[0], TEXT("\\"), reinterpret_cast(&fixed_file_info), &len)) { return false; } // version 为版本号 UINT32 vBitNumber = 0; vBitNumber = HIWORD(fixed_file_info->dwProductVersionMS); version += to_string(vBitNumber); version += "."; vBitNumber = LOWORD(fixed_file_info->dwProductVersionMS); version += to_string(vBitNumber); version += "."; vBitNumber = HIWORD(fixed_file_info->dwProductVersionLS); version += to_string(vBitNumber); version += "."; vBitNumber = LOWORD(fixed_file_info->dwProductVersionLS); version += to_string(vBitNumber); return true; } catch (...) { printf("get SYNBox Mould version failed"); //mLog::Error("get SYNBox Mould version failed\n"); } return false; } void nsSYN::TransJsonText(ResDataObject& config) { for (int x = 0; x < config.size(); x++) { //如果有Value if (config[x].GetKeyCount("Value") > 0) { //mLog::FINFO("TRY COVERT [{$}] VALUE {$}", config.GetKey(x), config[x]["Value"].size() > 0 ? config[x]["Value"].encode() : (const char*)config[x]["Value"]); if (config[x]["Value"].size() <= 0) { string va = (const char*)config[x]["Value"]; config[x] = va.c_str(); } else { ResDataObject rest = config[x]["Value"]; config[x] = rest; //mLog::FINFO("convert object [{$}], object {$}", config.GetKey(x), rest.encode()); } } //mLog::FINFO("After Convert {$}", config.encode()); } } //----------------------------------------------------------------------------- // nsSYN::SYNBOXMould //----------------------------------------------------------------------------- nsSYN::SYNBOXMould::SYNBOXMould() { } nsSYN::SYNBOXMould::~SYNBOXMould() { } void nsSYN::SYNBOXMould::Register (Dispatch* Dispatch) { //同步盒内容 Dispatch->Get.Push(AttrKey::SYNSTATE, [this](std::string& out) { if (m_SynBoxUnit.m_SynBoxState) out = m_SynBoxUnit.m_SynBoxState->JSGet(); return RET_STATUS::RET_SUCCEED; }); Dispatch->Get.Push(AttrKey::TOTALEXPSURENUMBER, [this](std::string& out) { if (m_SynBoxUnit.m_TotalExpNumber) out = m_SynBoxUnit.m_TotalExpNumber->JSGet(); return RET_STATUS::RET_SUCCEED; }); Dispatch->Get.Push(AttrKey::CURRENTEXPOSUREBNUMBER, [this](std::string& out) { if (m_SynBoxUnit.m_CurrentExpNumber) out = m_SynBoxUnit.m_CurrentExpNumber->JSGet(); return RET_STATUS::RET_SUCCEED; }); Dispatch->Set.Push(AttrKey::WORKSTATION, [this](std::string in) { ResDataObject json; json.decode(in.c_str()); auto value = (string)json[0]; return SetWS(value); }); Dispatch->Action.Push(ActionKey::SetValue_WORKSTATION, [this](std::string in, std::string& out) { ResDataObject json; json.decode(in.c_str()); auto value = (string)json[0]; return SetWS(value); }); Dispatch->Set.Push(AttrKey::EXPMODE, [this](std::string in) { ResDataObject json; json.decode(in.c_str()); auto value = (string)json[0]; SetExpMode(value); try { //解析出曝光次数 auto exptimes = (int)json[1]; SetExposureTimes(exptimes); } catch (...) { printf("get SYNBox Mould default exptimes failed"); } try { //解析出来framerate auto framerate = (int)json[2]; SetFrameRate(framerate); } catch (...) { printf("get SYNBox Mould default framerate failed"); } return RET_STATUS::RET_SUCCEED; }); Dispatch->Action.Push(ActionKey::SetExpMode, [this](std::string in, std::string& out) { ResDataObject json; json.decode(in.c_str()); auto value = (string)json[0]; SetExpMode(value); if (json.size() >= 2) { try { //解析出曝光次数 auto exptimes = (int)json[1]; SetExposureTimes(exptimes); } catch (...) { printf("get SYNBox Mould default exptimes failed"); } } //add by wxx 暂时不需要,由上层根据探测器反馈自行设置 //if (json.size() >= 3) //{ // try // { // //解析出帧率 // auto pps = (float)json[2]; // SetFrameRate(pps); // } // catch (...) // { // printf("get SYNBox Mould default PPS failed"); // } //} return RET_STATUS::RET_SUCCEED; }); Dispatch->Action.Push(ActionKey::SetExpEnable, [this](std::string in, std::string& out) { return SetExpEnable(); }); Dispatch->Action.Push(ActionKey::SetExpDisable, [this](std::string in, std::string& out) { return SetExpDisable(); }); Dispatch->Set.Push(AttrKey::EXPTIMES, [this](std::string in) { auto value = JSONTo (in); return SetExposureTimes(value); }); Dispatch->Action.Push(ActionKey::SetExposureTimes, [this](std::string in, std::string& out) { auto value = JSONTo (in); return SetExposureTimes(value); }); Dispatch->Action.Push(ActionKey::SetGenAECSignal, [this](std::string in, std::string& out) { auto value = JSONTo (in); return SetGenAECSignal(value); }); Dispatch->Action.Push(ActionKey::SimulateFootSwitchSignal, [this](std::string in, std::string& out) { auto value = JSONTo (in); return SimulateFootSwitchSignal(value); }); Dispatch->Action.Push(ActionKey::SimulateHandSwitchSignal, [this](std::string in, std::string& out) { auto value = JSONTo (in); return SimulateHandSwitchSignal(value); }); Dispatch->Action.Push(ActionKey::SetDirectSignal, [this](std::string in, std::string& out) { ResDataObject json; json.decode(in.c_str()); int paramCount = json.size(); for (int i = 0; i < paramCount; i++) { string strName = json.GetKey(i); string strValue = (string)json[i]; SetDirectSignal(strName, atoi(strValue.c_str())); } return RET_STATUS::RET_SUCCEED; }); //重置 Dispatch->Action.Push(ActionKey::Reset, [this](std::string in, std::string& out) { return Reset(); }); //同步模式 Dispatch->Action.Push(ActionKey::ActiveSyncMode, [this](std::string in, std::string& out) { ResDataObject json; json.decode(in.c_str()); _tSyncModeArgs t{ }; if (json.size() >= 3) { t.strWS = (string)json[0]; t.strSyncMode = (string)json[1]; t.strSyncValue = (string)json[2]; return ActiveSyncMode(t); } else { return RET_STATUS::RET_FAILED; }}); //发生器内容 Dispatch->Get.Push(AttrKey::DiosHandSwitch, [this](std::string& out) { if (m_SynBoxUnit.m_HandSwitchState) out = m_SynBoxUnit.m_HandSwitchState->JSGet(); return RET_STATUS::RET_SUCCEED; }); Dispatch->Get.Push(AttrKey::DiosGeneratorSync, [this](std::string& out) { if (m_SynBoxUnit.m_GenSynState) out = m_SynBoxUnit.m_GenSynState->JSGet(); return RET_STATUS::RET_SUCCEED; }); Dispatch->Set.Push(AttrKey::DiosGeneratorSync, [this](std::string in) { auto value = JSONTo (in); return SetGeneratortoSyncStatus(value); }); Dispatch->Action.Push(ActionKey::SetGeneratortoSyncStatus, [this](std::string in, std::string& out) { auto value = JSONTo (in); return SetGeneratortoSyncStatus(value); }); Dispatch->Set.Push(AttrKey::EXPFRAMERAT, [this](std::string in) { auto value = JSONTo (in); return SetFrameRate(value); }); Dispatch->Action.Push(ActionKey::SetFrameRate, [this](std::string in, std::string& out) { auto value = JSONTo (in); return SetFrameRate(value); }); Dispatch->Action.Push(ActionKey::SetValue_PPS, [this](std::string in, std::string& out) { auto value = JSONTo (in); return SetValue_PPS(value); }); //探测器内容 Dispatch->Get.Push(AttrKey::DiosDetectorStatus, [this](std::string& out) { if (m_SynBoxUnit.m_DetectorState) out = m_SynBoxUnit.m_DetectorState->JSGet(); return RET_STATUS::RET_SUCCEED; }); Dispatch->Get.Push(AttrKey::DiosXwindowStatus, [this](std::string& out) { if (m_SynBoxUnit.m_DetectorWindowState) out = m_SynBoxUnit.m_DetectorWindowState->JSGet(); return RET_STATUS::RET_SUCCEED; }); Dispatch->Action.Push(ActionKey::PrepareAcquisition, [this](std::string in, std::string& out) { return PrepareAcquisition(); }); Dispatch->Action.Push(ActionKey::StartWindowRequest, [this](std::string in, std::string& out) { return StartWindowRequest(); }); Dispatch->Action.Push(ActionKey::StopWindowRequest, [this](std::string in, std::string& out) { return StopWindowRequest(); }); //CAN口内容 Dispatch->Get.Push(AttrKey::DiosGRIDSync, [this](std::string& out) { if (m_SynBoxUnit.m_GridStatue) out = m_SynBoxUnit.m_GridStatue->JSGet(); return RET_STATUS::RET_SUCCEED; }); } //----------------------------------------------------------------------------- // 所有的消息响应函数 //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- // 所有的 GetXX 函数 //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- // nsSYN::DriverMould //----------------------------------------------------------------------------- nsSYN::DriverMould::DriverMould () { ConfigInfo Vender (ConfKey::DiosType, "string", "R", "TRUE", ""); m_ConfigInfo.push_back(Vender); ConfigInfo Model (ConfKey::DiosModel, "string", "R", "TRUE", ""); m_ConfigInfo.push_back(Model); EasyJSONEncoder synList; synList.Set ("0", "1"); synList.Set ("1", "2"); ConfigInfo GenIsConnect (ConfKey::DiosIsConnect, "int", "RW", "FALSE", ""); GenIsConnect.SetList (synList.ToString ().c_str ()); m_ConfigInfo.push_back(GenIsConnect); ConfigInfo SCFType (ConfKey::DiosSCFType, "string", "R", "TRUE", ""); m_ConfigInfo.push_back(SCFType); EasyJSONEncoder COMList; COMList.Set ("0", "COM1"); COMList.Set ("1", "COM2"); COMList.Set ("2", "COM3"); COMList.Set ("3", "COM4"); COMList.Set ("4", "COM5"); COMList.Set ("5", "COM6"); COMList.Set ("6", "COM7"); COMList.Set ("7", "COM8"); COMList.Set ("8", "COM9"); COMList.Set ("9", "COM10"); COMList.Set ("10", "COM11"); COMList.Set ("11", "COM12"); ConfigInfo SCFPort (ConfKey::DiosSCFPort, "string", "RW", "TRUE", ""); SCFPort.SetList (COMList.ToString ().c_str ()); m_ConfigInfo.push_back(SCFPort); ConfigInfo SCFBaudrate (ConfKey::DiosSCFBaudrate, "int", "R", "FALSE", ""); m_ConfigInfo.push_back(SCFBaudrate); ConfigInfo SCFBytesize (ConfKey::DiosSCFBytesize, "int", "R", "FALSE", ""); m_ConfigInfo.push_back(SCFBytesize); ConfigInfo SCFParity (ConfKey::DiosSCFParity, "int", "R", "FALSE", ""); m_ConfigInfo.push_back(SCFParity); ConfigInfo SCFStopbits (ConfKey::DiosSCFStopbits, "int", "R", "FALSE", ""); m_ConfigInfo.push_back(SCFStopbits); } nsSYN::DriverMould::~DriverMould () { } std::string nsSYN::DriverMould::GetGUID () const { return DeviceDriverType; } #ifdef _WIN64 #ifdef _DEBUG static const auto COM_SCFDllName = "Dios.Dev.SerialSCFX64D.dll"; static const auto TCP_SCFDllName = "Dios.Dev.TcpipSCFX64D.dll"; #else static const auto COM_SCFDllName = "Dios.Dev.SerialSCFX64.dll"; static const auto TCP_SCFDllName = "Dios.Dev.TcpipSCFX64.dll"; #endif #endif string nsSYN::DriverMould::GetConnectDLL(string& ConfigFileName) { string ConnectDLL = COM_SCFDllName; ResDataObject r_config, Connection; if (!r_config.loadFile(ConfigFileName.c_str())) return ConnectDLL; if (r_config["CONFIGURATION"]["connections"].GetKeyCount("Value") > 0) { Connection = r_config["CONFIGURATION"]["connections"]["Value"]; } else { Connection = r_config["CONFIGURATION"]["connections"][0]; } if ((string)Connection["type"] == "COM") ConnectDLL = COM_SCFDllName; else ConnectDLL = TCP_SCFDllName; return ConnectDLL; } ResDataObject nsSYN::DriverMould::GetConnectParam(string& ConfigFileName) { ResDataObject r_config, Connection; if (!r_config.loadFile(ConfigFileName.c_str())) return Connection; if (r_config["CONFIGURATION"]["connections"].GetKeyCount("Value") > 0) { Connection = r_config["CONFIGURATION"]["connections"]["Value"]; } else { Connection = r_config["CONFIGURATION"]["connections"][0]; } return Connection; }