Documentation :: Demo :: Tech Info

WebBarcode Javascript API


WebBarcode creates addtional Javascript API’s that can be called from webpages that are loaded inside the browser.

All of the API methods are located under the window.WebBarcode namespace so they do not cause interferrance with existing Javascript code that is present.

None of the methods return a value, however most of them do accept a Javascript callback function that will be invoked when the call succeeds.

Demo

From the device you can also use the demonstration webpage.

Error handling

There is a global onError method that will be called when an internal error occurs.

WebBarcode.onError(callback)

Arguments:

Accepts a single function, which will be called with a Javascript object of that encodes the error’s information. Multiple callbacks may be registered and they will be all called in the order they were added.

example:

WebBarcode.onError(function(error){
   console.log(error);
});

WebBarcode.playSoundID("not a number");

// logged to console:
{"code":"bad_snd","message":"Unrecognized value, must be number"}

WebBarcode.onBarcodeScan(callback)

Arguments:

{
	"value": "123434",
	"type" : "Code 39"
}

Linea Scan/Swipe

WebBarcode.Linea.emitTones(sounds)

Arguments:

Example sounds:

[
    { "tone":2000, "duration":400 },
    { "tone":5000, "duration":250 }
]

The above will play a 2,000 Hz tone for 400 milliseconds, and then a 5,000 Hz tone for 250 milliseconds.

WebBarcode.Linea.onSwipe(callback)

Arguments:

Example scan object:

{
	"track1": "%B5XXXXXXXXXXXXXX2^FIRST/LAST^?;4222222222222=1103101000000300001?",
	"track2": "AJLKDSB@^JKLFD",
	"track3": "",
	"isFinancialCard": true,

	"name": "CARD HOLDER NAME",
	"number": "4222222222222",
	"month": "12",
	"year":"2012",
	"first_name": "CARD",
	"last_name":"NAME",
	"service_code": "101",
	"discretionary_data": ""
}

The fields shown above after isFinancialCard will only be present if isFinancialCard is true.

WebBarcode.Linea.onScan(callback)

Arguments:

{
	"value": "1234",
	"type" : "UPC-A"
}

WebBarcode.Linea.onConnectionStateChange(callback)

Arguments:

Example status:

{ "status": "DISCONNECTED" }

Status will be one of: CONNECTED, CONNECTING, DISCONNECTED, or UNKNOWN

Sounds

WebBarcode.playSoundID(soundId)

Arguments:

Plays one of the pre-defined sounds that are included in the iOS operating system. A list of the possible IDs is located at: http://iphonedevwiki.net/index.php/AudioServices

Note: Sounds cannot be played one right after the other without a pause between each sound long enough for the previous sound to complete playing.

WebBarcode.vibrateDevice()

Triggers the device’s vibration function.

Location

WebBarcode.onLocationUpdate(callback)

Arguments:

Example location object:

{
  "longitude": -122.0312186,
  "latitude":    37.33233141,
  "timestamp": 1430273306.402647,
  "course": -1,
  "speed": 0,
  "verticalAccuracy": -1,
  "horizontalAccuracy": 5,
  "altitude": 0
}

Some of the location items, such as course and speed may not be present depending on the hardware capabilities of the device.

WebBarcode will only query for location if the preference item “Track Location” is switched on. Be aware that using the GPS can have a drastic impact on battery life.

External Accessory

WebBarcode.getConnectedAccessories(callback)

Returns:

Example accessory objects. Note: Different properties will be set depending on device type:

[
  {
    "serialNumber":"XXQLJ144500948",
    "hardwareRevision":"0.0.1",
    "modelNumber":"QLn320",
    "firmwareRevision":"0.0.1",
    "name":"bt-printer",
    "manufacturer":"Zebra Technologies"
  }
]

WebBarcode.pickAccessory()

Presents the standard accessory selection dialog for connecting external accessorys such as Bluetooth printers.

Note: The accessory selection dialog will show all available accessories. However if an accessory that is already connected is chosen, no accessory connection callback is fired (since it’s already connected). It’s recommended to check the connected accessories by using the WebBarcode.pickAccessory and then call this method if the desired accessory is not already connected.

WebBarcode.onAccessoryConnect(callback)

Arguments:

Example accessory object:

{
  "serial": "Z123483"
    "hardwareRevision":"0.0.1",
    "modelNumber":"QLn320"
}

Be aware that bluetooth devices will periodically disconnect and then connect and in rapid succession.

WebBarcode.onAccessoryDisconnect(callback)

Arguments:

WebBarcode.ZebraPrinter.print(data, callback)

Arguments:

Returns:

Example print job:

{
   "serial": "XXQLJ144500948",
   "data":   "^XA^BY8,0^FT124,10^BON,8,N,0,N,1,^FDYourTextHere^FS^XZ"
}

Example callback data sent for a successfull print:

{
	"serial":  "XXQLJ144500948",
	"code":    "prn_success",
	"message": "Print was successful"
}