Open Cash Drawer by Internet Explorer?

When I develop the "Clubhouse Management System", I need to open the cash drawer in web browser (because it is web-based system) ^.^
I search google, and dont has any similar code?!? that mean I need to do it!

First, I need a code to open the cash drawer; I using a simple code:

  1. Most cash drawers are attached to a printer port, To open the cash drawer we must send "control codes" to the port

    declare the "control codes":
    Dim strPin As String = Chr(27) + Chr(112) + Chr(0) + Chr(25) + Chr(250) + Chr(0)

  2. Save the "control codes" to a file:
    FileOpen(1, "c:\ocd.txt", OpenMode.Output)
    PrintLine(1, strPin)
    FileClose(1)

  3. hehe, now send to the port, for example: lpt1 port
    Shell("print /d:lpt1 c:\ocd.txt", AppWinStyle.Hide, True)



After that, I create a COM object using the COM class template of Visual Studio . Net;
The COM class template creates a new class, then configures your project to generate the class as a COM object and registers it with the operating system automatically.
  1. Open a New Windows Application project by clicking New on the File menu, and then clicking Project. The New Project dialog box will appear.
  2. With Visual Basic Projects highlighted in the Project Types list, select Class Library from the Templates list, and then click OK. The new project will be displayed.
  3. Select Add New Item from the Project menu. The Add New Item dialog box will be displayed.
  4. Select COM Class from the Templates list, and then click Open. Visual Basic .NET will add a new class and configure the new project for COM interop.
  5. Add code, such as properties, methods, and events to the COM class. We will create a "Open" module into the class and rename the class to class demo.
  6. Select Build Solution from the Build menu. Visual Basic .NET will build the assembly and register the new COM object with the operating system automatically.


Now, We can install the com DLL to the any client PC.

  1. Register the DLL File to your local PC:
    Click [Start] -> [Run] to run the following command.

    C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\RegAsm.exe D:\{file path}\MyCashDrawer.dll /tlb: D:\{file path}\MyCashDrawer.tlb

  2. Add your site in "Trusted Site".

  3. In "Internet Explorer", click [Tools] -> [Internet Options] -> [Security] -> [Trusted Sites] -> [Custom Level].

    Set [ActiveX controls and plug-ins] -> [Initialize and script ActiveX controls not marked as safe] to "Enable"

Finally, We can use it, create a HTML file, and insert the following code:
< script type="text/vbscript" language="vbscript" >
Dim oCashDrw
set oCashDrw = CreateObject("CashDrawer.demo")
oCashDrw.Open()
set oCashDrw = nothing
</script >

0 comments: