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

📄 samplecode.cpp

📁 BCAM 1394 Driver
💻 CPP
📖 第 1 页 / 共 3 页
字号:
      Bcam.Cancel();
      
      // Wait for the cancelled command to arrive at the completion port
      Bcam.WaitForCompletion(&FunctionCode, &ErrorCode, &pContext, 10000); // timeout 10s     
      ATLASSERT(ErrorCode == ERROR_OPERATION_ABORTED);
      
      MessageBox("Trigger did not arrive", _T("OnGrabWithHardwareTrigger"), MB_OK | MB_ICONEXCLAMATION);
    }   
    else 
    {
      ATLASSERT(false);
    }

    Bcam.Trigger.OnOff = false;
    
  } catch( BcamException &e )
  {
    CString Buffer, B;
    Buffer += (B.Format("Exception 0x%X occurred\n", e.Error() ), B);
    Buffer += (B.Format("Message = %s\n", e.Description() ), B);
    Buffer += (B.Format("Context = %s\n", e.Context()), B);
    MessageBox(Buffer, _T("OnGrabWithHardwareTrigger"), MB_OK | MB_ICONEXCLAMATION);
  }
  
  return 0;
}


LRESULT CMainFrame::OnGetInfo(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
  
  // Use exception handling
  try
  {
    // Get the devicename of the first camera
    std::list<CString> DeviceNames = CBcam::DeviceNames();
    if (DeviceNames.size() == 0) return 0;
    CString TheDeviceName = *(DeviceNames.begin());
    
    // Create the driver object and open the driver
    CBcam Bcam;
    Bcam.Open( TheDeviceName );
    
    // Parametrize camera for 640 x 480, Mono8, 7.5 fps
    Bcam.SetVideoMode(DCS_Format0, DCS_Mode5, DCS_7_5fps);
    
    // Allocate Resources (max number of buffers, max buffer size)
    Bcam.AllocateResources(1, 640*480 );
    
    
    // Get Information about the camera 
    CString DeviceName = Bcam.Info.DeviceName();
    CString ModelName = Bcam.Info.ModelName();
    CString VendorName = Bcam.Info.VendorName();
    CString NodeId = Bcam.Info.NodeId();
    
    // Get version information about the camera and the driver
    CString DriverSoftwareVersion = Bcam.Info.DriverSoftwareVersion();
    CString CameraDcamVersion;
    switch (Bcam.Info.CameraDcamVersion())
    {
    case 0x100:
      CameraDcamVersion = "1.04";
      break;
    case 0x101:
      CameraDcamVersion = "1.20";
      break;
    case 0x102:
      CameraDcamVersion = "1.30";
      break;
    default:
      CameraDcamVersion = "Unknown";
    }
    CString CameraFirmwareVersion = Bcam.Info.CameraFirmwareVersion();
    
    // Get information about the current connection to the camera
    // This information changes with AllocateResources!
    long IsoChannel = Bcam.Info.IsoChannel();
    BcamIsoSpeed IsoSpeedEnum = Bcam.Info.IsoSpeed();
    
    
    // Tell the user
    CString IsoSpeed;
    switch(IsoSpeedEnum)
    {
    case IsoSpeed_100:
      IsoSpeed = "S100";
      break;
    case IsoSpeed_200:
      IsoSpeed = "S200";
      break;
    case IsoSpeed_400:
      IsoSpeed = "S400";
      break;
    case IsoSpeed_800:
      IsoSpeed = "S800";
      break;
    case IsoSpeed_1600:
      IsoSpeed = "S1600";
      break;
    case IsoSpeed_3200:
      IsoSpeed = "S3200";
      break;
    case IsoSpeed_Unknown:
      IsoSpeed = "Unknown";
      break;
    default:
      ATLASSERT(false);
    }
    
    CString Buffer, B;
    Buffer += (B.Format("DeviceName            \t= %s\n", DeviceName), B);
    Buffer += (B.Format("ModelName             \t\t= %s\n", ModelName), B);
    Buffer += (B.Format("VendorName            \t= %s\n", VendorName ), B);
    Buffer += (B.Format("NodeId                \t\t= %s\n", NodeId ), B);
    Buffer += (B.Format("\n"), B);
    Buffer += (B.Format("DriverSoftwareVersion \t= %s\n", DriverSoftwareVersion ), B);
    Buffer += (B.Format("CameraDcamVersion     \t= %s\n", CameraDcamVersion ), B);
    Buffer += (B.Format("CameraFirmwareVersion \t= %s\n", CameraFirmwareVersion ), B);
    Buffer += (B.Format("\n"), B);
    Buffer += (B.Format("IsoChannel            \t\t= %ld\n", IsoChannel ), B);
    Buffer += (B.Format("IsoSpeed              \t\t= %s\n", IsoSpeed ), B);
    MessageBox(Buffer, _T("OnGetInfo"), MB_OK | MB_ICONINFORMATION);
    
  } catch( BcamException &e )
  {
    CString Buffer, B;
    Buffer += (B.Format("Exception 0x%X occurred\n", e.Error() ), B);
    Buffer += (B.Format("Message = %s\n", e.Description() ), B);
    Buffer += (B.Format("Context = %s\n", e.Context()), B);
    MessageBox(Buffer, _T("OnGrabSingleImage"), MB_OK | MB_ICONEXCLAMATION);
  }
  
  return 0;
  
}



LRESULT CMainFrame::OnGrabContinuously(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
  
  // Use exception handling
  try
  {
    // Get the devicename of the first camera
    std::list<CString> DeviceNames = CBcam::DeviceNames();
    if (DeviceNames.size() == 0) return 0;
    CString DeviceName = *(DeviceNames.begin());
    ATLTRACE(_T("Devicename = %s\n"), DeviceName);
    
    // Create the driver object and open the driver
    CBcam Bcam;
    Bcam.Open( DeviceName );
    
    // Parameter set for : 640 x 480, Mono8, 7.5 fps
    const DCSVideoFormat VideoFormat = DCS_Format0;
    const DCSVideoMode VideoMode = DCS_Mode5;
    const DCSVideoFrameRate VideoFrameRate = DCS_7_5fps;
    Bcam.SetVideoMode(VideoFormat, VideoMode, VideoFrameRate);
    
    // Create suitable a bitmap
    CSize ImageSize = BcamUtility::ImageSize(VideoFormat, VideoMode);
    CDibPtr ptrDib;
    ptrDib.Create( ImageSize, 8, CDib::TopDown, CDib::Monochrome );
    
    // Get a pointer to the image buffer
    char *pBuffer = (char*)ptrDib->GetPixels();
    
    // Allocate Resources (max num buffers, MaxImageSize
    Bcam.AllocateResources(1, ImageSize.cx * ImageSize.cy);
    
    Bcam.ContinuousShot = true;
    
    Bcam.GrabImageAsync(pBuffer, ImageSize.cx * ImageSize.cy, (void*)pBuffer, false);
    for( int i=0; i<10; i++)
    { 
      unsigned long ErrorCode;
      FunctionCode_t FunctionCode;
      void *pContext;
      
      Bcam.WaitForCompletion(&FunctionCode, &ErrorCode, &pContext, 3000);
      if (ErrorCode)
        throw BcamException( ErrorCode );
      if (FunctionCode == AsyncGrabImage)
        Bcam.GrabImageAsync(pContext, ImageSize.cx * ImageSize.cy, pContext, false);
    }
    
    // Turn continuous shot off
    Bcam.ContinuousShot = false;
    
    Bcam.Cancel();
    
    // Show the image
    m_view.SetBitmap( ptrDib );
    
  } catch( BcamException &e )
  {
    CString Buffer, B;
    Buffer += (B.Format("Exception 0x%X occurred\n", e.Error() ), B);
    Buffer += (B.Format("Message = %s\n", e.Description() ), B);
    Buffer += (B.Format("Context = %s\n", e.Context()), B);
    MessageBox(Buffer, _T("OnGrabContinously"), MB_OK | MB_ICONEXCLAMATION);
  }
  
  return 0;
}


LRESULT CMainFrame::OnSaveMemoryChannel(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
  /**** Simple ***/
  {
     // Get the devicename of the first camera
    std::list<CString> DeviceNames = CBcam::DeviceNames();
    if (DeviceNames.empty())
      return 0L;
    const CString DeviceName = *(DeviceNames.begin());
   
    // Create the device object and open it
    CBcam Bcam;
    Bcam.Open( DeviceName );

	  // Query the number of available Memory Channels.
    const unsigned long nMemoryChannels = Bcam.MemoryChannels.Count();
    if (0 == nMemoryChannels)
    {
      // Memory channels are not supported by the connected camera at all.
      assert( !Bcam.MemoryChannels.IsSupported() );
      return 0L;
    }
    // Memory Channels 0..nMemoryChannels-1 are available.
    // Channel number 0 is reserved for the factory settings and must not be saved.

    // Query the current Memory Channel. Note that its number only reflects 
    // the fact that the most recently load operation was performed from this 
    // Memory Channel. In particular single CSRs could been canged meanwhile. 
    // In other words current Memory Channel == i doesn't mean that all 
    // CSRs have the value loaded from the Memory Channel i currently.
    // (Regarding only the CSRs contained in the set to persist in Memory 
    // Channels as a matter of course. This may vary between different camera 
    // models.)
    const unsigned long iCurrentMemoryChannel = Bcam.MemoryChannels.Current();

    // Save the current settings to the memory channel with the highest 
    // available index number.
    Bcam.MemoryChannels[ nMemoryChannels - 1 ].Save();

    // Reload the factory settings.
    Bcam.MemoryChannels[ 0 ].Load();
  } 

  /**** Elaborate ***/
  try
  {
     // Get the devicename of the first camera
    std::list<CString> DeviceNames = CBcam::DeviceNames();
    if (DeviceNames.empty())
      return 0L;
   
    // Create the device object and open it
    CBcam Bcam;
    Bcam.Open( *DeviceNames.begin() );

	  // Query the number of available Memory Channels.
    const unsigned long nMemoryChannels = Bcam.MemoryChannels.Count();
    if (0 == nMemoryChannels)
    {
      // Memory channels are not supported by the connected camera at all.
      assert( !Bcam.MemoryChannels.IsSupported() );
      MessageBox(
        _T("Memory Channels aren't supported by camera"),
        _T("OnSaveMemoryChannel"),
        MB_OK | MB_ICONINFORMATION);
      return 0L;
    }

    // query current Memory Channel
    {
      unsigned long iCurrentMemoryChannel = Bcam.MemoryChannels.Current();
      CString strBuffer;
      strBuffer.Format(
        _T("Current Memory Channel is %lu of %lu Memory Channels"), 
        iCurrentMemoryChannel,
        nMemoryChannels );
      MessageBox(
        strBuffer,
        _T("OnSaveMemoryChannel"),
        MB_OK | MB_ICONINFORMATION);
    }

    // Save the current settings to the memory channel with the highest 
    // available index number.
    Bcam.MemoryChannels[ nMemoryChannels - 1 ].Save();

    // activate the currently saved memory channel
    Bcam.MemoryChannels[ nMemoryChannels - 1 ].Load();

    // re- query the current Memory Channel
    {
      const unsigned long iCurrentMemoryChannel = Bcam.MemoryChannels.Current();
      CString strBuffer;
      strBuffer.Format(
        _T("Now current Memory Channel is %lu of %lu Memory Channels"), 
        iCurrentMemoryChannel,
        nMemoryChannels );
      MessageBox(
        strBuffer,
        _T("OnSaveMemoryChannel"),
        MB_OK | MB_ICONINFORMATION);
    }


    // Reload the factory settings.
    Bcam.MemoryChannels[ 0 ].Load();
  } 
  catch( BcamException &e )
  {
    CString Buffer, B;
    Buffer += (B.Format("Exception 0x%X occurred\n", e.Error() ), B);
    Buffer += (B.Format("Message = %s\n", e.Description() ), B);
    Buffer += (B.Format("Context = %s\n", e.Context()), B);
    MessageBox(Buffer, _T("OnSaveMemoryChannel"), MB_OK | MB_ICONEXCLAMATION);
  }

  return 0L;
}

⌨️ 快捷键说明

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