Added basic device event handling.

This commit is contained in:
Eugene Wang
2018-11-15 19:25:18 -05:00
parent bd3d70c991
commit 0808270d1a
5 changed files with 73 additions and 1 deletions

View File

@@ -0,0 +1,17 @@
using NTwain.Data;
using System;
namespace NTwain
{
/// <summary>
/// Contains data for a TWAIN source event.
/// </summary>
public class DeviceEventArgs : EventArgs
{
/// <summary>
/// Gets the detailed device event.
/// </summary>
/// <value>The device event.</value>
public TW_DEVICEEVENT Data { get; internal set; }
}
}

View File

@@ -0,0 +1,16 @@
using NTwain.Data;
using NTwain.Internals;
namespace NTwain.Triplets
{
sealed class DeviceEvent : BaseTriplet
{
internal DeviceEvent(TwainSession session) : base(session) { }
public ReturnCode Get(ref TW_DEVICEEVENT sourceDeviceEvent)
{
return NativeMethods.DsmWin32(Session.Config.AppWin32, Session.CurrentSource.Identity,
DataGroups.Control, DataArgumentType.DeviceEvent, Message.Get, ref sourceDeviceEvent);
}
}
}

View File

@@ -30,5 +30,8 @@ namespace NTwain.Triplets
Status _status;
internal Status Status => _status ?? (_status = new Status(Session));
DeviceEvent _devEvent;
internal DeviceEvent DeviceEvent => _devEvent ?? (_devEvent = new DeviceEvent(Session));
}
}

View File

@@ -15,7 +15,23 @@ namespace NTwain
{
private void HandleSourceMsg(Message msg)
{
switch (msg)
{
case Message.DeviceEvent:
TW_DEVICEEVENT de = default;
var rc = DGControl.DeviceEvent.Get(ref de);
if (rc == ReturnCode.Success)
{
OnDeviceEvent(new DeviceEventArgs { Data = de });
}
break;
case Message.XferReady:
break;
case Message.CloseDSReq:
break;
case Message.CloseDSOK:
break;
}
}
}
}

View File

@@ -48,6 +48,26 @@ namespace NTwain
public DGCustom DGCustom { get; set; }
/// <summary>
/// Occurs when the source has generated an event.
/// </summary>
public event EventHandler<DeviceEventArgs> DeviceEvent;
/// <summary>
/// Raises the <see cref="DeviceEvent"/> event.
/// </summary>
/// <param name="e"></param>
protected virtual void OnDeviceEvent(DeviceEventArgs e)
{
OnDeviceEvent(e);
DeviceEvent?.Invoke(this, e);
}
/// <summary>
/// Occurs when a property value changes.
/// </summary>