Accessing the Line Scanner in IBM Anyplace Kiosk

The last week I was busy searching a way to access the integrated Line Scanner as found in the IBM Anyplace Kiosks. The biggest hurdle was actually to get the damn thing to work, after reading through various documentation (JavaPOS, OPOS, UnifiedPOS), installing different devices drivers, I finally succeeded with a OPOS based Windows solution. I still try to convince management to deploy a Linux based solution, but do not yet know if there are the needed device drivers available. IBM seems to support it with IRES, we will see.

So the next step was to actually program the scanner in order to receive data. Since our “application” runs within a browser I had to use ActiveX and JScript to access the scanner. During coding this I learned that in order to capture ActiveX Events one has to use a slightly different event handling technique. I eventually got it to work with the code below.

<html>
<head>
<title>Scanner</title>
</head>
<body>
<object classid="clsid:CCB90182-B81E-11D2-AB74-0040054C3719" id="Scanner" width="39" 

height="38">
</object>
<script type="text/jscript" language="JScript">

onload = function(){
    MyScanner = function(){

        var scanner = Scanner;
        var dc = ec = function(){};

        /* see the following msdn-link for further 
         * information on why this strange syntax actually works.
                 *
         * http://msdn2.microsoft.com/en-us/library/ms974564.aspx
         */

        function Scanner::DataEvent(){
            dc(scanner.ScanDataLabel);
            scanner.DataEventEnabled = true;
        }

        function Scanner::ErrorEvent(ResultCode, ResultCodeExtended, 

ErrorLocus, ErrorResponse){
            ec(ResultCode, ResultCodeExtended, ErrorLocus, 

ErrorResponse);
        }

        var open = function(devname){
            if(scanner.Open(devname))
                return false;
            return true;
        }

        var enable = function(devname){
            if(!open(devname))
                return false;
            if(scanner.Claim(1000))
                return false;
        
            scanner.DeviceEnabled = true;
            scanner.DataEventEnabled = true;
            scanner.DecodeData = true;
            return true;
        }

        return {
            init : function(devname,datacb,errorcb){
                if(!enable(devname))
                    return false;
                if(typeof datacb == "function")
                    dc = datacb;
                if(typeof errorcb == "function")
                    ec = datacb;
                return true;
            },
    
            close : function(){
                return !scanner.Close();
            }
        };

    }();


    var status = MyScanner.init("LineScanner",function(v){ 
            alert("scanner " + v) 
        },
        
        function(){
            alert("error");
        }
    );

    if(!status)
        MyScanner.close();
    else
        alert("could init");
}

onunload = function(){
    MyScanner.close();
}

</script>
</body>
</html>

An important point I would like to note is that only one application can access the scanner at the same time. Which means we must always call close to release the internal handle.

Hope this is useful for somebody.

Marc