#Region Service Attributes
#StartAtBoot: False
#End Region
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
Dim BarcodeData As AsyncStreams 'libreria RandomAccessFile
'
End Sub
Sub Service_Create
scanner.Initialize("scanner")
End Sub
Sub Service_Start (StartingIntent As Intent)
If Home.ssl_bluetooth Then CallSub(Null, ScanForBC)
End Sub
Sub Service_Destroy
If Home.ssl_bluetooth Then 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)
'Log (DeviceName)
If DeviceName.ToUpperCase.StartsWith(Home.nome_bluetooth.ToUpperCase.trim) Then ' CT10 = The start of my barcode scanner name(CT1013720208)
scanner.Connect2(Devices.GetValueAt(i), "00001101-0000-1000-8000-00805F9B34FB" )
End If
Next
Else
ToastMessageShow("Lettore Barcode non presente", False)
End If
End Sub
Sub scanner_Connected(Success As Boolean)
If Success Then
scanner.Listen
BarcodeData.Initialize(scanner.InputStream, scanner.OutputStream, "BarcodeData")
ToastMessageShow("Lettore Barcode connesso", False)
Else
ToastMessageShow("Errore connessione con Lettore Barcode. ["&Home.nome_bluetooth&"]", False)
End If
End Sub
Sub BarcodeData_NewData(Buffer() As Byte)
Dim Barcode As String = BytesToString(Buffer, 0, Buffer.Length, "UTF8")
If Main.bluetooth_loc <> Null Or Main.bluetooth_loc <> "" Then
Log("Main.bluetooth_loc = "&Main.bluetooth_loc)
CallSubDelayed2(Main.bluetooth_loc, "read_item_barcode", Barcode)
End If
End Sub
Sub BarcodeData_Error
ToastMessageShow("Lettore Barcode disconnesso", False)
If Home.ssl_bluetooth Then CallSub(Null, ScanForBC)
End Sub
Sub check_scanner As Boolean
If scanner.IsEnabled Then
Dim Devices As Map = scanner.GetPairedDevices
For i = 0 To Devices.Size - 1
Dim DeviceName As String = Devices.GetKeyAt(i)
'Log (DeviceName)
If DeviceName.ToUpperCase.StartsWith(Home.nome_bluetooth.ToUpperCase.trim) Then ' CT10 = The start of my barcode scanner name(CT1013720208)
scanner.Connect2(Devices.GetValueAt(i), "00001101-0000-1000-8000-00805F9B34FB" )
Return True
End If
Next
Return False
Else
ToastMessageShow("Lettore Barcode non presente", False)
Return False
End If
End Sub