Merged v2 into master

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

View File

@ -2056,7 +2056,20 @@ namespace NTwain.Data
Constrainable = 0x40,
GetHelp = 0x100,
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>

View File

@ -70,7 +70,15 @@ namespace NTwain.Internals
if (xferGroup == DataGroups.None ||
(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)
{
case XferMech.Memory:
@ -110,9 +118,13 @@ namespace NTwain.Internals
} while (rc == ReturnCode.Success && pending.Count != 0);
session.ChangeState(5, true);
session.DisableSource();
// 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.DisableSource();
}
}
#region audio xfers

View File

@ -14,6 +14,6 @@ namespace NTwain
// keep this same in majors releases
public const string Release = "2.0.0.0";
// 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>
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);
}

View File

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

View File

@ -105,19 +105,22 @@ namespace Tester.Winform
private void CleanupTwain()
{
if (_twain.State == 4)
if (_twain != null)
{
_twain.CurrentSource.Close();
}
if (_twain.State == 3)
{
_twain.Close();
}
if (_twain.State == 4)
{
_twain.CurrentSource.Close();
}
if (_twain.State == 3)
{
_twain.Close();
}
if (_twain.State > 2)
{
// normal close down didn't work, do hard kill
_twain.ForceStepDown(2);
if (_twain.State > 2)
{
// normal close down didn't work, do hard kill
_twain.ForceStepDown(2);
}
}
}