API: Scan Using Socket Mobile Scanners

Scan barcodes and QR codes using a Socket Mobile S800 scanner. This JavaScript API can return data from scanned barcodes, as well as check the connection status of the scanner and battery level.

Requirements

Kiosk Pro Enterprise

  • Integration of our JavaScript API into your webpage
    • Sample code to run within the app and download for integration into your own project is available here.
    • Best practices for working with the JavaScript API are available here.
  • App Settings
    • JavaScript > Access JavaScript API > By Import
    • Other Peripherals & Integrations > External Barcode & QR Code Scanners > Enable Socket Mobile Scanner = On
  • iOS/iPadOS Permissions
    • Bluetooth - more on enabling specific iOS/iPadOS permissions here
  • Physical Hardware
    • Socket Mobile S800 scanner. For more information about the Socket Mobile S800 scanner, click here.


Triggers via API Functions

Check if Scanning is Enabled

This function checks whether Socket Mobile scanning is enabled in Kiosk Pro's settings.

Format
kp_SocketScannerAPI_requestStateOfSupporting(callback);
		
Parameters callback - [string] the name of the callback to be triggered after the function has been executed
Callback format
callback(supported);
		
Callback return values
  • supported - [integer] returns whether the Socket Mobile scanner setting is enabled. Possible values are:
    • 0 - Not enabled
    • 1 - Enabled


Check Battery Level

This function checks the battery level of the Socket Mobile scanner.

Format
kp_SocketScannerAPI_requestBatteryLevel();
		
Parameters callback - [string] the name of the callback to be triggered after the function has been executed
Callback format
callback(levelInPercent)
		
Callback return values
  • levelInPercent - [integer] returns the battery level of the Socket Mobile scanner as a percentage. Possible values are:
    • -1 - Undefined, Socket Mobile scanner is likely not connected
    • 0-100 - Battery level


Notifications via API Callbacks

When Scanner is Connected

This callback triggers when the Socket Mobile scanner connects to Kiosk Pro.

Format
kp_SocketScannerAPI_didConnectToDevice(device);
		
Return values
  • device - [associative array] key/value pairs containing information about the Socket Mobile scanner. Possible values are:
    • friendlyName - [string] name for identifying the scanner.
    • deviceType - [integer] scanner model as a SKT Capture device type numeric value, representing a combination of product type and interface. Returned as a large Objective-C enumeration.
    • deviceTypeFriendlyName - [string] model name of scanner.
    • guid - [string] unique identifier of device. Due to iPadOS privacy restrictions, this value changes every time the scanner is connected.


When Scanner is Disconnected

This callback triggers when the Socket Mobile scanner disconnects from Kiosk Pro.

Format
kp_SocketScannerAPI_didDisconnectFromDevice(device);
		
Return values
  • device - [associative array] key/value pairs containing information about the Socket Mobile scanner. Possible values are:
    • friendlyName - [string] name for identifying the scanner.
    • deviceType - [integer] scanner model as a SKT Capture device type numeric value, representing a combination of product type and interface. Returned as a large Objective-C enumeration.
    • deviceTypeFriendlyName - [string] model name of scanner.
    • guid - [string] unique identifier of device. Due to iPadOS privacy restrictions, this value changes every time the scanner is connected.


When a Scan is Returned

This callback is triggered when the app finishes the scanning process successfully.

If the source image contains a valid code but this code does not match a supported type of code (as defined in Kiosk Pro settings) or if the source image does not contain a valid code, then this callback will not be triggered and the image will be ignored.

Format
kp_SocketScannerAPI_didReceiveDecodedDataFromDevice(decodedData, device);
		
Return values
  • decodedData - [associative array] key/value pairs containing information about the scanned data. Possible values are:
    • DataSourceID - [integer] decoded data source ID.
    • DataSourceIDFriendlyName - [string] readable decoded data source ID.
    • DataSourceName - [string] data source name.
    • DecodedData - [string] data returned from the barcode. Each byte transforms to string: @"%02X", (unsigned char)bytes[i].
    • StringFromDecodedData - [string] data returned from the barcode. This may not be returned if the data in the barcode is not UTF8 encoded.
  • device - [associative array] key/value pairs containing information about the Socket Mobile scanner. Possible values are:
    • friendlyName - [string] name for identifying the scanner.
    • deviceType - [integer] scanner model as a SKT Capture device type numeric value, representing a combination of product type and interface. Returned as a large Objective-C enumeration.
    • deviceTypeFriendlyName - [string] model name of scanner.
    • guid - [string] unique identifier of device. Due to iPadOS privacy restrictions, this value changes every time the scanner is connected.


When an Error is Returned

This callback is triggered when the camera is unable to recognize any images as a valid barcode for a period of 15 seconds.

Format
kp_SocketScannerAPI_didReceiveError(error);
		
Return values
  • error - [associative array] key/value pairs containing information about the scanned data. Possible values are:
    • domain - [string] where the error occurred
    • code - [integer] an identifier for the error
    • description - [string] a brief description of error
    • failureReason - [string] a reason for the error (optional, may return as empty)
    • recoverySuggestion - [string] a suggested solution (optional, may return as empty)
    • debugDescription - [string] a detailed description of the error (optional, may return as empty)


Sample Code

  • This sample code relies on the JavaScript APIs built into Kiosk Pro and will not run successfully in other browsers or within our in-app help interface.
  • To run sample code, set the app's homepage to https://kioskgroup.com/socket-mobile-api
  • To download a .zip of sample code, click here.

Change Log

  • Added in version 9.5.4.

Still stuck? How can we help? How can we help?