Power Management

It is important to know the power state of the scanner as it is for the host to make sure it does not need to be recharged during the time the scanner is needed and the operation has a chance to change batteries or charge the scanner.

The application can check the battery level of the scanner using Capture SDK.

Additionally, many Socket Mobile scanners support battery level change notification.

Following are some examples on how to configure the scanner for these features.

Reading the Battery Level

Here is example code showing how to request the scanner battery level information:

function getBatteryLevel() {
   const property = new SocketMobile.CaptureProperty(
      SocketMobile.CapturePropertyIds.BatteryLevelDevice,
      SocketMobile.CapturePropertyTypes.None,
      {}
   );
   captureDevice.getProperty(property)
   .then(({value}) => {
      const battery = document.getElementById('batteryLevel');
      battery.innerHTML = `Battery: ${(value & 0xff00)>>8}%`;
   })
   .catch(err => {
      console.log(`error while getting the battery level: ${err}`);
   });
}

Note

The value returned when getting the battery level of a device is an integer composed of 3 values:

Max Range

Current Value

Min Range

Byte 2

Byte 1

Byte 0

The Max Range is often 100, and Min Range 0, so the current value is expressed as a percentile, but ideally if the Socket Mobile device changes the granularity of the range, it is recommended to use the full scale: current value x 100 ÷ (Max range - Min Range)

Set up the Battery Level Change Notification

Setting up the scanner to make it send a notification each time the battery level changes is a 2 step process.

Since this setting is persistent in the scanner, the first time the scanner connects to the application we query the notification setting, if the battery level change notification is not activated then we activate it.

The initial battery level needs to be read at this time because it could take a long time before the first battery level change notification is received.

function configureNotification() {
   let property = new SocketMobile.CaptureProperty(
      SocketMobile.CapturePropertyIds.NotificationsDevice,
      SocketMobile.CapturePropertyTypes.None,
      {}
   );
   captureDevice.getProperty(property)
   .then(({value}) => {
      if(value & SocketMobile.Notifications.BatteryLevelChange === 0) {
         value |= SocketMobile.Notifications.BatteryLevelChange;
         property = new SocketMobile.CaptureProperty(
         SocketMobile.CapturePropertyIds.NotificationsDevice,
         SocketMobile.CapturePropertyTypes.Ulong,
         value
         );
         return captureDevice.setProperty(property)
      }
   })
   .catch(err => {
      console.log(`error while configuring the notifications: ${err}`);
   });

}

An appropriate place to read the first battery level is when the device connects.

The battery level change notifications are received in the same notification handler as any other Capture events and they are identified by this Capture event ID: SocketMobile.CaptureEventIds.BatteryLevel.

Power State Change and other Events

The same principle can be followed for the other events of the device, such as the SocketMobile.CaptureEventIds.Power event which notifies the application each time the scanner is plugged into a power source, or unplugged or dropped in the charger cradle.

Other events such as buttons state can be tracked by handling the Capture event ID: SocketMobile.CaptureEventIds.Buttons that has a long value that is a combination of the following mask values:

Available notifications

Below is a table of all the possible values for configuring the notifications that a device could send aside the device arrival/removal, decoded data.

These settings can be set conjointly if multiple events need to be received by the application.

Name

Description

SocketMobile.Notifications.TriggerButtonPress

The device sends a notification when the trigger button is pressed

SocketMobile.Notifications.TriggerButtonRelease

The device sends a notification when the trigger button is released

SocketMobile.Notifications.PowerButtonPress

The device sends a notification when the power button is pressed

SocketMobile.Notifications.PowerButtonRelease

The device sends a notification when the power button is released

SocketMobile.Notifications.PowerState

The device sends a notification when the power state changes (battery to AC or vice-versa) (not supported on all device)

SocketMobile.Notifications.BatteryLevelChange

The device sends a notification when the battery level changed (not supported on all device)

These notifications are often regrouped by type. The notifications regarding the buttons are regrouped in the Capture event with the SocketMobile.CaptureEventIds.Buttons ID, the battery level notification is sent with the SocketMobile.CaptureEventIds.BatteryLevel ID, the power state change notification is sent with the SocketMobile.CaptureEventIds.Power ID.

Refer to Capture Events List for a complete list of events Capture or the device could send.