⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bcam.cpp

📁 BCAM 1394 Driver
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/**
 * \brief given a friendly device name return a full device name
 *
 * The Bcam API is dealing with friendly device names. Friendly device names don't contain 
 * the driver's interface GUID. This function converts a friendly device name into a full device name, 
 * as it is used by the system. 
 *
 * \param     DeviceName a friendly device name
 * \return    the full device name
 *
 */
//------------------------------------------------------------------------------
CString BcamUtility::FullDeviceName(CString DeviceName)
{

  if (!IsFullDeviceName(DeviceName))
  {
    struct _GUID guid = GUID_FILE_DEVICE_BCAM_1394;
    CString guidString;
    guidString.Format( _T("#{%08lX-%04X-%04x-%02X%02X-%02X%02X%02X%02X%02X%02X}"), 
      guid.Data1, guid.Data2, guid.Data3, 
      guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3], 
      guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]); 
    return _T( "\\\\?\\1394#" ) + DeviceName + guidString;
  }
  else return DeviceName;
}


//------------------------------------------------------------------------------
// CString BcamUtility::FriendlyDeviceName(CString DeviceName)
// Author: 
// Date: 26.10.2002
//------------------------------------------------------------------------------
/**
 * \brief Retrieves the friendly device name for a given full device name
 *
 * The Bcam API is dealing with friendly device names. Friendly device names don't contain 
 * the driver's interface GUID. This function converts a full device named used by the system into a 
 * friendly device name
 *
 *  \param   DeviceName the full device name
 * \return   the friendly device name 
 *
 */
//------------------------------------------------------------------------------
CString BcamUtility::FriendlyDeviceName(CString DeviceName)
{
  if (IsFullDeviceName(DeviceName))
  {
    int first = DeviceName.Find('#');
    assert(first > 0);
    int l = DeviceName.GetLength();
    int second = DeviceName.Right(l - (first+1)).Find('#') + first + 1;
    assert(second > 0);
    int third = DeviceName.Right(l - (second+1)).Find('#') + second + 1;
    assert(third > 0);
    assert(DeviceName[third+1] == '{');
    return DeviceName.Left(third).Right(third-(first+1));
  }
  else return DeviceName;
}


///////////////////////////////////////////////////////////////////////////////
//
// class CBcam
//
///////////////////////////////////////////////////////////////////////////////

// static member initialization
HDEVNOTIFY CBcam::s_hDevInterfaceNotify = INVALID_HANDLE_VALUE;
CBcam::BcamMap_t CBcam::s_BcamMap;
HWND CBcam::s_hWndNotify = NULL;
HWND CBcam::s_hWndMsgOnly = NULL;
WNDPROC CBcam::s_lpPrevWndFunc = NULL;
ULONG CBcam::s_CompletionKey = 0;
//CThread CBcam::s_MessageLoopThread;
CBcam::CCleanUp CBcam::s_CleanUp;


///////////////////////////////////////////////////////////////////////////////
//
// CBcam::CBoolControl 
//
//

//------------------------------------------------------------------------------
// bool CBcam::CBoolControl::operator ()
// Author: 
//------------------------------------------------------------------------------
/**
 * \brief Inquire the feature is on or off.
 *
 * \retval  true if it is on    
 * \retval  false if it is not on
 */
//------------------------------------------------------------------------------
bool CBcam::CBoolControl::operator ()()
{
  throw BcamException( Bvc::ErrorNumber( E_NOTIMPL ), _T( "CBcam::CBoolControl::operator()" ) );
}

//------------------------------------------------------------------------------
// void CBcam::CBoolControl::operator =( bool OnOff )
// Author: 
//------------------------------------------------------------------------------
/**
 * \brief Turn a feature on or off
 *
 * \param     OnOff  true is on, false is off
 */
//------------------------------------------------------------------------------
void CBcam::CBoolControl::operator =( bool /*OnOff*/ )
{
  throw BcamException( Bvc::ErrorNumber( E_NOTIMPL ), _T( "CBcam::CBoolControl::operator=()" ) );
}
///////////////////////////////////////////////////////////////////////////////
//
// class CBcam::CScalarProperty
//
//

//------------------------------------------------------------------------------
// CBcam::CScalarProperty::CScalarProperty(  FunctionCode_t AsyncFuncCodeRaw,  FunctionCode_t AsyncFuncCodeAbs,  BcamFeatureID FuncId,  CBcam* pBcam ) : m_FunctionId( FuncId),  m_pBcam( FuncId, pBcam ), AbsControl( FuncId, mAbsControl, pBcam ), AutoMode( FuncId, mAutoMode, pBcam ), OnOff( FuncId, mOnOff, pBcam ), Raw( AsyncFuncCodeRaw, FuncId, pBcam ), Abs( AsyncFuncCodeAbs, FuncId, pBcam ){  /* NOP */ }
// Author: 
//------------------------------------------------------------------------------
/**
 * \brief Contruct a scalar property.
 *
 * \param     AsyncFuncCodeRaw Function code for asynchronous calls to raw register
 * \param     AsyncFuncCodeAbs Function code for asynchronous calls to absolute register
 * \param     FuncId Feature identifier
 * \param     pBcam Backpointer to the communication object
 */
//------------------------------------------------------------------------------
CBcam::CScalarProperty::CScalarProperty( 
                                        FunctionCode_t AsyncFuncCodeRaw, 
                                        FunctionCode_t AsyncFuncCodeAbs, 
                                        BcamFeatureID FuncId, 
                                        CBcam* pBcam ) 
: m_FunctionId( FuncId), 
  m_pBcam( pBcam ),
  AbsControl( FuncId, mAbsControl, pBcam ),
  AutoMode( FuncId, mAutoMode, pBcam  ),
  OnOff( FuncId, mOnOff, pBcam  ),
  Raw( AsyncFuncCodeRaw, FuncId, pBcam ),
  Abs( AsyncFuncCodeAbs, FuncId, pBcam )
{ 
  /* NOP */ 
}

//------------------------------------------------------------------------------
// bool CBcam::CScalarProperty::IsSupported(Supported_t Inquiry)
// Author: 
//------------------------------------------------------------------------------
/**
* \brief Inquire wether a feature is supported.
*
* \param     Inquiry Code of the requested feature.
* \return    
*
* Returns whether the feature is supported by the camera
* If the feature is not specified in DCAM then a BcamException with the
* error code BCAM_E_INVALID_INQUIRY is thrown.
* \exception BcamException The value of \c ::GetLastError() is thrown
*/
//------------------------------------------------------------------------------
bool CBcam::CScalarProperty::IsSupported(Supported_t Inquiry)
{
  ArgQueryDCSFeatureInq arg;
  arg.FeatId = m_FunctionId;
  ResQueryDCSFeatureInq res;
  m_pBcam->TryTransmit( _T( "CBcam::CScalarProperty::IsSupported()" ), IOCTL_BCAM_QUERY_DCS_FEATURE_INQ, &arg, sizeof(arg), &res, sizeof(res));
  switch ( Inquiry )
  {
  case inqPresent:
    return res.Scalar.Presence_Inq;
  case inqAbsControl:
    return res.Scalar.Abs_Control_Inq;
  case inqOnePush:
    return res.Scalar.One_Push_Inq;
  case inqReadOut:
    return res.Scalar.Read_Out_Inq;
  case inqOnOff:
    return res.Scalar.On_Off_Inq;
  case inqAuto:
    return res.Scalar.Auto_Inq;
  case inqManual:
    return res.Scalar.Manual_Inq;
  default:
    throw BcamException( BCAM_E_INVALID_INQUIRY, _T( "CBcam::CScalarProperty::IsSupported()" ), &Inquiry);
    
  }
  // return true;
}

//------------------------------------------------------------------------------
// void CBcam::CScalarProperty::OnePush()
// Author: 
//------------------------------------------------------------------------------
/**
* \brief Activate the OnePush feature.
* \exception BcamException The value of \c ::GetLastError() is thrown
*/
//------------------------------------------------------------------------------
void CBcam::CScalarProperty::OnePush()
{
  ArgSetDCSFeatureCSR arg;
  ZeroMemory(&arg, sizeof(arg));
  arg.FeatId = m_FunctionId;
  arg.FeatCSRDescriptor.Scalar.One_Push = 1;
  arg.Mask = DCS_FEATURE_CSR_SET_ONE_PUSH;
  m_pBcam->TryTransmit( _T( "CBcam::CScalarProperty::OnePush()" ), IOCTL_BCAM_SET_DCS_FEATURE_CSR, &arg, sizeof(arg) );
}

///////////////////////////////////////////////////////////////////////////////
// class CBcam::CScalarProperty::CBoolControl

//------------------------------------------------------------------------------
// CBcam::CScalarProperty::CBoolControl::CBoolControl( BcamFeatureID FuncId, Mode_t Mode, CBcam* pBcam ) : m_pBcam( pBcam ), m_FunctionId ( FuncId), m_Mode (Mode)
// Author: A. Happe
//------------------------------------------------------------------------------
/**
* \brief Create a switch for a part of a DCAM feature (e.g. Auto mode of Brightness)
*
* \param     FuncId Identifies the feature
* \param     Mode   Identifies the part of the feature
* \param     pBcam  Backpointer to the communication object 
*/
//------------------------------------------------------------------------------
CBcam::CScalarProperty::CBoolControl::CBoolControl( BcamFeatureID FuncId, Mode_t Mode, CBcam* pBcam ) 
: m_pBcam( pBcam ),
m_FunctionId ( FuncId),
m_Mode (Mode)
{
  /* NOP */ 
}

//------------------------------------------------------------------------------
// void CBcam::CScalarProperty::CBoolControl::operator=(bool Value)
// Author: Hartmut Nebelung
//------------------------------------------------------------------------------
/**
* \brief Set the value of the feature synchronously.
*
* \param     Value  The value to set, true means on and false off.
* 
* \throw BcamException The value of ::GetLastError() is thrown
*
* \b Example 
* \code
* m_pBcam->Brightness.AutoMode = true;
* m_pBcam->Brightness.AutoMode.operator =( true );
* \endcode
*/
//------------------------------------------------------------------------------
void CBcam::CScalarProperty::CBoolControl::operator=(bool Value)
{
  ArgSetDCSFeatureCSR arg;
  ZeroMemory(&arg, sizeof(arg));
  arg.FeatId = m_FunctionId;
  switch ( m_Mode )
  {
  case mOnOff:
    arg.FeatCSRDescriptor.Scalar.ON_OFF = Value;
    arg.Mask = DCS_FEATURE_CSR_SET_ON_OFF;
    break;
  case mAutoMode:
    arg.FeatCSRDescriptor.Scalar.A_M_Mode = Value;
    arg.Mask = DCS_FEATURE_CSR_SET_A_M_MODE;
    break;
  case mAbsControl:
    arg.FeatCSRDescriptor.Scalar.Abs_Control = Value;
    arg.Mask = DCS_FEATURE_CSR_SET_ABS_CONTROL;
    break;
  default:
    assert(false);
  }
  m_pBcam->TryTransmit( _T( "CBcam::CScalarProperty::CBoolControl::operator=()" ), IOCTL_BCAM_SET_DCS_FEATURE_CSR, &arg, sizeof(arg) );
}


//------------------------------------------------------------------------------
// bool CBcam::CScalarProperty::CBoolControl::operator()()
// Author: Hartmut Nebelung
//------------------------------------------------------------------------------
/**
* \brief Get the value of the feature synchronously.
*
* \return    
*
* Returns the current value. True means on and false off.
* 
* \throw BcamException The value of ::GetLastError() is thrown
*
* \b Example
* \code
* bool IsOn;
* IsOn = m_pBcam->Brightness.AutoMode();
* IsOn = m_pBcam->Brightness.AutoMode.operator()();
* \endcode
*/
//------------------------------------------------------------------------------
bool CBcam::CScalarProperty::CBoolControl::operator()()
{
  bool retVal = false;
  ArgGetDCSFeatureCSR arg;
  ZeroMemory(&arg, sizeof(arg));
  arg.FeatId = m_FunctionId;
  ResGetDCSFeatureCSR res;
  m_pBcam->TryTransmit( _T( "CBcam::CScalarProperty::CBoolControl::Operator()()" ),
    IOCTL_BCAM_GET_DCS_FEATURE_CSR, &arg, sizeof(arg), &res, sizeof(res) );
  switch ( m_Mode )
  {
  case mOnOff:
    retVal = res.Scalar.ON_OFF;
    break;
  case mAutoMode:
    retVal = res.Scalar.A_M_Mode;
    break;
  case mAbsControl:
    retVal = res.Scalar.Abs_Control;
    break;
  default:
    assert(false);
  }
  return retVal;
}

///////////////////////////////////////////////////////////////////////////////
// class CBcam::CScalarProperty::CRawRegister

//------------------------------------------------------------------------------
// CBcam::CScalarProperty::CRawRegister::CRawRegister( FunctionCode_t FuncCode, BcamFeatureID FuncId, CBcam* pBcam ): m_pBcam(pBcam),  m_FunctionId( FuncId), m_FunctionCode( FuncCode )
// Author: A. Happe
//------------------------------------------------------------------------------
/**
* \brief Create a raw register object 
*
* for accessing  a DCAM feature (e.g. Brightness)
*
* \param     FuncCode Function code used for asynchronous calls
* \param     FuncId   Feature identifier
* \param     pBcam    Backpointer to the communication object
*/
//------------------------------------------------------------------------------
CBcam::CScalarProperty::CRawRegister::CRawRegister( FunctionCode_t FuncCode, BcamFeatureID FuncId, CBcam* pBcam )
: m_pBcam(pBcam), 
m_FunctionId( FuncId),
m_FunctionCode( FuncCode )
{
  /* NOP */
}

//------------------------------------------------------------------------------
// unsigned long CBcam::CScalarProperty::CRawRegister::Min()
// Author: Hartmut Nebelung
//------------------------------------------------------------------------------
/**
* \brief Get the minimum of a DCAM feature synchronously.
*
* \return    
*
* Returns the minimum value.
* 
* \throw BcamException The value of \c ::GetLastError() is thrown
*
* \b Example
* \code
* unsigned long value;
* value = m_pBcam->Brightness.Raw.Min();
* \endcode

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -