Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
490 views
in Technique[技术] by (71.8m points)

php - Communicate with Cash Drawer from Website

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 cash drawer. I have found a model I am interested in

CR-4005

http://www.thebarcodewarehouse.co.uk/epos-systems/cash-drawers/cr-4005-b/

The supplier includes a driver which can be found here

http://www.posiflexusa.com/driver.php

This allows you to open the drawer etc using a dll file. An example of the codes given are like so:

Public Declare Function OpenUSB Lib "usbcr.dll" () As Long

I have minor experience with C but with google I am sure I could figure this part out.

The issue I am having is that the solution is just effectively a website hosted offsite, what I need to be able to do is from the site issue commands to the client machine using it. So that when they complete a sale I can open the drawer for that particular machine.

What I need to clarify is how I go about doing this. For example, I would assume I install the driver on the client machine and plug the cash drawer in. Then when they access the site I need to execute the C command shown above to open the drawer. The problem i am having is wrapping my head around how this would work. Surely if I execute the command on the server it will effectively be looking at the servers usb ports and trying to open the drawer. Rather than issuing the command to the client machine. Therefore in order to work around this would it be possible to maybe have the c file on the clients machine and then I simply call a file on the site using something like

C:Windowsexecute.bat

Which in turn calls the c file on the client machine.

I understand I don't have a lot of information to provide as I am trying to figure this out before going ahead with the purchase and I am probably over complicating this but any pointers or info would be most appreciated. Also I am not completely set on this model, so if you know an alternative with some good documentation or an existing solution, I am open to this also.

Notes

I understand there could be a possible solution with chrome api calls

I could potentially install xampp and create a simple php files that calls an exe which does the necessary work. Therefore maybe accessing a local address on the client machine could be another potential idea (ie 127.0.0.1/open.php).

Update

My Website including the POS side of things is built and ready to go. This is built using PHP and is hosted on an external server. We access the site via a domain.

When the user performs a specific action on the external site, it needs to open the staff members local till drawer either by opening a local file (ie an exe that can open the drawer) or by accessing say a local webserver on the machine ie localhost/open.

The till drawer is the one listed above and it is connected via USB to the clients machine. No receipt printer is used.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Let me get this straight:

  1. You did a web app which is a POS (presumably in PHP)
  2. Your users access the POS by a web browser on a local server
  3. You need to be able to open de cash drawer client side... (e.g. to give change back to customer)

Option 1:

Considering that:

  • You control the customer POS clients (as in you can install software and set policies)
  • You can install google chrome and set it as a requirement for your app

Then you could try using the native chrome USB library:

http://developer.chrome.com/apps/app_usb

It has it's caveats, yes, but chances are you may have luck and that the device can be opened with this. I've worked several years for a POS software company and both serial and usb cash drawers had a really really simple protocol that allowed us to open them even with FoxPro.

You would have to create a small chrome app that sends the command to open the drawer. This app should expose one function that could be called once you write the operation or commit the transaction to the server (e.g. when you saved a record of the sale) so you could attach a callback in jQuery o javascript that does this after you post the data and receive a succesful response.

Option 2:

Java applet:

I have no experience with this. But you may be able to use JNI (java native interface) to call native code. I'm not sure if the applet container is sandboxed in a way that does not allow you to do it, but these two links may come in handy:

How To Call Native (DLL) Code From Java Using JNI Calling C library routines from java

Option 3:

Doing it OS-wise:

Another option, and seems to be the easiest for me, is to map a keystroke at the OS level so that the combination executes certain command. You can see here a description of how to do it in windows. In linux (gnome and kde etc) this is very easy.

Once You did that, you could use this jQuery library, that "simulates" keystrokes, so, again, when you receive your response that the transaction is done and that you need to open de cash drawer you'll want to callback a function that executes a simulation keystroke that you previsouly had configured as per the article I gave you.

And of course, this command would run a locally native application which actually opens the drawer, can be in C/C++/C# or whatever the supported device API is. But I'm sure is a standard interface so you can code that app easily in any language. Here's a good start for C#.

Option 4:

Local web server.

Now that you mention having a local web server this could be an option, actually. But, why install XAMPP on client machines? There is a better way to do it. And the answer would be write a really really small and simple HTTP web server in C#/.NET. So following this approach you'll want to:

  1. Write an HTTP server in C#/.Net listening to a specific port (here's a guide, its barely 50 lines of code)
  2. In your C# code you'll want to either use any integration API coming with the hardware, P/Invoke to the C library (which I don't recommend) or simply using the send to USB port commands approach. And thus, it'll be simpler to open the drawer, print or do whatever you need from within C# which is OS integrated. (even for linux/mac with mono)
  3. Set up your code in C# so that the server only listens to local addresses so no one can open the till unless is the same network, heck, I would only allow 127.0.0.1 just for the sake of making sure only the local machine can open it.
  4. Put this compiled exe on windows autostart so that whenever the computer starts the mini web server that opens the till also starts.
  5. Just catch your callback whenever a transaction was succesful to the POS server and finally do something like:

    $.ajax({
        type: 'POST',
        dataType: 'json',
        data: 1,
        url: '127.0.0.1:8088/open',
        error: function() {
            alert('Could not open cash drawer');
        },
        success: function() {
            //do something else
        }
    });
    

So you'll be sending a POST request to the local machine which listens to the HTTP protocol in the 8088 port (or whatever you set up in your code) and then it'll handle internally the request as opening the drawer, if you throw an exception inside that code than you can return an HTTP 500 response from this C# mini webserver so that you catch it on the error handler of jquery (or whatever library that you use)

And I would highly recommend, like I told you, that this app only listens to local requests for security reasons, even if you are only doing a simple operation. It'll work because the client side jquery code is being called by the local machine.

You could also optimize the webserver app so that it read a .ini file or some settings file (.Net has the .config default which is the way to go) so that you can tweak it per-customer basis and you don't hardcode options.

Good luck! And let us know how you did it


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...