1、开发环境
VS2019+VC+Windowsx64
2、引用包含
头文件
C:/Program Files/Teledyne DALSA/Sapera/Classes
C:/Program Files/Teledyne DALSA/Sapera/Include
库
C:/Program Files/Teledyne DALSA/Sapera/Lib/Win64/SapClassBasic.lib
3、代码
头文件
#include <Basic/SapClassBasic.h>
关键成员变量
SapTransfer* m_Xfer;
SapBuffer* m_Buffers;
SapAcquisition* m_Acq;
4、初始化相机
bool DalsaScan::InitCarmer(std::string ServerName, std::string ConfigPath, int ResourceIndex)
{
if (initstate)
{
Destroy();
}
_buffcallback = nullptr;
m_Acq = nullptr;
m_Buffers = nullptr;
m_Xfer = nullptr;
initstate = false;
SapLocation loc(ServerName.c_str(), ResourceIndex);
if (SapManager::GetResourceCount(ServerName.c_str(), SapManager::ResourceAcq) > 0)
{
m_Acq = new SapAcquisition(loc, ConfigPath.c_str());
m_Buffers = new SapBufferWithTrash(2, m_Acq);
m_Xfer = new SapAcqToBuf(m_Acq, m_Buffers, XferCallback, this);
}
if (!CreateObject())
{
return false;
}
initstate = true;
return initstate;
}
bool DalsaScan::CreateObject()
{
// Create acquisition object
if (m_Acq && !*m_Acq && !m_Acq->Create())
{
DestoryObject();
return false;
}
// Create buffer object
if (m_Buffers && !*m_Buffers)
{
if (!m_Buffers->Create())
{
DestoryObject();
return false;
}
// Clear all buffers
m_Buffers->Clear();
}
// Create transfer object
if (m_Xfer && !*m_Xfer && !m_Xfer->Create())
{
DestoryObject();
return false;
}
return true;
}
void DalsaScan::Destroy()
{
DestoryObject();
initstate = false;
}
void DalsaScan::DestoryObject()
{
// Destroy transfer object
if (m_Xfer && *m_Xfer)
{
m_Xfer->Destroy();
}
// Destroy Buffer object
if (m_Buffers && *m_Buffers)
{
m_Buffers->Destroy();
}
// Destroy acquisition object
if (m_Acq && *m_Acq)
{
m_Acq->Destroy();
}
if (m_Xfer != nullptr)
{
delete m_Xfer;
}
if (m_Buffers != nullptr)
{
delete m_Buffers;
}
if (m_Acq != nullptr)
{
delete m_Acq;
}
m_Xfer = nullptr;
m_Buffers = nullptr;
m_Acq = nullptr;
initstate = false;
}
5、采图控制
bool DalsaScan::Grab()
{
return initstate?m_Xfer->Grab():initstate;
}
bool DalsaScan::Snap()
{
return initstate?m_Xfer->Snap():initstate;
}
bool DalsaScan::Freeze()
{
return initstate?m_Xfer->Freeze():initstate;
}
6、枚举采集卡名称
std::list<std::string> DalsaScan::EnumCardName()
{
list<string> cardlist = list<string>();
int serverCount = SapManager::GetServerCount();
if (serverCount == 0)
{
return cardlist;
}
for (int i = 0; i < serverCount; i++)
{
if (SapManager::GetResourceCount(i, SapManager::ResourceAcq) != 0)
{
char* serverName = nullptr;
serverName = (char*)malloc(CORSERVER_MAX_STRLEN);
if (serverName != nullptr)
{
memset(serverName, 0, CORSERVER_MAX_STRLEN);
SapManager::GetServerName(i, serverName, CORSERVER_MAX_STRLEN);
string name(serverName);
free(serverName);
if(name == "System")
{
continue;
}
cardlist.push_back(name);
}
else
{
printf("EnumCardName: Get CardName Memery Fail\n");
}
}
}
return cardlist;
}
7、使用示例
int main()
{
shared_ptr<IPythonScan> cis = GetCamer::GetCurrentCamera();
list<string> cardlist = cis->EnumCardName();
if (cardlist.size() == 0)
{
printf("card number is 0!\n");
system("pause");
return -0;
}
else
{
for (string name : cardlist)
{
printf("card name: %s\n", name.c_str());
}
}
if (!cis->InitCarmer(cardlist.front(), "C:\\Users\\wl\\Desktop\\N_No_Name_Default_Default.ccf", 0))
{
printf("init card fail!\n");
system("pause");
return -1;
}
if (!cis->CameraIsOnline())
{
printf("not detected camera!\n");
system("pause");
return -2;
}
cis->Destroy();
system("pause");
}
由于我的库里面掺杂了一些关于我们公司相机的控制选项,不适用其他公司的相机,就暂不放出来了,本人用DALSA的SDK不太熟悉,有问题请各位大大及时指正