Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim Scanner As Serial
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim BarcodeData As AsyncStreams
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")
Scanner.Initialize("Scanner")
End Sub
Sub Activity_Resume
CallSub(Null, ScanForBC)
End Sub
Sub Activity_Pause(UserClosed As Boolean)
Scanner.Disconnect
End Sub
Sub ScanForBC
If Scanner.IsEnabled Then
Dim Devices As Map = Scanner.GetPairedDevices
For i = 0 To Devices.Size - 1
Dim DeviceName As String = Devices.GetKeyAt(i)
If DeviceName.StartsWith("CT10") Then ' CT10 = The start of my barcode scanner name(CT1013720208)
Log(Scanner.Name)
Log(Devices.GetValueAt(i))
Scanner.Connect2(Devices.GetValueAt(i), "00001101-0000-1000-8000-00805F9B34FB")
End If
Next
End If
End Sub
Sub Scanner_Connected(Success As Boolean)
If Success Then
Scanner.Listen
BarcodeData.Initialize(Scanner.InputStream, Scanner.OutputStream, "BarcodeData")
ToastMessageShow("Barcode scanner connected OK", False)
Else
ToastMessageShow("Connection error.", False)
End If
End Sub
Sub BarcodeData_NewData(Buffer() As Byte)
Dim Barcode As String = BytesToString(Buffer, 0, Buffer.Length, "UTF8")
ToastMessageShow(Barcode.Trim, False)
End Sub
Sub BarcodeData_Error
'ToastMessageShow("Data error.", False)
End Sub