Communicate with Cash Drawer from Website

前端 未结 4 2022
暖寄归人
暖寄归人 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条回答
  •  时光取名叫无心
    2020-12-13 06:09

    Given the client machines presumably will be to some degree under your control, my understanding is all you need is a simple Remote Procedure Call system, I think that insisting the code must be run through a browser is unnecessarily difficult. My recommendation instead would to have a daemon (or service given we are in Windows land) running on the client machine which will respond to a remote request to control the cash draw. This program can be a completely separate program to the browser. You then have the server, upon a client opening a webpage send a packet to the client's IP address which will trigger this service on the client to control the cash draw.

    I am unfortunately too rusty with windows C programming to give an example but will try and break this down as simply as possible:

    On the client machines, run a daemon, which will accept connections on a particular port (only from the server's IP address of course to avoid just anyone connecting and controlling it. You could also use security certificates but that goes beyond the scope of this answer.) After accepting connections on this port it will respond to a set of packets which it can be sent which will correspond to actions on the cash draw. This can effectively be a simple C program which will listen on a socket then run functions in that DLL when it receives data.

    On the server you will need a program that responds to a client's attempt to access a particular webpage, you can hook this into PHP such that PHP will run a program on the server when the page is accessed, I assume you already know how to do this from what has been said in the question. This program will then open a connection to the IP of the client as given in the HTTP request and send a cash draw command to the socket the client's service is listening on. This should cause the client to do something with the draw. (you must hope the client is not masquerading an IP address however.)

    Finally you need the webpage to allow the client to request these commands from the server, there are a number of security concerns, particularly relating to the security of the client service but these are all relatively simple to overcome. This should also only take about 150 lines of code for a simple implementation. It also avoids any odd platform specific or browser specific code and completely avoids websockets.

    I hope this helps, if it is in any way unclear please leave a comment.

提交回复
热议问题