2

Tricky question this and I am not sure it can be resolved.

I am developing an EPOS system which runs entirely in the browser (preferring Google Chrome)

A couple of customers have mentioned the apparent need for it to be able to open a till drawer when they complete a sale.

The user presses the "Save Sale" button (which by the way submits using AJAX so if Javascript can be used in a solution, that'd be handy!) and then an invoice PDF is produced. On pressing the button, to achieve what we need, I need to be able to send a pulse to the USB port to trigger a solenoid on their till drawer.

Is it possible AT ALL for a browser to communicate with the USB port in this way?

If it is possible, an extension to this would be to also enable a feature to send, also by USB, a transaction total to a credit card terminal.

Having looked around a bit, I suspect, I will need to create a small piece of software which the user downloads to their local machine, which the browser then communicates with and this local application does the talking to USB, but I am afraid I have no idea where to begin in either direction with this.

Any pointers, tutorials or help at all would be very much appreciated!

Thanks in advance

EDIT:

I have found this: https://developer.chrome.com/apps/app_usb

But I think I am right in saying this is only suitable if I am developing a Chrome App rather than a website running in Chrome?

Jamie Hartnoll
  • 7,231
  • 13
  • 58
  • 97
  • The USB API for Chrome cannot be used for extensions. I don't know if an app can communicate with a webpage, but perhaps you can write a small server that runs on the client which can them communicate with your webapp using `postMessage`. – Lekensteyn Apr 03 '14 at 10:12
  • Thanks @Lekensteyn do you have any pointers/links I could look at regarding your solution? I'm not sure how I would implement it. Also, it has to be something which can be relatively easily deployed to a client machine. – Jamie Hartnoll Apr 03 '14 at 11:16
  • I posted an answer that should be applicable to different platforms (Linux, Windows, even Mac). Do you have any control over the platform running on client machines or do you just provide an appliance that clients can run, directly from their browser? – Lekensteyn Apr 03 '14 at 12:54
  • The application is provided to run directly from the browser. Thanks for your answer... part one is a bit mysterious to me! I'll have a go though! – Jamie Hartnoll Apr 03 '14 at 15:17
  • Jamie, yes unfortunately I cannot be more specific as the exact interface with the cash drawer is not mentioned. Feel free to comment if you have any questions. – Lekensteyn Apr 03 '14 at 16:21
  • To be honest, I have no idea how the interface will work at the moment! I guess my first stop will be to create something that can at least identify and find devices via the browser, then build on that.... not even sure where to start right now though! – Jamie Hartnoll Apr 03 '14 at 20:15
  • @Lekensteyn I've done a bit of digging today, but I am afraid I am completely lost! Sorry! I don't even know where to start. Am I looking at creating a little .exe which the user would install on their machine to enable the browser to communicate with their USB device? If so, is the node.js application which I just downloaded the place to build this? I'm afraid I don't know where I'm going. My experience is limited. Fairly good with Visual Studio, but that's it I am sorry to say! – Jamie Hartnoll Apr 04 '14 at 11:13
  • If your aim is cross-platform compatibility, then you could create a js file that your bundle with the node.js binaries (or python script + interpreter, etc). Otherwise, you can indeed just build an exe, but I would avoid that if possible. Your aim is to get an easy interface with the USB and the browser. But really, the language choice is irrelevant. Your first objective is to find out what interface is available from that cash drawer. – Lekensteyn Apr 04 '14 at 13:57
  • I am sorry, I'm totally lost! I've downloaded Node and simply cna't figure out what do to with it. I get a command line but how/where do I write Javascript and how does it run? I'm watching this http://nodetuts.com/01-node_intro.html. At 2:56 he goes into a Javascript editor, but what's he editing and how does this create a program. What runs it? I feel really dumb but have no idea what I am doing here! I can write Javascript fine, but it has to have somewhere to run and has to have a reference to Node to work... – Jamie Hartnoll Apr 04 '14 at 14:53
  • You just write a script file and run it with node (`node usb-server.js`). In the browser, you act on clicks, timers, HTTP respones, etc. In your `usb-server.js` script, you act on new HTTP connections (and if necessary, USB events so you can provide feedback to the client). Do you have any previous experience with the USB protocol? Are you sure that talking raw USB is the only way to communicate with this device? – Lekensteyn Apr 04 '14 at 15:56
  • Frankly... with this I have no idea at all!! – Jamie Hartnoll Apr 04 '14 at 18:53
  • Jamie, I am trying to help, but you have still not answered my query, which interface is available from the hardware? Do you know what kind of device your customer has available? Is there actually one single type of device instead of ten different ones? – Lekensteyn Apr 04 '14 at 19:22
  • @Lekensteyn I do appreciate your help! Sorry if it sounded ungrateful! There could be many types of cash drawer. It might not even be viable at all! I think what might be best is to start with the second part of my question which would be to send a transaction total to a card machine. This should be a more universal function, and easier to get documentation depending on the card machines. I'll find out tomorrow the tech info regarding the card terminals we use ourselves. Once I get to grips with that I should be able to expand the application. – Jamie Hartnoll Apr 06 '14 at 10:48
  • Ok, that matches my view on this situation, you have (a) customer(s) with this feature request, but the exact hardware varies between clients. You will benefit if you build your server application modular, that is, define the functions you expect from the hardware interface and present a single interface to the browser. Good luck again :) – Lekensteyn Apr 06 '14 at 10:55
  • @Lekensteyn it turns out I don't need to do this for the cash drawer anyway, just encourage clients to buy a receipt printer, which will integrate with the cash drawer and do that anyway. eg: http://www.star-emea.com/tsp100-futureprnt-introduction/ However... I cannot get any information from Card Terminal providers! http://stackoverflow.com/questions/17057340/ and http://stackoverflow.com/questions/18662567/ are asking the same question, but I called Ingenico earlier today (as I am using their terminals) and the couldn't have been less helpful! I guess I'll figure it out eventually! – Jamie Hartnoll Apr 07 '14 at 14:45

2 Answers2

0

As mentioned in the comments, you could set up a local server that runs on the client. That server should have appropriate permissions to access the USB port.

By "server", I do not mean a webserver such as nginx, but an application with a specific purpose. The exactly language for this application does not matter, but it has to provide a USB library. Example cross-platform libraries:

This means that you have to implement the USB device driver yourself. If your client already has a program (say, eject-drawer.exe) or different API/interface (e.g. /dev/theEPOSdevice), try to use those abstractions instead. If the USB device fits a certain device class, you can also opt to use libraries tailored that class. For USB HID, you can use HIDAPI (python binding, node.js library).

Let's say that the client server runs on http://localhost:8080/ and that your webapp runs on http://app.example.com/. You have some options for communication:

  • Set the apprioriate CORS headers on localhost:8080 and use "regular AJAX" calls.
  • Load localhost:8080 in an iframe on app.example.com and use the postMessage API to facilitate cross-domain communication.

The last part is not particularly difficult, you will likely spend some time on the first half where you need to interface with the USB device. Good luck!

Lekensteyn
  • 64,486
  • 22
  • 159
  • 192
0

Well, it can be solved using a signed ActiveX in VB. or a Java Applet. Any of them can access usb devices, given the right permissions. Java applets are multi-platform, so they should be your first choice.

This solution is more lightweight than running a full bloom http server, and also much more easier to maintain, as all the code will be located in the same place, IMHO.

There are plenty of tutorials about how to send data over a usb connection in any of both languages on internet, so I won't post any sample code.

Oscar
  • 13,594
  • 8
  • 47
  • 75