• 大小: 6.42MB
    文件类型: .gz
    金币: 2
    下载: 1 次
    发布日期: 2023-08-15
  • 语言: 其他
  • 标签: gige  vision  PC端代码  

资源简介

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(“\t“));
      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:

评论

共有 条评论