D
Deleted member 103
Guest
Hi,
I have derived the classe, here below, from the classe AsyncStreamsText, but I do not understand the different way in which "BytesToString" works.
For B4a I can use "UTF8" as a charset, but not for B4i because it crashes.
But if I use "iso-8859-1" in B4i as charset, then everything is alright.
The data comes from the same BLE module, so everything should be the same, right?
Is there a logical explanation?
I have derived the classe, here below, from the classe AsyncStreamsText, but I do not understand the different way in which "BytesToString" works.
For B4a I can use "UTF8" as a charset, but not for B4i because it crashes.
But if I use "iso-8859-1" in B4i as charset, then everything is alright.
The data comes from the same BLE module, so everything should be the same, right?
Is there a logical explanation?
B4X:
Sub Class_Globals
Private mTarget As Object
Private mEventName As String
Private sb As StringBuilder
#if b4a
Private charset As String = "UTF8"
#Else
Private charset As String = "iso-8859-1"
#End If
End Sub
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(TargetModule As Object, EventName As String)
mTarget = TargetModule
mEventName = EventName
sb.Initialize
End Sub
Public Sub NewData (Buffer() As Byte)
Dim newDataStart As Int = sb.Length
sb.Append(BytesToString(Buffer, 0, Buffer.Length, charset))
Dim s As String = sb.ToString
Dim start As Int = 0
For i = newDataStart To s.Length - 1
Dim c As Char = s.CharAt(i)
If i = 0 And c = Chr(10) Then '\n...
start = 1 'might be a broken end of line character
Continue
End If
If c = Chr(10) Then '\n
CallSubDelayed2(mTarget, mEventName & "_NewText", s.SubString2(start, i))
start = i + 1
Else If c = Chr(13) Then '\r
CallSubDelayed2(mTarget, mEventName & "_NewText", s.SubString2(start, i))
If i < s.Length - 1 And s.CharAt(i + 1) = Chr(10) Then '\r\n
i = i + 1
End If
start = i + 1
End If
Next
If start > 0 Then sb.Remove(0, start)
End Sub
Application_Start
Application_Active
pnlRoot_Resize
IsOrientationChanged=true
pnlRoot_Resize: IsListCronoTimerChanged=true
btnCronoModus_CheckedChange=false
pnlRoot_Resize
IsOrientationChanged=true
pnlRoot_Resize: IsListCronoTimerChanged=true
btnCronoModus_CheckedChange=false
Discovering services
Services discovery completed.
Error occurred on line: 21 (clsAsyncText)
Error decoding data as string.
Stack Trace: (
CoreFoundation <redacted> + 252
libobjc.A.dylib objc_exception_throw + 56
CoreFoundation <redacted> + 0
CMM-Lite -[B4ICommon BytesToString::::] + 344
CoreFoundation <redacted> + 144
CoreFoundation <redacted> + 292
CMM-Lite +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1624
CMM-Lite -[B4IShell runMethod:] + 448
CMM-Lite -[B4IShell raiseEventImpl:method:args::] + 1640
CMM-Lite -[B4IShellBI raiseEvent:eventarams:] + 1372
CMM-Lite +[B4IDebug delegate:::] + 80
CMM-Lite -[b4i_clsasynctext _newdata::] + 432
CMM-Lite -[b4i_clsbluetooth _dataavailable_new:::] + 1084
CMM-Lite -[b4i_clsbluetooth _btmanager_dataavailable:::] + 756
CoreFoundation <redacted> + 144
CoreFoundation <redacted> + 292
CMM-Lite +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1624
CMM-Lite -[B4IShell runMethod:] + 448
CMM-Lite -[B4IShell raiseEventImpl:method:args::] + 2164
CMM-Lite -[B4IShellBI raiseEvent:eventarams:] + 1372
CMM-Lite +[B4IObjectWrapper raiseEvent:::] + 300
CMM-Lite -[BlePeripheralDel peripheral:didUpdateValueForCharacteristic:error:] + 1276
CoreBluetooth <redacted> + 240
CoreBluetooth <redacted> + 132
CoreBluetooth <redacted> + 356
CoreBluetooth <redacted> + 204
CoreBluetooth <redacted> + 60
libdispatch.dylib <redacted> + 24
libdispatch.dylib <redacted> + 16
libdispatch.dylib <redacted> + 592
libdispatch.dylib <redacted> + 484
libdispatch.dylib <redacted> + 784
CoreFoundation <redacted> + 12
CoreFoundation <redacted> + 1964
CoreFoundation CFRunLoopRunSpecific + 436
GraphicsServices GSEventRunModal + 100
UIKitCore UIApplicationMain + 212
CMM-Lite main + 124
libdyld.dylib <redacted> + 4
)
Application_Active
pnlRoot_Resize
IsOrientationChanged=true
pnlRoot_Resize: IsListCronoTimerChanged=true
btnCronoModus_CheckedChange=false
pnlRoot_Resize
IsOrientationChanged=true
pnlRoot_Resize: IsListCronoTimerChanged=true
btnCronoModus_CheckedChange=false
Discovering services
Services discovery completed.
Error occurred on line: 21 (clsAsyncText)
Error decoding data as string.
Stack Trace: (
CoreFoundation <redacted> + 252
libobjc.A.dylib objc_exception_throw + 56
CoreFoundation <redacted> + 0
CMM-Lite -[B4ICommon BytesToString::::] + 344
CoreFoundation <redacted> + 144
CoreFoundation <redacted> + 292
CMM-Lite +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1624
CMM-Lite -[B4IShell runMethod:] + 448
CMM-Lite -[B4IShell raiseEventImpl:method:args::] + 1640
CMM-Lite -[B4IShellBI raiseEvent:eventarams:] + 1372
CMM-Lite +[B4IDebug delegate:::] + 80
CMM-Lite -[b4i_clsasynctext _newdata::] + 432
CMM-Lite -[b4i_clsbluetooth _dataavailable_new:::] + 1084
CMM-Lite -[b4i_clsbluetooth _btmanager_dataavailable:::] + 756
CoreFoundation <redacted> + 144
CoreFoundation <redacted> + 292
CMM-Lite +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1624
CMM-Lite -[B4IShell runMethod:] + 448
CMM-Lite -[B4IShell raiseEventImpl:method:args::] + 2164
CMM-Lite -[B4IShellBI raiseEvent:eventarams:] + 1372
CMM-Lite +[B4IObjectWrapper raiseEvent:::] + 300
CMM-Lite -[BlePeripheralDel peripheral:didUpdateValueForCharacteristic:error:] + 1276
CoreBluetooth <redacted> + 240
CoreBluetooth <redacted> + 132
CoreBluetooth <redacted> + 356
CoreBluetooth <redacted> + 204
CoreBluetooth <redacted> + 60
libdispatch.dylib <redacted> + 24
libdispatch.dylib <redacted> + 16
libdispatch.dylib <redacted> + 592
libdispatch.dylib <redacted> + 484
libdispatch.dylib <redacted> + 784
CoreFoundation <redacted> + 12
CoreFoundation <redacted> + 1964
CoreFoundation CFRunLoopRunSpecific + 436
GraphicsServices GSEventRunModal + 100
UIKitCore UIApplicationMain + 212
CMM-Lite main + 124
libdyld.dylib <redacted> + 4
)