📄 vc1394bcamdlg.cpp
字号:
//////////////////////////////////////////////////////////////////////////////
//
// Basler Vision Technologies
//
//////////////////////////////////////////////////////////////////////////////
//
// File - VC 1394BCAM Application
// Date - 23.11.05
// Version - 1.00
//
// Author - James Swift
// Contact - vc.support.europe@baslerweb.com
//
//////////////////////////////////////////////////////////////////////////////
/////////////////////// History and Changes //////////////////////////////////
//
// Release v1,0,0,0 - 23.11.05
// First release
//
// Release v1,0,0,1 - 6.1.06
// Added support for Read/Write registers
// Fixed bug with radio button grouping
// Fixed bug with trigger support
//
//////////////////////////////////////////////////////////////////////////////
/////////////////////// Notes ////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "VC1394BCAM.h"
#include "VC1394BCAMDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// link image manger lib's (LIB file directories must be set properly)
#pragma comment (lib, "cvcimg.lib")
#pragma comment (lib, "cvcutilities.lib")
#pragma comment (lib, "cvcdriver.lib")
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CVC1394BCAMDlg dialog
CVC1394BCAMDlg::CVC1394BCAMDlg(CWnd* pParent /*=NULL*/)
: CDialog(CVC1394BCAMDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CVC1394BCAMDlg)
m_bGrab = FALSE;
m_szCameraDetails = _T("");
m_szGet = _T("");
m_szSet = _T("");
m_szRegister = _T("f0f0081c");
m_szRegisterVal = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CVC1394BCAMDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CVC1394BCAMDlg)
DDX_Control(pDX, IDC_CVDISP, m_cvDisp);
DDX_Control(pDX, IDC_CVIMG, m_cvImg);
DDX_Check(pDX, IDC_C_GRAB, m_bGrab);
DDX_Text(pDX, IDC_S_CAMERADETAILS, m_szCameraDetails);
DDX_Text(pDX, IDC_E_GET, m_szGet);
DDX_Text(pDX, IDC_E_SET, m_szSet);
DDX_Text(pDX, IDC_E_REGISTER, m_szRegister);
DDX_Text(pDX, IDC_E_REGISTER_VAL, m_szRegisterVal);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CVC1394BCAMDlg, CDialog)
//{{AFX_MSG_MAP(CVC1394BCAMDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_B_OPENIMG, OnBOpenimg)
ON_BN_CLICKED(IDC_B_SAVEIMG, OnBSaveimg)
ON_BN_CLICKED(IDC_C_GRAB, OnCGrab)
ON_BN_CLICKED(IDC_B_CAMERADETAILS, OnBCameradetails)
ON_BN_CLICKED(IDC_R_TRIGDISABLED, OnRTrigdisabled)
ON_BN_CLICKED(IDC_R_TRIGASYNC, OnRTrigasync)
ON_BN_CLICKED(IDC_B_GET, OnBGet)
ON_BN_CLICKED(IDC_B_SET, OnBSet)
ON_BN_CLICKED(IDC_R_GAIN, OnRGain)
ON_BN_CLICKED(IDC_R_BRIGHTNESS, OnRBrightness)
ON_BN_CLICKED(IDC_R_SHUTTER, OnRShutter)
ON_BN_CLICKED(IDC_B_REGISTER_READ, OnBRegisterRead)
ON_BN_CLICKED(IDC_B_REGISTER_WRITE, OnBRegisterWrite)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CVC1394BCAMDlg message handlers
BOOL CVC1394BCAMDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
((CButton*)GetDlgItem(IDC_R_TRIGDISABLED))->SetCheck(TRUE);
((CButton*)GetDlgItem(IDC_R_TRIGASYNC))->SetCheck(FALSE);
((CButton*)GetDlgItem(IDC_R_GAIN))->SetCheck(TRUE);
((CButton*)GetDlgItem(IDC_R_BRIGHTNESS))->SetCheck(FALSE);
((CButton*)GetDlgItem(IDC_R_SHUTTER))->SetCheck(FALSE);
// Set the default Command ID
m_CommandID = DC_1394BCAM_GAIN;
return TRUE; // return TRUE unless you set the focus to a control
}
void CVC1394BCAMDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CVC1394BCAMDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CVC1394BCAMDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CVC1394BCAMDlg::OnBOpenimg()
{
// Load the image and pipe it to the display
m_cvImg.LoadImageByDialog();
m_cvDisp.SetImage(m_cvImg.GetImage());
}
void CVC1394BCAMDlg::OnBSaveimg()
{
// Save the image using the common dialog
m_cvImg.SaveImageByDialog();
}
void CVC1394BCAMDlg::OnCGrab()
{
UpdateData(TRUE);
// Set the grab mode
m_cvImg.SetGrab(m_bGrab);
}
BEGIN_EVENTSINK_MAP(CVC1394BCAMDlg, CDialog)
//{{AFX_EVENTSINK_MAP(CVC1394BCAMDlg)
ON_EVENT(CVC1394BCAMDlg, IDC_CVIMG, 5 /* ImageSnaped */, OnImageSnapedCvimg, VTS_NONE)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
void CVC1394BCAMDlg::OnImageSnapedCvimg()
{
// Refresh the display
m_cvDisp.Refresh();
}
void CVC1394BCAMDlg::GetStrCommandID(DC_1394BCAM_PARAM CommandID, CString &csResult)
{
long lStrLength;
char *szResult;
// Verify the image is valid
if (IsImage((IMG) m_cvImg.GetImage()))
{
// Call the DCStrCommand function with a null string to retrieve the required string length
DCStrCommand((IMG) m_cvImg.GetImage(), DC_GET | CommandID, NULL, NULL, NULL, lStrLength);
// Allocate the required string
szResult = (char *) malloc(lStrLength);
// Call the DCStrCommand function with the allocated string
DCStrCommand((IMG) m_cvImg.GetImage(), DC_GET | CommandID, NULL, NULL, szResult, lStrLength);
// Return the result
csResult.Format(szResult);
}
}
void CVC1394BCAMDlg::OnBCameradetails()
{
CString csVendor, csCameraModel, csSerialNumber, csDCAM, csDriver;
// Verify the image is valid
if (IsImage((IMG) m_cvImg.GetImage()))
{
// Retrieve all the camera parameters
GetStrCommandID(DC_1394BCAM_VENDOR, csVendor);
GetStrCommandID(DC_1394BCAM_CAMERA_MODEL, csCameraModel);
GetStrCommandID(DC_1394BCAM_SERIAL_NUMBER, csSerialNumber);
GetStrCommandID(DC_1394BCAM_DCAM_VERSION, csDCAM);
GetStrCommandID(DC_1394BCAM_DRIVER_SW_VERSION, csDriver);
// Format the display string
m_szCameraDetails.Format("Vendor : %s\nModel : %s\nSerial Number : %s\nDCAM : v%s\nDriver SW : v%s\n", csVendor, csCameraModel, csSerialNumber, csDCAM, csDriver);
}
UpdateData(FALSE);
}
void CVC1394BCAMDlg::OnRTrigdisabled()
{
// Disable the trigger
if( ((CButton*)GetDlgItem(IDC_R_TRIGDISABLED))->GetCheck())
SetTriggerMode ((IMG) m_cvImg.GetImage(), CVC_C_TRIGGER_DISABLE);
}
void CVC1394BCAMDlg::OnRTrigasync()
{
// Enable the trigger
if( ((CButton*)GetDlgItem(IDC_R_TRIGASYNC))->GetCheck())
SetTriggerMode ((IMG) m_cvImg.GetImage(), CVC_C_TRIGGER_ASYNCRON);
}
void CVC1394BCAMDlg::OnBGet()
{
long lLength;
UINT32 ui32Output;
UpdateData (TRUE);
if (IsImage((IMG) m_cvImg.GetImage()))
{
// Determing the length of the string
lLength = sizeof(UINT32);
// Pass the allocated string to return the parameter
DCBinaryCommand((IMG) m_cvImg.GetImage(), DC_GET | m_CommandID, NULL, NULL, &ui32Output, lLength);
// Display the current value
m_szGet.Format("%d", ui32Output);
}
UpdateData (FALSE);
}
void CVC1394BCAMDlg::OnBSet()
{
long lLength, lDummy;
UINT32 ui32Input;
UpdateData (TRUE);
// Determine the length of the value
lLength = sizeof(UINT32);
// Store the new value
ui32Input = atol(m_szSet.GetBuffer(1));
// Pass the new value
DCBinaryCommand((IMG) m_cvImg.GetImage(), DC_SET | m_CommandID, &ui32Input, lLength, NULL, lDummy);
UpdateData (FALSE);
}
void CVC1394BCAMDlg::OnRGain()
{
// Set the command ID
m_CommandID = DC_1394BCAM_GAIN;
}
void CVC1394BCAMDlg::OnRBrightness()
{
// Set the command ID
m_CommandID = DC_1394BCAM_BRIGHTNESS;
}
void CVC1394BCAMDlg::OnRShutter()
{
// Set the command ID
m_CommandID = DC_1394BCAM_SHUTTER;
}
void CVC1394BCAMDlg::OnBRegisterRead()
{
long lInputLength, lOutputLength;
UINT32 ui32Input, ui32Output;
UpdateData (TRUE);
if (IsImage((IMG) m_cvImg.GetImage()))
{
// Determing the length of the string
lInputLength = sizeof(UINT32);
lOutputLength = sizeof(UINT32);
ui32Input = strtoul(m_szRegister.GetBuffer(1), NULL, 16);
// Pass the allocated string to return the parameter
DCBinaryCommand((IMG) m_cvImg.GetImage(), DC_GET | DC_1394BCAM_REGISTER_READ, &ui32Input, lInputLength, &ui32Output, lOutputLength);
// Display the current value
m_szRegisterVal.Format("%x", ui32Output);
}
UpdateData (FALSE);
}
void CVC1394BCAMDlg::OnBRegisterWrite()
{
long lInputLength, lOutputLength;
UINT32 ui32Input, ui32Output;
UpdateData (TRUE);
// Determine the length of the value
lInputLength = sizeof(UINT32);
lOutputLength = sizeof(UINT32);
// Store the new value
ui32Input = strtoul(m_szRegister.GetBuffer(1), NULL, 16);
ui32Output = strtoul(m_szRegisterVal.GetBuffer(1), NULL, 16);
// Pass the new value
DCBinaryCommand((IMG) m_cvImg.GetImage(), DC_SET | DC_1394BCAM_REGISTER_WRITE, &ui32Input, lInputLength, &ui32Output, lOutputLength);
UpdateData (FALSE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -