Merged v2 into master

This commit is contained in:
Eugene Wang
2014-06-26 06:45:23 -04:00
6 changed files with 116 additions and 47 deletions

View File

@@ -2056,7 +2056,20 @@ namespace NTwain.Data
Constrainable = 0x40, Constrainable = 0x40,
GetHelp = 0x100, GetHelp = 0x100,
GetLabel = 0x200, GetLabel = 0x200,
GetLabelEnum = 0x400 GetLabelEnum = 0x400,
/// <summary>
/// Cap applies to entire session/machine.
/// </summary>
Machine = 0x1000,
/// <summary>
/// Cap applies to bitonal cameras.
/// </summary>
Bitonal = 0x2000,
/// <summary>
/// Cap applies to color cameras.
/// </summary>
Color = 0x4000
} }
/// <summary> /// <summary>

View File

@@ -70,7 +70,15 @@ namespace NTwain.Internals
if (xferGroup == DataGroups.None || if (xferGroup == DataGroups.None ||
(xferGroup & DataGroups.Image) == DataGroups.Image) (xferGroup & DataGroups.Image) == DataGroups.Image)
{ {
var mech = session.CurrentSource.CapGetCurrent(CapabilityId.ICapXferMech).ConvertToEnum<XferMech>(); // default to memory
var mech = XferMech.Memory;
object mechRaw = session.CurrentSource.CapGetCurrent(CapabilityId.ICapXferMech);
if (mechRaw != null)
{
mech = mechRaw.ConvertToEnum<XferMech>();
}
switch (mech) switch (mech)
{ {
case XferMech.Memory: case XferMech.Memory:
@@ -110,9 +118,13 @@ namespace NTwain.Internals
} while (rc == ReturnCode.Success && pending.Count != 0); } while (rc == ReturnCode.Success && pending.Count != 0);
// some poorly written scanner drivers return failure on EndXfer so also check for pending count now
// this may break with other sources but we'll see
if (pending.Count == 0)
{
session.ChangeState(5, true); session.ChangeState(5, true);
session.DisableSource(); session.DisableSource();
}
} }
#region audio xfers #region audio xfers

View File

@@ -14,6 +14,6 @@ namespace NTwain
// keep this same in majors releases // keep this same in majors releases
public const string Release = "2.0.0.0"; public const string Release = "2.0.0.0";
// change this for each nuget release // change this for each nuget release
public const string Build = "2.0.1"; public const string Build = "2.0.3";
} }
} }

View File

@@ -15,7 +15,7 @@ namespace NTwain.Triplets
/// <returns></returns> /// <returns></returns>
public ReturnCode Get(TWImageMemXfer xfer) public ReturnCode Get(TWImageMemXfer xfer)
{ {
Session.VerifyState(6, 6, DataGroups.Image, DataArgumentType.ImageMemFileXfer, Message.Get); Session.VerifyState(6, 7, DataGroups.Image, DataArgumentType.ImageMemFileXfer, Message.Get);
return Dsm.DsmEntry(Session.AppId, Session.CurrentSource.Identity, Message.Get, xfer); return Dsm.DsmEntry(Session.AppId, Session.CurrentSource.Identity, Message.Get, xfer);
} }

View File

@@ -15,7 +15,7 @@ namespace NTwain
/// <summary> /// <summary>
/// Represents a TWAIN data source. /// Represents a TWAIN data source.
/// </summary> /// </summary>
public partial class TwainSource : INotifyPropertyChanged public partial class TwainSource
{ {
ITwainSessionInternal _session; ITwainSessionInternal _session;
@@ -179,7 +179,7 @@ namespace NTwain
private set private set
{ {
_supportedCaps = value; _supportedCaps = value;
OnPropertyChanged("SupportedCaps"); //OnPropertyChanged("SupportedCaps");
} }
} }
@@ -219,41 +219,82 @@ namespace NTwain
#endregion #endregion
#region INotifyPropertyChanged Members //#region INotifyPropertyChanged Members
///// <summary>
///// Occurs when a property value changes.
///// </summary>
//public event PropertyChangedEventHandler PropertyChanged;
///// <summary>
///// Raises the <see cref="PropertyChanged"/> event.
///// </summary>
///// <param name="propertyName">Name of the property.</param>
//protected void OnPropertyChanged(string propertyName)
//{
// var syncer = _session.SynchronizationContext;
// if (syncer == null)
// {
// try
// {
// var hand = PropertyChanged;
// if (hand != null) { hand(this, new PropertyChangedEventArgs(propertyName)); }
// }
// catch { }
// }
// else
// {
// syncer.Post(o =>
// {
// try
// {
// var hand = PropertyChanged;
// if (hand != null) { hand(this, new PropertyChangedEventArgs(propertyName)); }
// }
// catch { }
// }, null);
// }
//}
//#endregion
#region cameras
/// <summary> /// <summary>
/// Occurs when a property value changes. /// Gets the cameras supported by the source.
/// </summary> /// </summary>
public event PropertyChangedEventHandler PropertyChanged; /// <returns></returns>
public IList<string> GetCameras()
{
TWFileSystem fs = new TWFileSystem();
List<string> cams = new List<string>();
var rc = DGControl.FileSystem.GetFirstFile(fs);
while (rc == ReturnCode.Success)
{
switch (fs.FileType)
{
case FileType.Camera:
case FileType.CameraBottom:
case FileType.CameraTop:
case FileType.CameraPreview:
cams.Add(fs.OutputName);
break;
}
rc = DGControl.FileSystem.GetNextFile(fs);
}
return cams;
}
/// <summary> /// <summary>
/// Raises the <see cref="PropertyChanged"/> event. /// Sets the target camera for cap negotiation that can be set per camera.
/// </summary> /// </summary>
/// <param name="propertyName">Name of the property.</param> /// <param name="cameraName"></param>
protected void OnPropertyChanged(string propertyName) /// <returns></returns>
public ReturnCode SetCamera(string cameraName)
{ {
var syncer = _session.SynchronizationContext; TWFileSystem fs = new TWFileSystem();
if (syncer == null) fs.InputName = cameraName;
{ return DGControl.FileSystem.ChangeDirectory(fs);
try
{
var hand = PropertyChanged;
if (hand != null) { hand(this, new PropertyChangedEventArgs(propertyName)); }
}
catch { }
}
else
{
syncer.Post(o =>
{
try
{
var hand = PropertyChanged;
if (hand != null) { hand(this, new PropertyChangedEventArgs(propertyName)); }
}
catch { }
}, null);
}
} }
#endregion #endregion

View File

@@ -104,6 +104,8 @@ namespace Tester.Winform
} }
private void CleanupTwain() private void CleanupTwain()
{
if (_twain != null)
{ {
if (_twain.State == 4) if (_twain.State == 4)
{ {
@@ -120,6 +122,7 @@ namespace Tester.Winform
_twain.ForceStepDown(2); _twain.ForceStepDown(2);
} }
} }
}
#endregion #endregion