Let me get this straight:
- You did a web app which is a POS (presumably in PHP)
- Your users access the POS by a web browser on a local server
- 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:
- Write an HTTP server in C#/.Net listening to a specific port (here's a guide, its barely 50 lines of code)
- 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)
- 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.
- Put this compiled exe on windows autostart so that whenever the computer starts the mini web server that opens the till also starts.
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