Barcode Scanner App Codelab
Introduction
Welcome to the Barcode Scanner App codelab! In this tutorial, you will learn how to:
- Install the app via terminal
- Verify the service is running
- Simulate external connections using Postman
- Send commands and check responses
- Explore three use cases: successful scan, aborted scan, and unsupported device
Prerequisites
- Castles S1U2 device is required for this codelab
- Device must be connected to a network (via WiFi)
- Barcode Scanner app (only available from the SmartPOS Store)
- Postman installed on your computer
Step 1: Install the Application
Open the SmartPOS Store client app on your device (usually found in the terminal menu)
Search for "Barcode Scanner" in the SmartPOS Store
Install the application directly from the SmartPOS Store
Confirm installation on your device
Step 2: Verify Service Startup
After installation, check the status bar for the Barcode Scanner app service icon
If the icon is not visible, open the app from the launcher menu
The main activity will display the service status and WebSocket connection info
Verify that the service icon (camera icon) is present in the status bar
If an external connection has been established, the notification center will display the connection status
Step 3: Simulate External Connection Using Postman
Open Postman on your computer
Create a new collection
Create a new WebSocket request
Enter the WebSocket URL with the device IP and port (found in the app's main activity screen)
Click Connect to establish the WebSocket connection
You should see a successful connection message
Step 4: Use Case 1 - Successful readScannerData
In Postman, send the following command as a simple string (not JSON):
readScannerData
Confirm the command has been sent successfully in Postman
The app will initiate a scan. Present a barcode or QR code at the bottom of the device so the reader can scan it
You should receive a response in Postman with the scanned data
Success Response
{
"status": "success",
"data": "<scanned-barcode-data>"
}
Step 5: Use Case 2 - Aborted Scan
This use case demonstrates how to abort a scan operation using cancelRead.
Send the readScannerData command:
readScannerData
Before scanning a barcode, send the cancelRead command:
cancelRead
You should receive the cancel confirmation:
json { "status": "success", "data": "Read operation canceled" }
You should also receive a response to the initial read command:
json { "status": "error", "data": "No data read from scanner" }
Step 6: Use Case 3 - Unsupported Device
This use case demonstrates what happens when you attempt to use the scanner on a device that does not support barcode scanning hardware.
Send the readScannerData command on a device without scanner hardware
You will receive a response indicating a fatal error:
json { "status": "fatal", "data": "Scanner not supported" }
Command Reference
| Command | Description | Response |
|---|---|---|
readScannerData | Initiates a barcode scan | Success with data or error |
cancelRead | Cancels an ongoing scan | Success confirmation |
Response Status Types
| Status | Description |
|---|---|
success | Operation completed successfully |
error | Recoverable error occurred |
fatal | Unrecoverable error (e.g., unsupported hardware) |
Summary
You have learned how to:
- Install and verify the Barcode Scanner app
- Connect and interact with the app using Postman
- Send commands and handle responses for successful, aborted, and unsupported scan operations