简体   繁体   中英

How can I get MICR string from scanner by using TWAIN driver

I am writting some c# code for extract MICR string from checks.

My scanner is Cannon DR-850M which support MICR reader.

It can read MICR string on it's own scanning program. But I need to make my own by using TWAIN.

I can scan images in my program with TWAIN driver. However, I couldn't find how to get MICR string.

Is there a function to access scanner's MICR reader in TWAIN? or anything else?


I found that MICR data were located in "Extended Image Info". Thanks for answering.

and I got a little more problem.

Here's my code.

// Twain DLL Wrapper
[StructLayout(LayoutKind.Sequential, Pack = 2)]
internal class TwInfo
{                                   // TW_INFO
    public short InfoID;
    public short ItemType;
    public short NumItems;
    public short CondCode;
    public int Item;
}

[StructLayout(LayoutKind.Sequential, Pack = 2)]
internal class TwExtImageInfo
{                                   // TW_EXTIMAGEINFO
    public int NumInfos;
    [MarshalAs(UnmanagedType.Struct, SizeConst = 1)]
    public TwInfo Info;
}

//Application
public void GetExtendedImageInfo()
    {
        TwRC rc;
        TwExtImageInfo exinf = new TwExtImageInfo();

        exinf.NumInfos = 1;
        exinf.Info = new TwInfo();
        exinf.Info.InfoID = (short)TwEI.BARCODETEXT;

        rc = DSexfer(appid, srcds, TwDG.Image, TwDAT.ExtImageInfo, TwMSG.Get, exinf);

        // Here's What I want to know.
        IntPtr itemPtr = new IntPtr(exinf.Info.Item);  
        string str = Marshal.PtrToStringAnsi(itemPtr); // It returns weird value.
    }

// Here's result
exinf.Info.CondCode : 0 (short)
exinf.Info.InfoID   : 4610 (short)
exinf.Info.Item : 36962876 (int)  // what's that?
exinf.Info.ItemType : 12 (short)
exinf.Info.NumItems : 4 (short)
exinf.NumInfos      : 1 (int)

I got these values from TWAIN.

But I don't know what kind of value exinf.Info.Item is

In sample App, It show right MICR characters. But my own returns strange value.

Can I get some help?


SOLVED

I just missed using GlobalLock for pointer.

Here's code.

public string GetExtendedImageInfo()
    {
        TwRC rc;
        TwExtImageInfo exinf = new TwExtImageInfo();

        exinf.NumInfos = 1;
        exinf.Info = new TwInfo();
        exinf.Info.InfoID = (short)TwEI.BARCODETEXT;

        rc = DSexfer(appid, srcds, TwDG.Image, TwDAT.ExtImageInfo, TwMSG.Get, exinf);

        StringBuilder strItem = new StringBuilder(255);
        IntPtr itemPtr = new IntPtr(exinf.Info.Item);
        IntPtr dataPtr = GlobalLock(itemPtr);
        string str = Marshal.PtrToStringAnsi(dataPtr);
        GlobalUnlock(itemPtr);
        GlobalFree(itemPtr);

        return str;
    }

You can use TWAIN sample app to connect to your Cannon scanner, locate the custom capability for MICR and use the capability to access the MICR feature.

This article might help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM