TWAIN Working Group

Newsletter Signup
Donate
Help keep TWAIN free
  • About TWAIN
    • What’s New?
    • News
    • Events
    • Membership
    • Consider a Donation
    • Contact Us
  • Why TWAIN?
  • Developers
    • Driver Developer
    • Application Developer
    • TWAIN Features
    • Specification & Tools
    • Self Certification Process
  • Support Forums
  • Scanner End-User
  • Find Certified Drivers
    • Facebook
    • LinkedIn
    • Vimeo

Get and Set Resolutions

Forums › TWAIN Classic › Get and Set Resolutions

  • This topic has 6 replies, 5 voices, and was last updated 5 years, 7 months ago by peterlee.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • December 9, 2011 at 2:53 pm #22721 Reply
    Anonymous
    Participant
    • Topics - 60
    • Replies - 107
    • Total Posts - 167

    Hi,

    I’m trying to set the datasources possible resolutions to 200, 300, or 600. We have our own barcode decoding logic, and those are the only resolutions it supports.

    Currently we check the resolution via the imageinfo after the TransferReady message comes through. If the resolution isn’t supported we tell the user to pick out of our supported list. We haven’t been able to cleanly return to the DataSource UI after the transfer ready message comes in.

    To fix this, I thought it would be nice to limit the resolutions shown on the DS UI. When I try to get the resoluion I end up with an array with a couple valid DPI numbers interleaved with 0s and then some off the wall numbers. I’ve attempted to change the Units to each possible and I’m still unable to receive a clean array of possible resolutions.

    What could I be doing wrong?

    Vb.Net
    Enum class


    _
    Friend Class Tw_Enum
    Public ItemType As Short
    Public NumItem As Short
    Public CurrentIndex As Short
    Public DefaultIndex As Short
    Public ItemList() As Short
    End Class

    Capability Class


    _
    Friend Class TwCapabilityEnum
    Public Cap As Short
    Public ConType As Short
    Public Handle As IntPtr

    Public Sub TwCapability(ByVal capIn As TwCap)
    Cap = CType(capIn, Short)
    ConType = -1
    End Sub

    Public Sub New(ByVal capIn As TwCap, ByVal sval As Short)
    Cap = CType(capIn, Short)
    ConType = CType(TwOn.Enum, UShort)
    Handle = Win32.GlobalAlloc(&H42, 6)
    Dim pv As IntPtr = Win32.GlobalLock(Handle)
    Marshal.WriteInt16(pv, 0, CType(TwType.Fix32, Short))
    Marshal.WriteInt32(pv, 2, CType(sval, Integer))
    Win32.GlobalUnlock(Handle)
    End Sub

    Public Sub Dispose()
    If Not Equals(Handle, IntPtr.Zero) Then
    Win32.GlobalFree(Handle)
    End If
    End Sub

    Protected Overrides Sub Finalize()
    If Not Equals(Handle, IntPtr.Zero) Then
    Win32.GlobalFree(Handle)
    End If
    End Sub
    End Class

    Get Resolution Capability (returncode is success):


    p_oCapEnum = New TwCapabilityEnum(TwCap.IXNativeRes, 0)
    rcResult = DScap(p_oApp, p_oDataSource, TwDG.Control, TwDAT.Capability, TwMSG.Get, p_oCapEnum)

    Reading of Cap Enum:


    Dim twResolutions As Tw_Enum
    Dim pPointerToStructure As IntPtr

    If p_rcLastResult = TwRC.Success Then
    twResolutions = New Tw_Enum
    pPointerToStructure = GlobalLock(p_oCapEnum.Handle)
    Marshal.PtrToStructure(pPointerToStructure, twResolutions)
    End If

    twResolutions.Item contains several numbers that don’t seem like valid resolutions no matter what Unit is set at.

    DSEntry:


    _
    Friend Shared Function DScap( _
    <[In](), Out()> ByVal origin As TwIdentity, _
    <[In]()> ByVal dest As TwIdentity, ByVal dg As TwDG, _
    ByVal dat As TwDAT, _
    ByVal msg As TwMSG, <[In](), Out()> ByVal capa As TwCapabilityEnum) As TwRC
    End Function

    I know the post was code heavy, but I’ve hit a wall. I’m not sure where to go from here. Any information is greatly appreciated.

    Side note:

    I’ve downloaded Twacker32 and sent the message to get the XRes Capabilities in an enum container, the result was a nice: 150, 200, 300, 600 … When I attempted to set the Xres Capability using twacker and an enum container I wasn’t able to change the values. I’d set the number of items to 3 and 3 0s would populate in the list and I couldn’t edit them.

    December 10, 2011 at 6:41 pm #25509 Reply
    Amil
    Participant
    • Topics - 0
    • Replies - 6
    • Total Posts - 6

    Hi,

    From what you wrote, I believe you are checking the resolution in state 6.
    Why don’t you just check the current resolution in state 4 using ICAP_XRESOLUTION/ICAP_YRESOLUTION?
    Then you can restrict the DS to use only 200, 300, or 600 dpi and display the UI if the current resolution is not supported by your application.

    I think the problem might be that you are trying to change capabilities while in state 6 which is not allowed.

    By the way, which scanner are you using?

    December 15, 2011 at 8:36 pm #25510 Reply
    peterp
    Participant
    • Topics - 0
    • Replies - 30
    • Total Posts - 30

    I apologize, but I accidently deleted Rogers account while trying to clean up the SPAM.

    Roger, please register again. Sorry for the inconvenience.

    August 3, 2012 at 8:26 pm #25511 Reply
    si_ben
    Participant
    • Topics - 7
    • Replies - 22
    • Total Posts - 29

    Dim twResolutions As Tw_Enum
    Dim pPointerToStructure As IntPtr

    If p_rcLastResult = TwRC.Success Then
    twResolutions = New Tw_Enum
    pPointerToStructure = GlobalLock(p_oCapEnum.Handle)
    Marshal.PtrToStructure(pPointerToStructure, twResolutions)
    End If
    _________________________________________________________
    I dont think that this is going to work. When i tried it like this i got some
    wierd numbers in my structure. I had to code it like this to get it to work ::
    _________________________________________________________

    Dim twResolutions As Tw_Enum
    If p_rcLastResult = TwRC.Success Then
    twResolutions = Marshal.PtrToStructure(GlobalLock(p_oCapEnum.Handle), GetType(Tw_Enum))
    End If

    That should give you your values successfully..
    I tried it your way, and for some reason when you Lock the Handle outside of that call, the Memory location becomes LOCKED so you cannot access Protected Memory. Your PtrToStructure shouldn’t work.

    August 3, 2012 at 9:19 pm #25512 Reply
    Amil
    Participant
    • Topics - 0
    • Replies - 6
    • Total Posts - 6

    Ah. Well, rogers, may not be around anymore to see your solution, but hopefully it will help future searchers.

    —
    Software consulting

    August 3, 2012 at 9:21 pm #25513 Reply
    si_ben
    Participant
    • Topics - 7
    • Replies - 22
    • Total Posts - 29

    Lol ya I noticed after I posted, He was one of the few I see trying in VB as well. Now I may never know if that would solve the problem but… I think it will 😉

    June 18, 2015 at 9:34 am #25514 Reply
    peterlee
    Participant
    • Topics - 0
    • Replies - 24
    • Total Posts - 24

    @Roger Holland wrote:

    Hi,

    I’m trying to set the datasources possible resolutions to 200, 300, or 600. We have our own barcode decoding logic, and those are the only resolutions it supports.

    Currently we check the resolution via the imageinfo after the TransferReady message comes through. If the resolution isn’t supported we tell the user to pick out of our supported list. We haven’t been able to cleanly return to the DataSource UI after the transfer ready message comes in.

    To fix this, I thought it would be nice to limit the resolutions shown on the DS UI. When I try to get the resoluion I end up with an array with a couple valid DPI numbers interleaved with 0s and then some off the wall numbers. I’ve attempted to change the Units to each possible and I’m still unable to receive a clean array of possible resolutions.

    What could I be doing wrong?

    Vb.Net
    Enum class


    _
    Friend Class Tw_Enum
    Public ItemType As Short
    Public NumItem As Short
    Public CurrentIndex As Short
    Public DefaultIndex As Short
    Public ItemList() As Short
    End Class

    Capability Class


    _
    Friend Class TwCapabilityEnum
    Public Cap As Short
    Public ConType As Short
    Public Handle As IntPtr

    Public Sub TwCapability(ByVal capIn As TwCap)
    Cap = CType(capIn, Short)
    ConType = -1
    End Sub

    Public Sub New(ByVal capIn As TwCap, ByVal sval As Short)
    Cap = CType(capIn, Short)
    ConType = CType(TwOn.Enum, UShort)
    Handle = Win32.GlobalAlloc(&H42, 6)
    Dim pv As IntPtr = Win32.GlobalLock(Handle)
    Marshal.WriteInt16(pv, 0, CType(TwType.Fix32, Short))
    Marshal.WriteInt32(pv, 2, CType(sval, Integer))
    Win32.GlobalUnlock(Handle)
    End Sub

    Public Sub Dispose()
    If Not Equals(Handle, IntPtr.Zero) Then
    Win32.GlobalFree(Handle)
    End If
    End Sub

    Protected Overrides Sub Finalize()
    If Not Equals(Handle, IntPtr.Zero) Then
    Win32.GlobalFree(Handle)
    End If
    End Sub
    End Class

    Get Resolution Capability (returncode is success):


    p_oCapEnum = New TwCapabilityEnum(TwCap.IXNativeRes, 0)
    rcResult = DScap(p_oApp, p_oDataSource, TwDG.Control, TwDAT.Capability, TwMSG.Get, p_oCapEnum)

    Reading of Cap Enum:


    Dim twResolutions As Tw_Enum
    Dim pPointerToStructure As IntPtr

    If p_rcLastResult = TwRC.Success Then
    twResolutions = New Tw_Enum
    pPointerToStructure = GlobalLock(p_oCapEnum.Handle)
    Marshal.PtrToStructure(pPointerToStructure, twResolutions)
    End If

    twResolutions.Item contains several numbers that don’t seem like valid resolutions no matter what Unit is set at.

    DSEntry:


    _
    Friend Shared Function DScap( _
    <[In](), Out()> ByVal origin As TwIdentity, _
    <[In]()> ByVal dest As TwIdentity, ByVal dg As TwDG, _
    ByVal dat As TwDAT, _
    ByVal msg As TwMSG, <[In](), Out()> ByVal capa As TwCapabilityEnum) As TwRC
    End Function

    I know the post was code heavy, but I’ve hit a wall. I’m not sure where to go from here. Any information is greatly appreciated.

    Side note:

    I’ve downloaded Twacker32 and sent the message to get the XRes Capabilities in an enum container, the result was a nice: 150, 200, 300, 600 … When I attempted to set the Xres Capability using twacker and an enum container I wasn’t able to change the values. I’d set the number of items to 3 and 3 0s would populate in the list and I couldn’t edit them.

    I wonder whether it supports a 3rd party barcode reading toolkits as well?

    Best regards,
    Arron

  • Author
    Posts
Viewing 7 posts - 1 through 7 (of 7 total)
Reply To: Get and Set Resolutions
Your information:




Quick Links

Service Providers
TWAIN Support Forums
Membership
Contact Us
Privacy Policy

Newsletter Signup

TWAIN Working Group Family

TWAIN Working Group
TWAIN Direct®
TWAIN Resources
TWAIN Certified Drivers
PDF/raster

  • Facebook
  • GitHub
  • LinkedIn
  • Vimeo

Recent Topics

  • EPSON V600 TWAIN and WIA on Windows 10
  • When and how to use WaitForEvents command ?
  • Problem enumerating list of installed scanners in windows server 2012
  • Failed to create TWAIN progress! Error code is 1260.
  • To get the list of scanners from javascript client side (browser)
  • Quarterly Newsletter
  • TWAIN Working Group Membership
  • Logo Usage
  • TWAIN License
  • Contact Us
Privacy Policy • Privacy Tools • Copyright © 2021 TWAIN Working Group • by iHwy, LLC • Log in

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.