StarMgsIO Android SDK Ver 1.5.0

Overview

This package contains StarMgsIO SDK Ver 1.5.0
starmgsio.jar is a library for supporting application development for Star scales.

  1. Contents
  2. Scope
  3. Installation
  4. API
    1. StarDeviceManager
    2. StarDeviceManager.InterfaceType
    3. StarDeviceManagerCallback
    4. ConnectionInfo
    5. ConnectionInfo.InterfaceType
    6. ConnectionInfo.Builder
    7. Scale
    8. ScaleCallback
    9. ScaleSetting
    10. ScaleOutputConditionSetting
    11. ScaleData
    12. ScaleData.Unit
    13. ScaleData.ComparatorResult
    14. ScaleData.DataType
    15. ScaleData.Status
  5. Copyright
  6. Release History

Contents

MG_series_Scale_StarMgsIO_Android_SDK_V1_5_0/
├── Documents/
│   └── readme.url                      // Link to release Notes
│── Software/
│   ├── SDK/                           // Samples (Ver 1.5.0)
│   └── Distributables/
│       └── starmgsio.jar              // starmgsio.jar (Ver 1.5.0)
└── SoftwareLicenseAgreement.pdf       // Software License Agreement

Scope

Supported models :

Supported OS :

Installation

StarMgsIO SDK library supports Maven Repository and JAR file. Please link library that suits your application configuration.

Use Maven Repository

  1. Insert following code in app/build.gradle.
dependencies { implementation 'com.starmicronics:starmgsio:starmgsioVersion' ... }

Please refer to app/build.gradle in SDK for the latest library version.

Use JAR File

  1. In your app, please link starmgsio.jar located in Software/Distributables/.

  2. Insert following code in app/build.gradle.

dependencies { implementation files('../../Distributables/starmgsio.jar') ... }

Configuration

  1. Please give permissions below in your AndroidManifest.xml. (These settings are related by BLE. (Required))
    ACCESS_FINE_LOCATION needs runtime permission.
    Please turn ON location permission(App info -> Permissions -> Location), or make your app to ask users to turn on the permission.
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.starmicronics.starmgsiosdk"> <uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" /> <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30" /> <uses-permission android:name="android.permission.BLUETOOTH_SCAN" /> <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" /> <!-- Declare this required feature if you want to make the app available to BLE-capable devices only. If you want to make your app available to devices that don't support BLE, you should omit this in the manifest. Instead, determine BLE capability by using PackageManager.hasSystemFeature(FEATURE_BLUETOOTH_LE) --> <uses-feature android:name="android.hardware.bluetooth_le" android:required="true"/> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <application> ... </application> </manifest>
  1. Add about use of USB connection. (Optional)
    In case of check on the checkbox of connection permission dialog, then the dialog will not be displayed even if the cable is inserted or removed unless the application is reinstalled. In addition, the sample application will automatically launch when you insert the cable.

Create "device_filter.xml" in res folder.

<?xml version="1.0" encoding="utf-8"?> <resources> <usb-device vendor-id="1305" product-id="4100" /> <usb-device vendor-id="1305" product-id="4101" /> <usb-device vendor-id="1305" product-id="4102" /> <usb-device vendor-id="1305" product-id="4136" /> <usb-device vendor-id="1305" product-id="4137" /> <usb-device vendor-id="1305" product-id="4138" /> <usb-device vendor-id="1305" product-id="4139" /> <usb-device vendor-id="1305" product-id="4140" /> <usb-device vendor-id="1305" product-id="4141" /> </resources>

And add next text in manifest.xml.

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.starmicronics.starmgsiosdk"> ... <application ...> <activity ... android:exported="true"> <intent-filter> <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" /> </intent-filter> <meta-data android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" android:resource="@xml/device_filter" /> </activity> </application> </manifest>

API

StarDeviceManager

public class StarDeviceManager

This class is used to manage a scale.

Public constructor
StarDeviceManager(Context context)
Create a StarDeviceManager class instance for all interface.
StarDeviceManager(Context context, StarDeviceManager.InterfaceType type)
Create a StarDeviceManager class instance for specific interface.

Usage

mStarDeviceManager = new StarDeviceManager(ScanActivity.this, StarDeviceManager.InterfaceType.All);
Public methods
void scanForScales(StarDeviceManagerCallback callback)
Start scanning scales
callback: The information to connect a scale will be notified to StarDeviceManagerCallback#onDiscoverScale method when a new scale is discovered
void stopScan()
Stop scanning scales
Scale createScale(@NonNull ConnectionInfo info)
Create a Scale class instance with the information to connect a scale
String getVersionName()
Get starmgsio.jar library version name

Usage - scanForScales()

mStarDeviceManager.scanForScales(mStarDeviceManagerCallback);

See ScanActivity for more information.

Usage - createScale()

mScale = starDeviceManager.createScale(connectionInfo);

See ScaleActivity for more information.


StarDeviceManager.InterfaceType

public enum StarDeviceManager.InterfaceType

This enum is used to specify the StarDeviceManager's InterfaceType setting.

Constants
StarDeviceManager.InterfaceType BluetoothLowEnergy
Bluetooth Low Energy
StarDeviceManager.InterfaceType USB
USB
StarDeviceManager.InterfaceType All
All interface which can support by this library

StarDeviceManagerCallback

public abstract class StarDeviceManagerCallback

This class is used to receive the result of processes done in the StarDeviceManager class.

Public constructor
StarDeviceManagerCallback()
Create a StarDeviceManagerCallback class instance
Public method
void onDiscoverScale(@NonNull ConnectionInfo info)
Notify the execution result of StarDeviceManager#scanForScales method
private final StarDeviceManagerCallback mStarDeviceManagerCallback = new StarDeviceManagerCallback() { @Override public void onDiscoverScale(@NonNull ConnectionInfo connectionInfo) { Map item = new HashMap<>(); item.put(INTERFACE_TYPE_KEY, connectionInfo.getInterfaceType().name()); item.put(DEVICE_NAME_KEY, connectionInfo.getDeviceName()); item.put(IDENTIFIER_KEY, connectionInfo.getIdentifier()); if(!mDataMapList.contains(item)) { mDataMapList.add(item); mAdapter.notifyDataSetChanged(); } } };

ConnectionInfo

public class ConnectionInfo

The following constants is used for ConnectionInfo class as any device identifier of scale(exclude BLE).

Constants
String ANY_DEVICE_IDENTIFIER
Any device identifier of scale(exclude BLE). If 2 more scales can be detected on a host device, library automatically selects one scale at random every time.

Data class to store the information to connect a scale

Public methods
ConnectionInfo.InterfaceType getInterfaceType()
Return interface type
String getIdentifier()
Return identifier
String getMacAddress()
Return MAC address
String getDeviceName()
Return device name
int getBaudRate()
Return baud rate
ScaleType getScaleType()
Return scale type

ConnectionInfo.InterfaceType

public enum ConnectionInfo.InterfaceType

This enum is used to specify the ConnectionInfo's InterfaceType setting.

Constants
ConnectionInfo.InterfaceType BLE
Bluetooth Low Energy
ConnectionInfo.InterfaceType USB
USB
ConnectionInfo.InterfaceType INVALID
Invalid value

ConnectionInfo.Builder

public static class ConnectionInfo.Builder

Builder class to generate the ConnectionInfo class instance.

Public constructor
ConnectionInfo.Builder()
Create a builder for the information to connect a scale

Public methods
ConnectionInfo.Builder setBleInfo(string identifier)
Set the BLE connection information (specify the mac address)
In case of communicate with scale with BLE, please set connection information with this method.
ConnectionInfo.Builder setUsbInfo(string identifier)
Set the USB connection information (specify the device identifier which could be gotten from scan result.)
If a device communicate with our scale with USB, please set connection information with this method.
ConnectionInfo.Builder setBaudRate(int baudRate)
Set the baud rate information
In case of USB interface, check and set the communication settings of the device to be used.
ConnectionInfo build()
Return generated ConnectionInfo class instance.

Scale

public abstract class Scale

This class is used to communicate with a scale.

The following constants is used for ScaleCallback class as status code of scale.

Constants
int CONNECT_SUCCESS
Connect to a scale operation completed successfully
int CONNECT_NOT_AVAILABLE
The host device does not have the function to connect to a scale
int CONNECT_ALREADY_CONNECTED
Attempt to connect to a scale even though already connected to it
int CONNECT_TIMEOUT
Connect to a scale operation is failed due to timeout
int CONNECT_NOT_SUPPORTED
Attempt to connect to not supported device
int CONNECT_NOT_GRANTED_PERMISSION
Attempt to connect to not permission device
int CONNECT_NOW_CONNECTING
Now connecting by other request
int CONNECT_READ_WRITE_ERROR
Read or write error is occurred
int CONNECT_UNEXPECTED_ERROR
Connect to a scale operation is failed due to unexpected error
int DISCONNECT_SUCCESS
Disconnect a scale operation completed successfully
int DISCONNECT_NOT_CONNECTED
Attempt to disconnect a scale even though not connected to it
int DISCONNECT_UNEXPECTED_DISCONNECTION
Scale is disconnected unexpectedly
int DISCONNECT_TIMEOUT
Disconnect a scale operation is failed due to timeout
int DISCONNECT_READ_WRITE_ERROR
Read or write error is occurred
int DISCONNECT_UNEXPECTED_ERROR
Disconnect a scale operation is failed due to unexpected error
int UPDATE_SETTING_SUCCESS
Change scale settings operation completed successfully
int UPDATE_SETTING_NOT_CONNECTED
Attempt to change scale settings even though scale is not connected
int UPDATE_SETTING_REQUEST_REJECTED
Change scale settings operation is failed due to request is rejected
int UPDATE_SETTING_TIMEOUT
Change scale settings operation is failed due to timeout
int UPDATE_SETTING_NOW_EXECUTING_ERROR
Failed to request scale settings, other request is now executing.
int UPDATE_SETTING_UNEXPECTED_ERROR
Change scale settings operation is failed due to unexpected error
int UPDATE_SETTING_NOT_SUPPORTED
An unsupported command was specified.
Public methods
void connect(ScaleCallback callback)
Connect to a scale and set callback to notify the communication result with it
callback: The result will be notified to ScaleCallback#onConnect method
void disconnect()
Disconnect a scale
callback: The result will be notified to ScaleCallback#onDisconnect method
void updateSetting(ScaleSetting setting)
Change scale settings
The result will be notified to ScaleCallback#onUpdateSetting method
void updateOutputConditionSetting(ScaleOutputConditionSetting setting)
Change scale output condition settings
The result will be notified to ScaleCallback#onUpdateOutputConditionSetting method.

Note : Once this method is executed, that state is maintained.
However, the status is reset to setting menu when the balance is turned on again.
In order to save the setting on the balance, please push [Menu] key and then return to the measuring mode.

ScaleCallback

public abstract class ScaleCallback

This class is used to receive the result of processes done in the Scale class.

Public constructor
ScaleCallback()
Create a ScaleCallback instance
Public methods
void onConnect(Scale scale, int status)
Notify the execution result of Scale#connect method
void onDisconnect(Scale scale, int status)
Notify the execution result of Scale#disconnect method or physical disconnection
void onReadScaleData(Scale scale, ScaleData scaleData)
Notify that weight data is received from a scale
void onUpdateSetting(Scale scale, ScaleSetting setting, int status)
Notify execution result of the Scale#updateSetting method
void onUpdateOutputConditionSetting(Scale scale, ScaleOutputConditionSetting setting, int status)
Notify execution result of the Scale#updateOutputConditionSetting method

ScaleSetting

public enum ScaleSetting

This enum is used to specify the scale setting.

Constants
ScaleSetting ZeroPointAdjustment
Zero Point Adjustment


ScaleOutputConditionSetting

public enum ScaleOutputConditionSetting

This enum is used to specify the scale output condition setting.

Constants
ScaleOutputConditionSetting StopOutput
Stop output

Note : MG-T Scale is not support.
ScaleOutputConditionSetting ContinuousOutputAtAllTimes
Continuous output at all times
ScaleOutputConditionSetting ContinuousOutputAtStableTimes
Continuous output at stable times(Output stop at unstable times)
ScaleOutputConditionSetting PushDownKeyForOneTimeInstantOutput
Push down [Output] key for one-time instant output

Note : MG-T Scale is not support.
ScaleOutputConditionSetting AutoOutput
Auto output

Note : MG-T Scale is not support.
ScaleOutputConditionSetting OneTimeOutputAtStableTimes
One-time output at stable times(Output stop at unstable times)

Note : MG-T Scale is not support.
ScaleOutputConditionSetting OneTimeOutputAtStableTimesAndContinuousOutputAtUnstableTimes
One-time output at stable times(Continuous output at unstable times)

Note : MG-T Scale is not support.
ScaleOutputConditionSetting PushDownKeyForOneTimeOutputAtStableTimes
Push down [Output] key for one-time output at stable times

Note : MG-T Scale is not support.

ScaleType

public enum ScaleType

This enum is used to specify the scale type.

Constants
ScaleType INVALID
lnvalid value
ScaleType MGS
MG-S322,MG-S1501,MG-S8200,MG-S322 USCA MG-S1501 USCA, MG-S8200 USCA
ScaleType MGTS
MG-T12,MG-T30,MG-T60,MG-T12 UDB,MG-T30 UDB MG-T60 UDB
Public methods
ScaleType getEnum(String name)
Get the ScaleType of Enum type from the String name (MGS or MGTS).

ScaleData

public interface ScaleData

This interface manages weight data received from a scale.

Public methods
double getWeight()
Weight
ScaleData.Unit getUnit()
Unit of weight
ScaleData.ComparatorResult getComparatorResult()
Result of comparator function
ScaleData.DataType getDataType()
Type of the data
ScaleData.Status getStatus()
Scale status
int getNumberOfDecimalPlaces()
Number of decimal places of weight
String getRawString()
Raw string

ScaleData.Unit

public enum ScaleData.Unit

This enum is used to specify the unit of weight.

Constants
ScaleData.Unit INVALID
Invalid value
ScaleData.Unit MG
Milligram
ScaleData.Unit KG
Kilogram
ScaleData.Unit G
Gram
ScaleData.Unit CT
Carat
ScaleData.Unit MOM
Momme
ScaleData.Unit OZ
Ounce
ScaleData.Unit LB
Pound
ScaleData.Unit OZT
Troy ounce
ScaleData.Unit DWT
Penny weight
ScaleData.Unit GN
Grain
ScaleData.Unit TLH
Hong Kong tael
ScaleData.Unit TLS
Singapore tael
ScaleData.Unit TLT
Taiwan tael
ScaleData.Unit TO
Tola
ScaleData.Unit MSG
Mesghal
ScaleData.Unit BAT
Baht
ScaleData.Unit PCS
Parts counting
ScaleData.Unit PERCENT
Percentage weighing
ScaleData.Unit COEFFICIENT
Multiplied by Coefficient

ScaleData.ComparatorResult

public enum ScaleData.ComparatorResult

This enum is used to specify the result of comparator function.

Constants
ScaleData.ComparatorResult INVALID
Invalid value
ScaleData.ComparatorResult SHORTAGE
Shortage
ScaleData.ComparatorResult OK
Proper
ScaleData.ComparatorResult OVER
Over

ScaleData.DataType

public enum ScaleData.DataType

This enum is used to specify the type of the data.

Constants
ScaleData.DataType INVALID
Invalid value
ScaleData.DataType NET_NOT_TARED
Net weight (not tared)
ScaleData.DataType NET
Net weight (tared)
ScaleData.DataType TARE
Tare weight
ScaleData.DataType PRESET_TARE
Preset tare weight
ScaleData.DataType TOTAL
Total value
ScaleData.DataType UNIT
Unit weight
ScaleData.DataType GROSS
Gross

ScaleData.Status

public enum ScaleData.Status

This enum is used to specify the status of weight data.

Constants
ScaleData.Status INVALID
Invalid value
ScaleData.Status STABLE
Data stable
ScaleData.Status UNSTABLE
Data unstable
ScaleData.Status ERROR
Data error

Copyright 2020 - 2023 Star Micronics Co., Ltd. All rights reserved.


Release History

Ver.1.5.0(US market only)
2023/10/31

Ver.1.4.0(US market only)
2021/12/20

Ver.1.3.0(US market only)
2020/04/06

Ver.1.2.0 (US market only)
2019/12/25

Ver.1.1.0 (US market only)
2019/08/19

Ver.1.0.0 (US market only)
2018/06/29