Click here to Skip to main content
15,867,568 members
Articles / All Topics

OPOS (OLE for Retail POS) with JavaScript

Rate me:
Please Sign up or sign in to vote.
5.00/5 (3 votes)
1 Nov 2015CPOL2 min read 12.6K   1   1
OPOS (OLE for retail POS) with JavaScript

This article may contain live JavaScript that has been reviewed and tested for security. If you wish to submit articles containing JavaScript please email your submissions to submit@codeproject.com.

The following simple JavaScript / HTML document demonstrates the fundamentals of establishing connectivity with the selected POS hardware device, through device dependent OPOS service object adhering to the UnifiedPOS device management architecture and specification.

The detailed UnifiedPOS Retail Peripheral Architecture specification is available here.

This example uses a Magnetic Stripe Reader (MSR) as the hardware unit to demonstrate the basic device initialization process.

  1. Open: Opens a selected device for subsequent input / output operations
  2. Claim: Requests exclusive access to the device
  3. Enable Device: Bring the device to an operational state
  4. Enable Data Events: Enable delivery of notifications when input data is available. The application should subscribe to notification events by registering a Data Event handler.
  5. Release: Releases exclusive access to the device
  6. Close: Release the device and allocated resources
HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>POS Test Application</title>

<script type="text/javascript">
    //OPOS Data Event handler function
    function onDataEvent(status) {
        //Retrieve and demonstrate available MSR track data.
        document.getElementById("track1").innerHTML = OPOSMsr.Track1Data;
        document.getElementById("track2").innerHTML = OPOSMsr.Track2Data;
        document.getElementById("track3").innerHTML = OPOSMsr.Track3Data;
    }

    function onOpenClick() {
        //Subscribe for UPOS Data Events
        OPOSMsr.attachEvent('data event', onDataEvent);

        var result = OPOSMsr.Open("MSR-Device");
        if (result != 0) {
            //Failed to open MSR device with given device name.
            alert(result.toString());
        }
    }

    function onCloseClick() {
        var result = OPOSMsr.Close();
        if (result != 0) {
            //Close function invocation failed.
            alert(result.toString());
        }
    }

    function onClaimClick() {
        var result = OPOSMsr.Claim(1000);
        if (result == 0) {
            //If exclusive access is granted, bring the device to operational state.
            OPOSMsr.DeviceEnabled = 1;
            OPOSMsr.DataEventEnabled = 1;
        } else {
            alert(result.toString());
        }
    }

    function onReleaseClick() {
        //Release exclusive access for the device.
        var result = OPOSMsr.Relese();
        if (result != 0) {
            alert(result.toString());
        }
    }

    function enableDataEvents() {
        //Retrieve number of data events queued by the device / service object.
        var eventCount = OPOSMsr.DataCount;
        document.getElementById("dataEventCount").innerHTML = eventCount.toString();

        //The DataEventEnabled property is automatically disabled for each Data
        //Event notification. The application should indicate its readiness to
        //handle the next Data Event by enabling this property.
        OPOSMsr.DataEventEnabled = 1;
    }
</script>
</head>
<body>
    <object id="OPOSMsr"
      class id="clsid:CCB90122-B81E-11D2-AB74-0040054C3719" height="36"
     width="36"> </object>
    <br />
    <button id="openButton" onclick="onOpenClick()">Open</button>
    <button id="claimButton" onclick="onClaimClick()">Claim</button>
    <br />
    <button id="closeButton" onclick="onCloseClick()">Close</button>
    <button id="releaseButton" onclick="onReleaseClick()">Release</button>
    <br />
    <button id="dataEventEnableButton" onclick="enableDataEvents()">Enable
  Data Events</button>
    <div></div>
    <div id="dataEventCount"></div>
    <div id="track1"></div>
    <div id="track2"></div>
    <div id="track3"></div>

</body>
</html>

This example uses the <object> tag to embed the device specific UnifiedPOS compliant control object as an ActiveX control. The relevant ActiveX control is located through the specified Class ID.

When the OPOS MSR ActiveX control object is registered using the "Regsvr32" command line tool, the relevant Class ID is added to the following location in the Microsoft Windows registry.

[HKEY_CLASSES_ROOT\OPOS.MSR\CLSID]

When the above HTML document is loaded on Internet Explorer web browser, a frequent browser crash problem may occur. This is caused by a mismatch in threading models used by different components loaded during operation. Detailed information on Processes, Threads and Apartments is available here.

The following registry entry is created when the control object is registered, which indicates the location of the object in the file system and its threading model. The ThreadingModel value should be set to Apartment.

Windows 32 bit:

[HKEY_CLASSES_ROOT\CLSID\{Class ID}\InprocServer32]

Windows 64 bit:

[HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{Class ID}\InprocServer32]

The OPOS MSR control object depends on the services provided by the device specific service object to form its input output operations. The service object is registered as a separate object using "Regsvr32" command line tool. During the registration process, a separate registry entry is created with its own class ID in [HKEY_CLASSES_ROOT\CLSID]. The ThreadingModel value of service object should be set to Apartment.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Engineer MTT Network (Pvt.) Ltd.
Sri Lanka Sri Lanka
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- No messages could be retrieved (timeout) --