Good Morning,
Can someone steer straight (again - sob sob - soz)
I am trying to send a single unsigned byte (higher than 128) to my microcontroller but couldn't (and couldn't figure out how to change a signed byte to an unsigned one).
so I used the binary pattern equivalent and used negative numbers in B4A.
Anyway - the following code is supposed to send a single byte from a button press, but the compiler grumbles with a
java.lang.ArrayIndexOutOfBoundsException: length=0; index=0
at buffer(0)= -15
Any/All help gratefully appreciated.
Cheers.
Can someone steer straight (again - sob sob - soz)
I am trying to send a single unsigned byte (higher than 128) to my microcontroller but couldn't (and couldn't figure out how to change a signed byte to an unsigned one).
so I used the binary pattern equivalent and used negative numbers in B4A.
Anyway - the following code is supposed to send a single byte from a button press, but the compiler grumbles with a
java.lang.ArrayIndexOutOfBoundsException: length=0; index=0
at buffer(0)= -15
Any/All help gratefully appreciated.
Cheers.
B4X:
Sub Button_Click
'BT transmission protocol from tablet TO base unit (one byte)
'81 (Start game 1) Or 82 (Start game 2) Or 83 (Start game 3)
'8F (Stop current game)
Dim buffer(0) As Byte
If Button.Text="START" And TLRB.Checked=True Then
buffer(0) = -2
Else If Button.Text="START" And CNRB.Checked=True Then
buffer(0) = -3
Else If Button.Text="START" And BCRB.Checked=True Then
buffer(0) = -1
Else If Button.Text="STOP" Then
buffer(0) = -15
End If
AStreams.Write(buffer)
End Sub