gige vision PC端代码,在windows和linux平台上可用。 降分分享,希望能帮助有缘人
代码片段和文件信息
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include “GigEVision.h“
#include “Gvcp.h“
#include “GenICam.h“
GenICamManager::GenICamManager(GigEVision& gev):
m_gev(gev)
{
}
void GenICamManager::ReadxmlFile()
{
std::vector data = m_gev.Gvcp().ReadBlock(GENICAM_ZIPFILEINFO_ADDRESS 512);
std::string sTxt(data.begin() data.end());
std::vector aParts;
boost::algorithm::split(aParts sTxt boost::algorithm::is_any_of(“;“));
if(aParts.size() != 3)
throw std::runtime_error(“Error getting genicam file location on camera“);
int nAddr nSize;
std::stringstream ss;
ss << std::hex << aParts[1];
ss >> nAddr;
ss.clear();
ss << std::hex << aParts[2];
ss >> nSize;
data = m_gev.Gvcp().ReadBlock(nAddr nSize);
// TODO: find a way to decompress the zip-file in menory without writing the file to disk
// TODO: use a platform independent path
std::string sFilename(“/tmp/genicam.zip“);
std::string retData;
try
{
std::ofstream os(sFilename.c_str() std::ios::binary);
os.write((char*)(&data[0]) data.size());
os.flush();
struct zip* zz = zip_open(sFilename.c_str() 0 0);
if(zz == 0)
throw std::runtime_error(“Error opening genicam zipfile“);
struct zip_file* zf = zip_fopen_index(zz 0 0);
if(zf == 0)
throw std::runtime_error(“Error opening file in zip archive“);
boost::array buff;
int nRead = 0;
while((nRead = zip_fread(zf buff.data() buff.size())) != 0)
std::copy(buff.begin() buff.begin()+nRead std::back_inserter(retData));
// clean up file from disk
boost::filesystem::remove(sFilename);
}
catch(std::exception& e)
{
boost::filesystem::remove(sFilename);
throw e;
}
setenv(“GENICAM_ROOT_V1_1“ GENICAM_ROOT_PATH true);
m_cam._LoadxmlFromString(retData.c_str());
}
uint32_t GenICamManager::GetAddress(const std::string& sKey)
{
GenApi::INode* pN = m_cam._GetNode(sKey.c_str());
uint32_t nAddr = 0;
if(pN != 0)
{
GenICam::gcstring val att;
if(pN->GetProperty(“Address“ val att))
{
nAddr = boost::lexical_cast(val);
}
if(pN->GetProperty(“pAddress“ val att) && val.length() > 0)
{
std::string sTmp(val);
std::vector parts;
boost::algorithm::split(parts sTmp boost::algorithm::is_any_of(“ “));
for(size_t i=0; i {
GenApi::INode* pAddrNode = m_cam._GetNode(parts[i].c_str());
assert(pAddrNode);
GenICam::gcstring sAddr sAtt;
assert(pAddrNode->GetProperty(“Value“ sAddr sAtt));
nAddr += boost::lexical_cast(sAddr);
}
}
}
else
throw std::runtime_error(str(boost:
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。
评论列表(条)