Communicate with Cash Drawer from Website

前端 未结 4 2021
暖寄归人
暖寄归人 2020-12-13 05:47

I am currently building a POS solution for my company. The hardest part is shopping for the cash drawer as I do not have much experience with them and would prefer a USB cas

4条回答
  •  -上瘾入骨i
    2020-12-13 06:14

    Not really an answer, though too long for a comment..

    It sounds to me like you wish to call native code from a browser. That's not going to please lots of people, although I am aware of precisely one way to achieve this. It involves Internet Explorer and a COM server (activeX). IE can create an instance of the activeX program, which you'll need to write.

    This activeX can then issue the command to the vendor-supplied DLL. The problem with this though, is that if I was sitting at one of the terminals and had a keyboard, I could also open the drawer. You'd also need a method of communicating the intent to open the drawer from the server to the client. I suppose you could use WebSockets to maintain a communication channel between the client and the server, through which you issue the intent to open the drawer.

    This may be okay in a locked-down situation, though has all kinds of security concerns I've not considered nor mentioned here.

    To recap, here's a possible solution:

    1. Establish a WebSocket connection between the client and the server.
    2. Issue a command via this channel to the client browser from the server.
    3. Catch this command in the browser and then create an ActiveX object.
    4. Using javascript, tell this activeX object to open the drawer.
    5. Inside the ActiveX object, respond to a request to open the drawer by calling the appropriate function in the vendor-supplied DLL.

    I'd feel a little uneasy about implementing this personally (and would wish to be compensated handsomely).

    Incidentally, you can control amongst other examples, MS Office in this manner - allowing you to create a spreadsheet/word doc/etc from within the browser, populating the new document with user entered info.

    Here's a JS file I wrote for a project 18 months ago, that controls Excel.

    //
    // jsExcelObj.js
    // 28/08/2012 
    
    // the (only Excel) app instance - we only want to have 1
    // **** don't access this variable directly ****
    var jsExcelApp = null;
    
    /*****************************************************************************
        Excel class
    *****************************************************************************/
    function startExcel()
    {
        jsExcelApp = new ActiveXObject("Excel.Application");
    }
    
    function stopExcel()
    {
        jsExcelApp.Quit();
        delete(jsExcelApp);
        jsExcelApp = null;
    }
    
    function jsExcelWorkbook(filename)
    {
        if (jsExcelApp == null)
            startExcel(); //jsExcelApp = new ActiveXObject("Excel.Application");
    
        this.mFilename = filename;
        this.mExcelSheet = null;
        this.mWorkbook = jsExcelApp.Workbooks.Open(filename);
    
        this.close = function()
        {
            this.mWorkbook.Close(false);
            this.mFilename = null;
            this.mExcelSheet = null;
            this.mWorkbook = null;
        }
    
        this.open = function(filename)
        {
            if (jsExcelApp == null)
                startExcel();
    
            if (this.mFilename != null)
                this.close();
    
            this.mFilename = filename;
            this.mExcelSheet = null;
            this.mWorkbook = jsExcelApp.Workbooks.Open(filename);
        }
    
        this.setSheet = function(sheetName)
        {
            this.mExcelSheet = this.mWorkbook.Worksheets(sheetName);
        }
    
        this.getCellValue = function(column, row)
        {
            return this.mExcelSheet.Cells(row, column).value;
        }
    
        // returns the cells background colour as a html hex color value - e.g "7a554a"
        this.getCellColor = function(column, row)
        {
            var hexStrVel, r, g, b, decNum;
    
            decNum =  this.mExcelSheet.Cells(row, column).Interior.Color;
            // get a hexidecimal string representation of the number
            hexStrVal = decNum.toString(16);
    
            // pad to 6 bytes long
            while (hexStrVal.length < 6)
            {
                hexStrVal = "0" + hexStrVal;
            }
    
            // extract the 3 components
            r = hexStrVal.substr(4,2);
            g = hexStrVal.substr(2,2);
            b = hexStrVal.substr(0,2);
    
            return r+g+b; // return them in reverse order
        }
    }
    

    Using it is a simple as:

    
    
    

    I'm more than a little curious as to what other answers you'll get to this question. It sounds like a long march through a minefield from every perspective I can think of..

    I would consider very seriously implementing my own server/client architecture using c++ and forget about using HTML/PHP. This may be because I know too little, or it may be because I know enough to see the dangers - I don't know!

提交回复
热议问题