#pragma once #include "spHelper.h" #include "SimpleString.h" #include "Blob.h" //#define DeviceService_Method_GetDevInfo 65535 //#define DeviceService_MethodSignature_GetDevInfo 296205965 // //struct DeviceService_GetDevInfo_Req //{ // void Serialize(SpBuffer &Buf) // { // } //}; // //struct DeviceService_GetDevInfo_Ans //{ // CSimpleStringA type; // CSimpleStringA model; // CSimpleStringA vendor; // int state; // WORD wMajor; //release major version // WORD wMinor; //release minor version // WORD wRevision; //bug repair version with the major and minor version remains the same // WORD wBuild; //compile version // // void Serialize(SpBuffer &Buf) // { // Buf & type & model & vendor & state & wMajor & wMinor & wRevision & wBuild; // } //}; // //class DeviceService_ClientBase : public CClientSessionBase { //public: // DeviceService_ClientBase(CEntityBase *pEntity) : m_pEntityBase(pEntity), m_bSysManaged(false) {} // //protected: // virtual ~DeviceService_ClientBase() {} // //public: // // ErrorCodeEnum Connect(CSmartPointer &spAsyncWait, const CSimpleStringA &strRemoteEntity) // { // CSmartPointer pFunc = m_pEntityBase->GetFunction(); // // CSimpleStringA strServiceName = strRemoteEntity + "Service"; // ErrorCodeEnum Error = pFunc->ConnectRemoteEntity(this, (const char*)strRemoteEntity, (const char*)strServiceName, spAsyncWait); // if (Error == Error_Succeed) { // m_bSysManaged = true; // } // return Error; // } // // ErrorCodeEnum Connect(const CSimpleStringA &strRemoteEntity) // { // CSmartPointer spAsyncWait; // ErrorCodeEnum Error = Connect(spAsyncWait, strRemoteEntity); // if (Error == Error_Succeed) { // Error = spAsyncWait->WaitAnswer(); // } // return Error; // } // // ErrorCodeEnum GetDevInfo(DeviceService_GetDevInfo_Req &Req, CSmartPointer &spAsyncWait, DWORD dwTimeout) // { // CSmartPointer pFunc = GetFunction(); // CAutoBuffer Buf = SpObject2Buffer(Req); // return pFunc->AsyncRequest(DeviceService_Method_GetDevInfo, DeviceService_MethodSignature_GetDevInfo, Buf, spAsyncWait, dwTimeout); // } // // ErrorCodeEnum GetDevInfo(DeviceService_GetDevInfo_Req &Req, DeviceService_GetDevInfo_Ans &Ans, DWORD dwTimeout) // { // CSmartPointer spAsyncWait; // ErrorCodeEnum Error = GetDevInfo(Req, spAsyncWait, dwTimeout); // if (Error == Error_Succeed) { // bool bEnd = false; // Error = SpWaitAnswerObject(spAsyncWait, Ans, bEnd); // LOG_ASSERT(Error || bEnd); // } // return Error; // } // // bool SafeDelete() // { // if (!m_bSysManaged) { // delete this; // } // return m_bSysManaged; // } // //protected: // bool m_bSysManaged; // CEntityBase *m_pEntityBase; //}; // //ErrorCodeEnum SpGetDeviceInfo(CEntityBase *pEntity, const CSimpleStringA &devDevEntityName, // CSimpleStringA &strType, CSimpleStringA &strModel, CSimpleStringA &strVendor, int &nState, CBlob &blobVersion) //{ // DeviceService_ClientBase *pClient = new DeviceService_ClientBase(pEntity); // ErrorCodeEnum rc = pClient->Connect(devDevEntityName); // if (rc == Error_Succeed) // { // DeviceService_GetDevInfo_Req req; // DeviceService_GetDevInfo_Ans ans; // rc = pClient->GetDevInfo(req, ans, 5000); // if (rc == Error_Succeed) // { // strType = ans.type; // strModel = ans.model; // strVendor = ans.vendor; // nState = ans.state; // blobVersion.Alloc(8); // ((BYTE*)blobVersion.m_pData)[0] = (ans.wMajor >> 8) & 0xFF; // ((BYTE*)blobVersion.m_pData)[1] = ans.wMajor & 0xFF; // ((BYTE*)blobVersion.m_pData)[2] = (ans.wMinor >> 8) & 0xFF; // ((BYTE*)blobVersion.m_pData)[3] = ans.wMinor & 0xFF; // ((BYTE*)blobVersion.m_pData)[4] = (ans.wRevision >> 8) & 0xFF; // ((BYTE*)blobVersion.m_pData)[5] = ans.wRevision & 0xFF; // ((BYTE*)blobVersion.m_pData)[6] = (ans.wBuild >> 8) & 0xFF; // ((BYTE*)blobVersion.m_pData)[7] = ans.wBuild & 0xFF; // } // pClient->GetFunction()->CloseSession(); // } // pClient->SafeDelete(); // return rc; //} ErrorCodeEnum SpGetAllDevices(CEntityBase *pEntity, CAutoArray &devs) { CSmartPointer pConfig; ErrorCodeEnum rc = pEntity->GetFunction()->OpenConfig(Config_Root, pConfig); if (rc == Error_Succeed) { int nCount(0); rc = pConfig->ReadConfigValueInt("Device", "Number", nCount); if (rc == Error_Succeed && nCount>0) { devs.Init(nCount); for(int i=0; iReadConfigValue("Device", (const char*)str, devs[i]); } } } return rc; } ErrorCodeEnum SpGetDeviceInfo(CEntityBase *pCallerEntity, const CSimpleStringA &devDeviceName, CSimpleStringA &strModel, CSimpleStringA &strVendor, CSimpleStringA &strVersion) { CSmartPointer pConfig; ErrorCodeEnum rc = pCallerEntity->GetFunction()->OpenConfig(Config_Root, pConfig); if (rc == Error_Succeed) { CSimpleStringA strSection = CSimpleStringA("Device.") + devDeviceName; pConfig->ReadConfigValue(strSection, "Vendor", strVendor); pConfig->ReadConfigValue(strSection, "Version", strVersion); strModel = devDeviceName; if (!strVendor.IsNullOrEmpty()) { strModel += "."; strModel += strVendor; } if (!strVersion.IsNullOrEmpty()) { strModel += "."; strModel += strVersion; } } return rc; } ErrorCodeEnum SpGetDevAdaptorPath(CEntityBase *pCallerEntity, const CSimpleStringA &devDeviceName, CSimpleStringA &strDevAdaptorPath) { CSmartPointer pConfig; ErrorCodeEnum rc = pCallerEntity->GetFunction()->OpenConfig(Config_Root, pConfig); if (rc == Error_Succeed) { CSimpleStringA strSection = CSimpleStringA("Device.") + devDeviceName; strDevAdaptorPath = devDeviceName; CSimpleStringA str; pConfig->ReadConfigValue(strSection, "Vendor", str); if (!str.IsNullOrEmpty()) { strDevAdaptorPath += "."; strDevAdaptorPath += str; } str.Clear(); pConfig->ReadConfigValue(strSection, "Version", str); if (!str.IsNullOrEmpty()) { strDevAdaptorPath += "."; strDevAdaptorPath += str; } str.Clear(); pConfig->ReadConfigValue(strSection, "Batch", str); if (!str.IsNullOrEmpty()) { strDevAdaptorPath += "."; strDevAdaptorPath += str; } CSimpleStringA strDepPath; pCallerEntity->GetFunction()->GetPath("Dep", strDepPath); strDevAdaptorPath = CSimpleStringA::Format("%s\\%s.dll", (const char*)strDepPath, (const char*)strDevAdaptorPath); } return rc; } // add by ly ErrorCodeEnum SpGetDevAdaptorPathByIndex(int nIndex, CEntityBase *pCallerEntity, const CSimpleStringA &devDeviceName, CSimpleStringA &strDevAdaptorPath) { CSmartPointer pConfig; ErrorCodeEnum rc = pCallerEntity->GetFunction()->OpenConfig(Config_Root, pConfig); if (rc == Error_Succeed) { char tmp[64] = {0}; CSimpleStringA strSection = CSimpleStringA("Device.") + devDeviceName; strDevAdaptorPath = devDeviceName; CSimpleStringA str; sprintf(tmp, "Vendor_%d", nIndex); pConfig->ReadConfigValue(strSection, tmp, str); if (!str.IsNullOrEmpty()) { strDevAdaptorPath += "."; strDevAdaptorPath += str; } str.Clear(); sprintf(tmp, "Version_%d", nIndex); pConfig->ReadConfigValue(strSection, tmp, str); if (!str.IsNullOrEmpty()) { strDevAdaptorPath += "."; strDevAdaptorPath += str; } str.Clear(); sprintf(tmp, "Batch_%d", nIndex); pConfig->ReadConfigValue(strSection, tmp, str); if (!str.IsNullOrEmpty()) { strDevAdaptorPath += "."; strDevAdaptorPath += str; } CSimpleStringA strDepPath; pCallerEntity->GetFunction()->GetPath("Dep", strDepPath); strDevAdaptorPath = CSimpleStringA::Format("%s\\%s.dll", (const char*)strDepPath, (const char*)strDevAdaptorPath); } return rc; }