/// <summary> /// Convert the contents of a capability to a string that we can show in /// our simple GUI... /// </summary> /// <param name="a_twty">Data type</param> /// <param name="a_intptr">Pointer to the data</param> /// <param name="a_iIndex">Index of the item in the data</param> /// <returns>Data in CSV form</returns> public string GetIndexedItem(TWTY a_twty, IntPtr a_intptr, int a_iIndex) { IntPtr intptr; // Index by type... switch (a_twty) { default: return ("Get Capability: (unrecognized item type)..." + a_twty); case TWTY.INT8: { intptr = (IntPtr)((ulong)a_intptr + (ulong)(1 * a_iIndex)); sbyte i8Value = (sbyte)Marshal.PtrToStructure(intptr, typeof(sbyte)); return (i8Value.ToString()); } case TWTY.INT16: { intptr = (IntPtr)((ulong)a_intptr + (ulong)(2 * a_iIndex)); short i16Value = (short)Marshal.PtrToStructure(intptr, typeof(short)); return (i16Value.ToString()); } case TWTY.INT32: { intptr = (IntPtr)((ulong)a_intptr + (ulong)(4 * a_iIndex)); int i32Value = (int)Marshal.PtrToStructure(intptr, typeof(int)); return (i32Value.ToString()); } case TWTY.UINT8: { intptr = (IntPtr)((ulong)a_intptr + (ulong)(1 * a_iIndex)); byte u8Value = (byte)Marshal.PtrToStructure(intptr, typeof(byte)); return (u8Value.ToString()); } case TWTY.BOOL: case TWTY.UINT16: { intptr = (IntPtr)((ulong)a_intptr + (ulong)(2 * a_iIndex)); ushort u16Value = (ushort)Marshal.PtrToStructure(intptr, typeof(ushort)); return (u16Value.ToString()); } case TWTY.UINT32: { intptr = (IntPtr)((ulong)a_intptr + (ulong)(4 * a_iIndex)); uint u32Value = (uint)Marshal.PtrToStructure(intptr, typeof(uint)); return (u32Value.ToString()); } case TWTY.FIX32: { intptr = (IntPtr)((ulong)a_intptr + (ulong)(4 * a_iIndex)); TW_FIX32 twfix32 = (TW_FIX32)Marshal.PtrToStructure(intptr, typeof(TW_FIX32)); return (((double)twfix32.Whole + ((double)twfix32.Frac / 65536.0)).ToString()); } case TWTY.FRAME: { CSV csv = new CSV(); intptr = (IntPtr)((ulong)a_intptr + (ulong)(16 * a_iIndex)); TW_FRAME twframe = (TW_FRAME)Marshal.PtrToStructure(intptr, typeof(TW_FRAME)); csv.Add(((double)twframe.Left.Whole + ((double)twframe.Left.Frac / 65536.0)).ToString()); csv.Add(((double)twframe.Top.Whole + ((double)twframe.Top.Frac / 65536.0)).ToString()); csv.Add(((double)twframe.Right.Whole + ((double)twframe.Right.Frac / 65536.0)).ToString()); csv.Add(((double)twframe.Bottom.Whole + ((double)twframe.Bottom.Frac / 65536.0)).ToString()); return (csv.Get()); } case TWTY.STR32: { intptr = (IntPtr)((ulong)a_intptr + (ulong)(34 * a_iIndex)); TW_STR32 twstr32 = (TW_STR32)Marshal.PtrToStructure(intptr, typeof(TW_STR32)); return (twstr32.Get()); } case TWTY.STR64: { intptr = (IntPtr)((ulong)a_intptr + (ulong)(66 * a_iIndex)); TW_STR64 twstr64 = (TW_STR64)Marshal.PtrToStructure(intptr, typeof(TW_STR64)); return (twstr64.Get()); } case TWTY.STR128: { intptr = (IntPtr)((ulong)a_intptr + (ulong)(130 * a_iIndex)); TW_STR128 twstr128 = (TW_STR128)Marshal.PtrToStructure(intptr, typeof(TW_STR128)); return (twstr128.Get()); } case TWTY.STR255: { intptr = (IntPtr)((ulong)a_intptr + (ulong)(256 * a_iIndex)); TW_STR255 twstr255 = (TW_STR255)Marshal.PtrToStructure(intptr, typeof(TW_STR255)); return (twstr255.Get()); } } }
/// <summary> /// Convert the contents of a transfer group to a string that we can show in /// our simple GUI... /// </summary> /// <param name="a_u32Xfergroup">A TWAIN structure</param> /// <returns>A CSV string of the TWAIN structure</returns> public string XfergroupToCsv(UInt32 a_u32Xfergroup) { try { CSV csv = new CSV(); csv.Add("0x" + a_u32Xfergroup.ToString("X")); return (csv.Get()); } catch { return ("***error***"); } }
/// <summary> /// The common start to every capability csv... /// </summary> /// <param name="a_cap">Capability number</param> /// <param name="a_twon">Container</param> /// <param name="a_twty">Data type</param> /// <returns></returns> private CSV Common(CAP a_cap, TWON a_twon, TWTY a_twty) { CSV csv = new CSV(); // Add the capability... string szCap = a_cap.ToString(); if (!szCap.Contains("_")) { szCap = "0x" + ((ushort)a_cap).ToString("X"); } // Build the CSV... csv.Add(szCap); csv.Add("TWON_" + a_twon); csv.Add("TWTY_" + a_twty); // And return it... return (csv); }
/// <summary> /// Convert the contents of a setup mem xfer structure to a string that /// we can show in our simple GUI... /// </summary> /// <param name="a_twsetupmemxfer">A TWAIN structure</param> /// <returns>A CSV string of the TWAIN structure</returns> public string SetupmemxferToCsv(TW_SETUPMEMXFER a_twsetupmemxfer) { try { CSV csv = new CSV(); csv.Add(a_twsetupmemxfer.MinBufSize.ToString()); csv.Add(a_twsetupmemxfer.MaxBufSize.ToString()); csv.Add(a_twsetupmemxfer.Preferred.ToString()); return (csv.Get()); } catch { return ("***error***"); } }
/// <summary> /// Convert the contents of a userinterface to a string that we can show in /// our simple GUI... /// </summary> /// <param name="a_twuserinterface">A TWAIN structure</param> /// <returns>A CSV string of the TWAIN structure</returns> public string UserinterfaceToCsv(TW_USERINTERFACE a_twuserinterface) { try { CSV csv = new CSV(); csv.Add(a_twuserinterface.ShowUI.ToString()); csv.Add(a_twuserinterface.ModalUI.ToString()); return (csv.Get()); } catch { return ("***error***"); } }
/// <summary> /// Convert the contents of a custom DS data to a string that we can show in /// our simple GUI... /// </summary> /// <param name="a_twcustomdsdata">A TWAIN structure</param> /// <returns>A CSV string of the TWAIN structure</returns> public string CustomdsdataToCsv(TW_CUSTOMDSDATA a_twcustomdsdata) { try { CSV csv = new CSV(); csv.Add(a_twcustomdsdata.InfoLength.ToString()); IntPtr intptr = DsmMemLock(a_twcustomdsdata.hData); csv.Add(intptr.ToString()); DsmMemUnlock(a_twcustomdsdata.hData); return (csv.Get()); } catch { return ("***error***"); } }
/// <summary> /// Convert the contents of a setup file xfer structure to a string that /// we can show in our simple GUI... /// </summary> /// <param name="a_twsetupfilexfer">A TWAIN structure</param> /// <returns>A CSV string of the TWAIN structure</returns> public string SetupfilexferToCsv(TW_SETUPFILEXFER a_twsetupfilexfer) { try { CSV csv = new CSV(); csv.Add(a_twsetupfilexfer.FileName.Get()); csv.Add("TWFF_" + a_twsetupfilexfer.Format); csv.Add(a_twsetupfilexfer.VRefNum.ToString()); return (csv.Get()); } catch { return ("***error***"); } }
/// <summary> /// Convert the contents of a image layout to a string that we can show in /// our simple GUI... /// </summary> /// <param name="a_twimagelayout">A TWAIN structure</param> /// <returns>A CSV string of the TWAIN structure</returns> public string ImagelayoutToCsv(TW_IMAGELAYOUT a_twimagelayout) { try { CSV csv = new CSV(); csv.Add(((double)a_twimagelayout.Frame.Left.Whole + ((double)a_twimagelayout.Frame.Left.Frac / 65536.0)).ToString()); csv.Add(((double)a_twimagelayout.Frame.Top.Whole + ((double)a_twimagelayout.Frame.Top.Frac / 65536.0)).ToString()); csv.Add(((double)a_twimagelayout.Frame.Right.Whole + ((double)a_twimagelayout.Frame.Right.Frac / 65536.0)).ToString()); csv.Add(((double)a_twimagelayout.Frame.Bottom.Whole + ((double)a_twimagelayout.Frame.Bottom.Frac / 65536.0)).ToString()); csv.Add(a_twimagelayout.DocumentNumber.ToString()); csv.Add(a_twimagelayout.PageNumber.ToString()); csv.Add(a_twimagelayout.FrameNumber.ToString()); return (csv.Get()); } catch { return ("***error***"); } }
/// <summary> /// Convert the contents of an image mem xfer structure to a string that /// we can show in our simple GUI... /// </summary> /// <param name="a_twsetupfilexfer">A TWAIN structure</param> /// <returns>A CSV string of the TWAIN structure</returns> public string ImagememferToCsv(TW_IMAGEMEMXFER a_twimagememxfer) { try { CSV csv = new CSV(); csv.Add("TWCP_" + (TWCP)a_twimagememxfer.Compression); csv.Add(a_twimagememxfer.BytesPerRow.ToString()); csv.Add(a_twimagememxfer.Columns.ToString()); csv.Add(a_twimagememxfer.Rows.ToString()); csv.Add(a_twimagememxfer.XOffset.ToString()); csv.Add(a_twimagememxfer.YOffset.ToString()); csv.Add(a_twimagememxfer.BytesWritten.ToString()); csv.Add(a_twimagememxfer.Memory.Flags.ToString()); csv.Add(a_twimagememxfer.Memory.Length.ToString()); csv.Add(a_twimagememxfer.Memory.TheMem.ToString()); return (csv.Get()); } catch { return ("***error***"); } }
/// <summary> /// Convert the contents of an identity to a string that we can show in /// our simple GUI... /// </summary> /// <param name="a_twidentity">A TWAIN structure</param> /// <returns>A CSV string of the TWAIN structure</returns> public string IdentityToCsv(TW_IDENTITY a_twidentity) { try { CSV csv = new CSV(); csv.Add(a_twidentity.Id.ToString()); csv.Add(a_twidentity.Version.MajorNum.ToString()); csv.Add(a_twidentity.Version.MinorNum.ToString()); csv.Add(a_twidentity.Version.Language.ToString()); csv.Add(a_twidentity.Version.Country.ToString()); csv.Add(a_twidentity.Version.Info.Get()); csv.Add(a_twidentity.ProtocolMajor.ToString()); csv.Add(a_twidentity.ProtocolMinor.ToString()); csv.Add("0x" + a_twidentity.SupportedGroups.ToString("X")); csv.Add(a_twidentity.Manufacturer.Get()); csv.Add(a_twidentity.ProductFamily.Get()); csv.Add(a_twidentity.ProductName.Get()); return (csv.Get()); } catch { return ("***error***"); } }
/// <summary> /// Convert the contents of a image info to a string that we can show in /// our simple GUI... /// </summary> /// <param name="a_twimageinfo">A TWAIN structure</param> /// <returns>A CSV string of the TWAIN structure</returns> public string ImageinfoToCsv(TW_IMAGEINFO a_twimageinfo) { try { CSV csv = new CSV(); csv.Add(((double)a_twimageinfo.XResolution.Whole + ((double)a_twimageinfo.XResolution.Frac / 65536.0)).ToString()); csv.Add(((double)a_twimageinfo.YResolution.Whole + ((double)a_twimageinfo.YResolution.Frac / 65536.0)).ToString()); csv.Add(a_twimageinfo.ImageWidth.ToString()); csv.Add(a_twimageinfo.ImageLength.ToString()); csv.Add(a_twimageinfo.SamplesPerPixel.ToString()); csv.Add(a_twimageinfo.BitsPerSample_0.ToString()); csv.Add(a_twimageinfo.BitsPerSample_1.ToString()); csv.Add(a_twimageinfo.BitsPerSample_2.ToString()); csv.Add(a_twimageinfo.BitsPerSample_3.ToString()); csv.Add(a_twimageinfo.BitsPerSample_4.ToString()); csv.Add(a_twimageinfo.BitsPerSample_5.ToString()); csv.Add(a_twimageinfo.BitsPerSample_6.ToString()); csv.Add(a_twimageinfo.BitsPerSample_7.ToString()); csv.Add(a_twimageinfo.Planar.ToString()); csv.Add("TWPT_" + (TWPT)a_twimageinfo.PixelType); csv.Add("TWCP_" + (TWCP)a_twimageinfo.Compression); return (csv.Get()); } catch { return ("***error***"); } }
/// <summary> /// Convert the contents of a filesystem string to a string that we can show in /// our simple GUI... /// </summary> /// <param name="a_twfilesystem">A TWAIN structure</param> /// <returns>A CSV string of the TWAIN structure</returns> public string FilesystemToCsv(TW_FILESYSTEM a_twfilesystem) { try { CSV csv = new CSV(); csv.Add(a_twfilesystem.InputName.Get()); csv.Add(a_twfilesystem.OutputName.Get()); csv.Add(a_twfilesystem.Context.ToString()); csv.Add(a_twfilesystem.Recursive.ToString()); csv.Add(a_twfilesystem.FileType.ToString()); csv.Add(a_twfilesystem.Size.ToString()); csv.Add(a_twfilesystem.CreateTimeDate.Get()); csv.Add(a_twfilesystem.ModifiedTimeDate.Get()); csv.Add(a_twfilesystem.FreeSpace.ToString()); csv.Add(a_twfilesystem.NewImageSize.ToString()); csv.Add(a_twfilesystem.NumberOfFiles.ToString()); csv.Add(a_twfilesystem.NumberOfSnippets.ToString()); csv.Add(a_twfilesystem.DeviceGroupMask.ToString()); return (csv.Get()); } catch { return ("***error***"); } }
/// <summary> /// Convert the contents of an entry point to a string that /// we can show in our simple GUI... /// </summary> /// <param name="a_twentrypoint">A TWAIN structure</param> /// <returns>A CSV string of the TWAIN structure</returns> public string EntrypointToCsv(TW_ENTRYPOINT a_twentrypoint) { try { CSV csv = new CSV(); csv.Add(a_twentrypoint.Size.ToString()); csv.Add("0x" + ((a_twentrypoint.DSM_Entry == null)?"0":a_twentrypoint.DSM_Entry.ToString("X"))); csv.Add("0x" + ((a_twentrypoint.DSM_MemAllocate == null) ? "0" : a_twentrypoint.DSM_MemAllocate.ToString("X"))); csv.Add("0x" + ((a_twentrypoint.DSM_MemFree == null) ? "0" : a_twentrypoint.DSM_MemFree.ToString("X"))); csv.Add("0x" + ((a_twentrypoint.DSM_MemLock == null) ? "0" : a_twentrypoint.DSM_MemLock.ToString("X"))); csv.Add("0x" + ((a_twentrypoint.DSM_MemUnlock == null) ? "0" : a_twentrypoint.DSM_MemUnlock.ToString("X"))); return (csv.Get()); } catch { return ("***error***"); } }
/// <summary> /// Convert the contents of a device event to a string that we can show in /// our simple GUI... /// </summary> /// <param name="a_twdeviceevent">A TWAIN structure</param> /// <returns>A CSV string of the TWAIN structure</returns> public string DeviceeventToCsv(TW_DEVICEEVENT a_twdeviceevent) { try { CSV csv = new CSV(); csv.Add(((TWDE)a_twdeviceevent.Event).ToString()); csv.Add(a_twdeviceevent.DeviceName.Get()); csv.Add(a_twdeviceevent.BatteryMinutes.ToString()); csv.Add(a_twdeviceevent.BatteryPercentage.ToString()); csv.Add(a_twdeviceevent.PowerSupply.ToString()); csv.Add(((double)a_twdeviceevent.XResolution.Whole + ((double)a_twdeviceevent.XResolution.Frac / 65536.0)).ToString()); csv.Add(((double)a_twdeviceevent.YResolution.Whole + ((double)a_twdeviceevent.YResolution.Frac / 65536.0)).ToString()); csv.Add(a_twdeviceevent.FlashUsed2.ToString()); csv.Add(a_twdeviceevent.AutomaticCapture.ToString()); csv.Add(a_twdeviceevent.TimeBeforeFirstCapture.ToString()); csv.Add(a_twdeviceevent.TimeBetweenCaptures.ToString()); return (csv.Get()); } catch { return ("***error***"); } }
/// <summary> /// Convert the contents of a callback2 to a string that we can show in /// our simple GUI... /// </summary> /// <param name="a_twcallback2">A TWAIN structure</param> /// <returns>A CSV string of the TWAIN structure</returns> public string Callback2ToCsv(TW_CALLBACK2 a_twcallback2) { try { CSV csv = new CSV(); csv.Add(a_twcallback2.CallBackProc.ToString()); csv.Add(a_twcallback2.RefCon.ToString()); csv.Add(a_twcallback2.Message.ToString()); return (csv.Get()); } catch { return ("***error***"); } }
/// <summary> /// Convert the contents of a pending xfers structure to a string that /// we can show in our simple GUI... /// </summary> /// <param name="a_twsetupfilexfer">A TWAIN structure</param> /// <returns>A CSV string of the TWAIN structure</returns> public string PendingxfersToCsv(TW_PENDINGXFERS a_twpendingxfers) { try { CSV csv = new CSV(); csv.Add(a_twpendingxfers.Count.ToString()); csv.Add(a_twpendingxfers.EOJ.ToString()); return (csv.Get()); } catch { return ("***error***"); } }
/// <summary> /// Restore a snapshot of driver values... /// </summary> /// <param name="a_szFile">File to use to restore driver settings</param> /// <returns>SUCCESS if the restore succeeded</returns> public STS RestoreSnapshot(string a_szFile) { STS sts; byte[] abSettings; UInt32 u32Length; IntPtr intptrHandle; string szCapability; string szCustomdsdata; string szStatus; CSV csv = new CSV(); // Reset the driver, we don't care if it succeeds or fails... szStatus = ""; szCapability = ""; Send("DG_CONTROL", "DAT_CAPABILITY", "MSG_RESETALL", ref szCapability, ref szStatus); // Get the snapshot from a file... FileStream filestream = null; try { filestream = new FileStream(a_szFile, FileMode.Open); u32Length = (UInt32)filestream.Length; abSettings = new byte[u32Length]; filestream.Read(abSettings, 0, abSettings.Length); } finally { if (filestream != null) { filestream.Dispose(); } } // Put it in an intptr... intptrHandle = Marshal.AllocHGlobal((int)u32Length); Marshal.Copy(abSettings, 0, intptrHandle, (int)u32Length); // Set the snapshot, if possible... szStatus = ""; csv.Add(u32Length.ToString()); csv.Add(intptrHandle.ToString()); szCustomdsdata = csv.Get(); sts = Send("DG_CONTROL", "DAT_CUSTOMDSDATA", "MSG_SET", ref szCustomdsdata, ref szStatus); // Cleanup... Marshal.FreeHGlobal(intptrHandle); // All done... return (sts); }
/// <summary> /// Convert the contents of an entry point to a string that /// we can show in our simple GUI... /// </summary> /// <param name="a_twentrypoint">A TWAIN structure</param> /// <returns>A CSV string of the TWAIN structure</returns> public virtual string EntrypointToCsv(TW_ENTRYPOINT a_twentrypoint) { try { CSV csv = new CSV(); csv.Add(a_twentrypoint.Size.ToString()); csv.Add("0x" + a_twentrypoint.DSM_Entry.ToString("X")); csv.Add("0x" + Marshal.GetFunctionPointerForDelegate(a_twentrypoint.DSM_MemAllocate).ToString("X")); csv.Add("0x" + Marshal.GetFunctionPointerForDelegate(a_twentrypoint.DSM_MemFree).ToString("X")); csv.Add("0x" + Marshal.GetFunctionPointerForDelegate(a_twentrypoint.DSM_MemLock).ToString("X")); csv.Add("0x" + Marshal.GetFunctionPointerForDelegate(a_twentrypoint.DSM_MemUnlock).ToString("X")); return (csv.Get()); } catch { return ("***error***"); } }