public Capability(Capabilities capability, TwainType twainType, Identity applicationId, Identity sourceId) { _capability = capability; _applicationId = applicationId; _sourceId = sourceId; _twainType = twainType; }
public static int SetBasicCapability(Capabilities capability, int rawValue, TwainType twainType, Identity applicationId, Identity sourceId) { var c = new Capability(capability, twainType, applicationId, sourceId); var basicValue = c.GetBasicValue(); // Check that the device supports the capability if (basicValue.ConditionCode != ConditionCode.Success) { throw new TwainException(string.Format("Unsupported capability {0}", capability), basicValue.ErrorCode, basicValue.ConditionCode); } if (basicValue.RawBasicValue == rawValue) { // Value is already set return(rawValue); } // TODO: Check the set of Available Values that are supported by the Source for that // capability. //if (value in set of available values) //{ c.SetValue(rawValue); //} // Verify that the new values have been accepted by the Source. basicValue = c.GetBasicValue(); // Check that the device supports the capability if (basicValue.ConditionCode != ConditionCode.Success) { throw new TwainException(string.Format("Unexpected failure verifying capability {0}", capability), basicValue.ErrorCode, basicValue.ConditionCode); } return(basicValue.RawBasicValue); }
/// <summary> /// Reads a TWAIN value. /// </summary> /// <param name="baseAddress">The base address.</param> /// <param name="offset">The offset.</param> /// <param name="type">The TWAIN type.</param> /// <returns></returns> public static object ReadValue(IntPtr baseAddress, ref int offset, TwainType type) { object val = null; switch (type) { case TwainType.Int8: val = (sbyte)Marshal.ReadByte(baseAddress, offset); break; case TwainType.UInt8: val = Marshal.ReadByte(baseAddress, offset); break; case TwainType.Bool: case TwainType.UInt16: val = (ushort)Marshal.ReadInt16(baseAddress, offset); break; case TwainType.Int16: val = Marshal.ReadInt16(baseAddress, offset); break; case TwainType.UInt32: val = (uint)Marshal.ReadInt32(baseAddress, offset); break; case TwainType.Int32: val = Marshal.ReadInt32(baseAddress, offset); break; case TwainType.Fix32: Fix32 f32 = new Fix32(); f32.Whole = Marshal.ReadInt16(baseAddress, offset); f32.Frac = (ushort)Marshal.ReadInt16(baseAddress, offset + 2); val = f32; break; case TwainType.Frame: Frame frame = new Frame(); frame.Left = (Fix32)ReadValue(baseAddress, ref offset, TwainType.Fix32); frame.Top = (Fix32)ReadValue(baseAddress, ref offset, TwainType.Fix32); frame.Right = (Fix32)ReadValue(baseAddress, ref offset, TwainType.Fix32); frame.Bottom = (Fix32)ReadValue(baseAddress, ref offset, TwainType.Fix32); return(frame); // no need to update offset again after reading fix32 case TwainType.Str128: case TwainType.Str255: case TwainType.Str32: case TwainType.Str64: val = Marshal.PtrToStringAnsi(new IntPtr(baseAddress.ToInt64() + offset)); break; /* case TwainType.Handle: * val = Marshal.ReadIntPtr(baseAddress, offset); * break;*/ } offset += GetItemTypeSize(type); return(val); }
/// <summary> /// Gets the byte size of the item type. /// </summary> /// <param name="type"></param> /// <returns></returns> public static int GetItemTypeSize(TwainType type) { if (__sizes.ContainsKey(type)) { return(__sizes[type]); } return(0); }
/// <summary> /// Gets the byte size of the item type. /// </summary> /// <param name="type"></param> /// <returns></returns> public static int GetItemTypeSize(TwainType type) { if (__sizes.ContainsKey(type)) { return __sizes[type]; } return 0; }
/// <summary> /// Reads a TWAIN value. /// </summary> /// <param name="baseAddress">The base address.</param> /// <param name="offset">The offset.</param> /// <param name="type">The TWAIN type.</param> /// <returns></returns> public static object ReadValue(IntPtr baseAddress, ref int offset, TwainType type) { object val = null; switch (type) { case TwainType.Int8: val = (sbyte)Marshal.ReadByte(baseAddress, offset); break; case TwainType.UInt8: val = Marshal.ReadByte(baseAddress, offset); break; case TwainType.Bool: case TwainType.UInt16: val = (ushort)Marshal.ReadInt16(baseAddress, offset); break; case TwainType.Int16: val = Marshal.ReadInt16(baseAddress, offset); break; case TwainType.UInt32: val = (uint)Marshal.ReadInt32(baseAddress, offset); break; case TwainType.Int32: val = Marshal.ReadInt32(baseAddress, offset); break; case TwainType.Fix32: Fix32 f32 = new Fix32(); f32.Whole = Marshal.ReadInt16(baseAddress, offset); f32.Frac = (ushort)Marshal.ReadInt16(baseAddress, offset + 2); val = f32; break; case TwainType.Frame: Frame frame = new Frame(); frame.Left = (Fix32)ReadValue(baseAddress, ref offset, TwainType.Fix32); frame.Top = (Fix32)ReadValue(baseAddress, ref offset, TwainType.Fix32); frame.Right = (Fix32)ReadValue(baseAddress, ref offset, TwainType.Fix32); frame.Bottom = (Fix32)ReadValue(baseAddress, ref offset, TwainType.Fix32); return frame; // no need to update offset again after reading fix32 case TwainType.Str128: case TwainType.Str255: case TwainType.Str32: case TwainType.Str64: val = Marshal.PtrToStringAnsi(new IntPtr(baseAddress.ToInt64() + offset)); break; /* case TwainType.Handle: val = Marshal.ReadIntPtr(baseAddress, offset); break;*/ } offset += GetItemTypeSize(type); return val; }
public CapabilityOneValue(TwainType twainType, int value) { Value = value; TwainType = twainType; }