Ho visto che mi hai risposto dall' altra parte, grazie ancora
Ho provato ad implementare il tuo codice, ma il programma esce dicendomi "Unfortunatley B4A Example has stopped". Se vado a leggere il log di debug, mi dà un errore alla riga 77 ossia:
LogCat connected to: emulator-5554
--------- beginning of /dev/log/main
--------- beginning of /dev/log/system
java.lang.RuntimeException: java.io.EOFException
at anywheresoftware.b4a.shell.Shell.virtualAssets(Shell.java:159)
at anywheresoftware.b4a.shell.Shell.start(Shell.java:91)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:76)
at b4a.example.main.afterFirstLayout(main.java:90)
at b4a.example.main.access$100(main.java:16)
at b4a.example.main$WaitForLayout.run(main.java:76)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.io.EOFException
at libcore.io.Streams.readFully(Streams.java:83)
at java.io.DataInputStream.readInt(DataInputStream.java:103)
at anywheresoftware.b4a.shell.Shell.virtualAssets(Shell.java:131)
... 14 more
Copying updated assets files (1)
** Activity (main) Create, isFirst = true **
Error occurred on line: 77 (main)
java.lang.NumberFormatException: Invalid double: "x"
at java.lang.StringToReal.invalidReal(StringToReal.java:63)
at java.lang.StringToReal.parseDouble(StringToReal.java:269)
at java.lang.Double.parseDouble(Double.java:295)
at b4a.example.main._crc(main.java:386)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:636)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:305)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:238)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:121)
at b4a.example.main.afterFirstLayout(main.java:98)
at b4a.example.main.access$100(main.java:16)
at b4a.example.main$WaitForLayout.run(main.java:76)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
** Activity (main) Resume **
Il codice che ho scritto io è il seguente:
#Region Project Attributes
#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
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.
Private Button1 As Button
Private EditText1 As EditText
Private EditText2 As EditText
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")
Activity.LoadLayout("Main")
EditText1.Text = "0x19 0x03 0x00 0x44 0x 00 0x03"
CRC(EditText1.Text)
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Button1_Click
End Sub
Sub CRC(DialString As String) As String
Dim Res As String
Dim G As Long, A As Long, AUX As Long
Dim ALow As Long, AHigh As Long, AL As Long
Dim Carry As Int
Dim i, J As Int
Dim cA As Long
A = 65535
G = 40961
i = 0
Do While i < DialString.Length
J = 0
ALow = A / 256
ALow = ALow * 256
ALow = A - ALow
AHigh = (A / 256) * 256
'cA = Asc(Mid$(DialString, i + 1, 1))
cA = DialString.SubString2(i, i + 1)
AL = Bit.Xor(cA, ALow)
AUX = AHigh + AL
A = AUX
Do While J < 8
J = J + 1
AUX = A
A = A / 2
Carry = AUX Mod 2
If Carry = 1 Then
A = Bit.Xor(G, A)
End If
Loop
i = i + 1
Loop
ALow = A - (A / 256) * 256
AHigh = A / 256
Res = Chr(ALow) & Chr(AHigh)
' Return Res
EditText2.Text = Res
End Sub