Evening guys,
The code below throws up an error when trying to send a byte via usb
I know somethings wrong - what have i done or not done here.
Thanks in advance
Steve
Logger connected to: Fusion5 Fusion5_F104Bv2
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
2
130
Error occurred on line: 331 (Main)
java.lang.Exception: hex string has odd number of characters
at anywheresoftware.b4a.agraham.byteconverter.ByteConverter.HexToBytes(ByteConverter.java:254)
at Target.Game.main._timer2_tick(main.java:1178)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.objects.Timer$TickTack.run(Timer.java:105)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6548)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:857)
The code below throws up an error when trying to send a byte via usb
I know somethings wrong - what have i done or not done here.
Thanks in advance
Steve
B4X:
Private Sub Timer2_Tick 'used to send data to controller in 2 seconds
Timer2.Enabled=False 'switch timer off
tx = Bit.ShiftLeft(tx,1) 'tx is a string
Log(tx) 'prints the correct #
tx=Bit.Or(tx,0x80) 'is correct 02 becomes 130 (0x82)
Log(tx)
Dim t() As Byte = bc.HexToBytes(tx) 't becomes a byte to send - CRASH
If usbserial.IsInitialized Then
usbserial.Write(t)
End If
End Sub
Logger connected to: Fusion5 Fusion5_F104Bv2
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
2
130
Error occurred on line: 331 (Main)
java.lang.Exception: hex string has odd number of characters
at anywheresoftware.b4a.agraham.byteconverter.ByteConverter.HexToBytes(ByteConverter.java:254)
at Target.Game.main._timer2_tick(main.java:1178)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.objects.Timer$TickTack.run(Timer.java:105)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6548)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:857)