最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to access devices on a client PC from a browser - Stack Overflow

programmeradmin2浏览0评论

What are the various ways to access devices on client PC - a barcode reader, a scanner, etc. - from a browser? I realize my users may need a plugin. These devices may have an API that is specific to their device; I would like to exploit their API if available (maybe Java, maybe C, maybe mand line).

What are the various ways to access devices on client PC - a barcode reader, a scanner, etc. - from a browser? I realize my users may need a plugin. These devices may have an API that is specific to their device; I would like to exploit their API if available (maybe Java, maybe C, maybe mand line).

Share Improve this question edited Feb 1, 2010 at 18:10 Upperstage asked Feb 1, 2010 at 18:02 UpperstageUpperstage 3,7678 gold badges46 silver badges68 bronze badges 2
  • Every barcode scanner I've ever seen works as a keyboard, so it will work everywhere a keyboard will with no extra setup. – BlueRaja - Danny Pflughoeft Commented Feb 1, 2010 at 18:13
  • The devices are more similar to a scanner than to a barcode reader. – Upperstage Commented Feb 1, 2010 at 18:14
Add a ment  | 

4 Answers 4

Reset to default 5

A signed Java applet can have platform-independent access to most things. The user has to have Java installed, and has to allow the signed applet to run.

If you write a plug-in to the NSAPI, once they've installed it you'll have access to essentially anything the user can access. Of course, they have to install the plug-in.

Flash offers quite a lot of access to devices.

This is not a trivial thing, and there is no standardized API for it (except maybe in the JScript/ActiveX area that is confined to Internet Explorer).

For accessing scanners through the TWAIN interface, check out this question for all generally available options I know of.

Most other things will be down to custom programmed Active-X and other plug-ins. I have seen mercial barcode scanner plug-ins discussed on SO, but can't find the question right now.

Many barcode readers can be inserted between the keyboard and the PC, so the scanned barcodes go straight into the keyboard buffer. Other devices either plug into a serial port or have drivers that emulate a serial port. The following python code will copy data from a real or virtual COM port to the keyboard buffer of the active window. The COM port number is hard-coded but this can easily be changed.

import serial
import SendKeys

ser = serial.Serial(2)
print ser.portstr
while 1: # exit loop when ctrl/c pressed
    line = ""
    while 1:
        char = ser.read()
        if char == "\r": break
        line = line + char
    print line
    SendKeys.SendKeys(line, 0)
ser.close()

Depending on what you are trying to do, Silverlight and Adobe both have some limited capability in this arena. WebCams, printing in Silverlight 4.0, etc. However, it is non-trivial. Silverlight 4.0 and Flash both support barcode scanning.

发布评论

评论列表(0)

  1. 暂无评论