Leadtools TWAIN (Leadtools.Twain assembly) Send comments on this topic. | Back to Introduction - All Topics | Help Version 17.0.3.30
GetDeviceEventCapability Method
See Also 
Leadtools.Twain Namespace > TwainSession Class : GetDeviceEventCapability Method



Gets device events capability values for current TWAIN session.

Syntax

Visual Basic (Declaration) 
Public Function GetDeviceEventCapability() As TwainCapability
Visual Basic (Usage)Copy Code
Dim instance As TwainSession
Dim value As TwainCapability
 
value = instance.GetDeviceEventCapability()
C# 
public TwainCapability GetDeviceEventCapability()
C++/CLI 
public:
TwainCapability^ GetDeviceEventCapability(); 

Return Value

A TwainCapability object that represents CAP_DEVICEEVENT capability values

Example

Visual BasicCopy Code
Public Sub GetDeviceEventCapabilityExample(ByVal parent As IWin32Window)
   Dim session As TwainSession = New TwainSession()
   session.Startup(parent, "manufacturer", "productFamily", "version", "application", TwainStartupFlags.None)

   Try
      Dim twnCap As TwainCapability = session.GetDeviceEventCapability()
      If twnCap.Information.Type = TwainCapabilityType.DeviceEvent Then
         Dim count As Integer = twnCap.ArrayCapability.Count
         Dim i As Integer

         For i = 0 To count - 1
            Dim capValue As TwainCapabilityValue = CType(twnCap.ArrayCapability.GetValue(i), TwainCapabilityValue)
            Select Case capValue
               Case TwainCapabilityValue.DeviceEventCheckBattery
                  MessageBox.Show("Device event checks the battery")
               Case TwainCapabilityValue.DeviceEventCheckResolution
                  MessageBox.Show("Device event checks the resolution")
               Case TwainCapabilityValue.DeviceEventDeviceReady
                  MessageBox.Show("Device event is ready")
            End Select
         Next

         Dim cap As TwainCapability = New TwainCapability()
         cap.Information.Type = TwainCapabilityType.DeviceEvent
         cap.Information.ContainerType = TwainContainerType.Array

         cap.ArrayCapability.Count = 5
         cap.ArrayCapability.ItemType = TwainItemType.Uint16
         cap.ArrayCapability.SetValue(0, TwainCapabilityValue.DeviceEventDeviceReady)
         cap.ArrayCapability.SetValue(1, TwainCapabilityValue.DeviceEventCheckDeviceOnline)
         cap.ArrayCapability.SetValue(2, TwainCapabilityValue.DeviceEventCheckBattery)
         cap.ArrayCapability.SetValue(3, TwainCapabilityValue.DeviceEventCheckPowerSupply)
         cap.ArrayCapability.SetValue(4, TwainCapabilityValue.DeviceEventCheckResolution)

         session.SetDeviceEventCapability(cap)
         MessageBox.Show("DeviceEvent is changed successfully")
         session.ResetDeviceEventCapability(twnCap)
         MessageBox.Show("DeviceEvent is reset to default values successfully")
      End If
   Catch
   End Try
   session.Shutdown()
End Sub
C#Copy Code
public void GetDeviceEventCapabilityExample(IWin32Window parent)
{
   TwainSession session = new TwainSession();
   session.Startup(parent, "manufacturer", "productFamily", "version", "application", TwainStartupFlags.None);

   try
   {
      TwainCapability twnCap = session.GetDeviceEventCapability();
      if (twnCap.Information.Type == TwainCapabilityType.DeviceEvent)
      {
         int count = twnCap.ArrayCapability.Count;
         for (int i = 0; i < count; i++)
         {
            TwainCapabilityValue capValue = (TwainCapabilityValue)twnCap.ArrayCapability.GetValue(i);
            switch (capValue)
            {
               case TwainCapabilityValue.DeviceEventCheckBattery:
                  MessageBox.Show("Device event checks the battery");
                  break;
               case TwainCapabilityValue.DeviceEventCheckResolution:
                  MessageBox.Show("Device event checks the resolution");
                  break;
               case TwainCapabilityValue.DeviceEventDeviceReady:
                  MessageBox.Show("Device event is ready");
                  break;
            }
         }

         TwainCapability cap = new TwainCapability();
         cap.Information.Type = TwainCapabilityType.DeviceEvent;
         cap.Information.ContainerType = TwainContainerType.Array;

         cap.ArrayCapability.Count = 5;
         cap.ArrayCapability.ItemType = TwainItemType.Uint16;
         cap.ArrayCapability.SetValue(0, TwainCapabilityValue.DeviceEventDeviceReady);
         cap.ArrayCapability.SetValue(1, TwainCapabilityValue.DeviceEventCheckDeviceOnline);
         cap.ArrayCapability.SetValue(2, TwainCapabilityValue.DeviceEventCheckBattery);
         cap.ArrayCapability.SetValue(3, TwainCapabilityValue.DeviceEventCheckPowerSupply);
         cap.ArrayCapability.SetValue(4, TwainCapabilityValue.DeviceEventCheckResolution);

         session.SetDeviceEventCapability(cap);
         MessageBox.Show("DeviceEvent is changed successfully");
         session.ResetDeviceEventCapability(twnCap);
         MessageBox.Show("DeviceEvent is reset to default values successfully");
      }
   }
   catch
   { }

   session.Shutdown();
}

Remarks

Call this function to get CAP_DEVICEEVENT capability values. To set CAP_DEVICEEVENT capability, you can call SetDeviceEventCapability method, also to rest CAP_DEVICEEVENT capability to default values, call ResetDeviceEventCapability method.

To get status for each device event, set EnableGetDeviceEvent to TRUE. Also, to get information for device event, call GetDeviceEventData method.

Requirements

Target Platforms: Microsoft .NET Framework 2.0, Windows 2000, Windows XP, Windows Server 2003 family, Windows Server 2008 family, Windows Vista, Windows 7

See Also