how to send bytes (not ASCII)

Electrocutioner

Member
Licensed User
Longtime User
Hi,

ive been searching and I can't find the exact answer. I need to construct a command string.

The following code sends numbers as ascii. for example the number 50 is sent as ascii '5' then ascii '0' as it would be typed on a keyboard. My question is how would I send byte values? so if i send 50, it sends the value 50 as 8 bit code. Are there other options besides "UTF8"?


B4X:
Dim sb As StringBuilder
Dim cmd_String As String
Dim buffer() As Byte

sb.Initialize
sb.append(A) .append(B) .append(C)

cmd_String = sb.ToString

buffer=cmd_String.GetBytes("UTF8")
AStream.Write(buffer)


End Sub

thanks!
 

Electrocutioner

Member
Licensed User
Longtime User
sorry Erel im still confused

B4X:
Sub send_CMD_String

Dim sb As StringBuilder
Dim cmd_String As String
Dim teststring As String

Dim Bytes () As Byte = Array As Byte(50)

Bytes(0) = A
Bytes(1) = B
Bytes(2) = C

AStream.Write(Bytes)

I need to send for example if the variable is 50, I need to send integer 50 and not '5' then '0'
 
Upvote 0

Beja

Expert
Licensed User
Longtime User
Hi Electrocutioner,

I don't get it!! why would you declare an array that is not used (Array As Byte(50))

but may be you try to dimension the bytes array with actual range.. for example:
DIM bytes (0 to 2) AS Byte
or
DIM bytes (3) AS Byte

Another thing,
I think you should put it like this:

bytes(0) = &H0A (instead of bytes(0) = A)
because "A" is a string value and can not be assigned to a byte type array element.
This is what I think and after all we are in a free country
 
Last edited:
Upvote 0

Electrocutioner

Member
Licensed User
Longtime User
Please look at the first post. A, B, and C are variables.

So say I have a screen which the user enters values for A, B, and C.

Then I would like to send the data accross bluetooth in a command string.

for example if A=30, B=40, C=50 the output stream is 33 30 34 30 35 30.

but what i really want is to send 30, 40, and 50.

I hope this makes sense to someone.
 
Upvote 0

Electrocutioner

Member
Licensed User
Longtime User
I have figured it out.
simply send the ascii value.
Hopefully this will help someone.

B4X:
Dim sb As StringBuilder
Dim cmd_String As String
Dim buffer() As Byte
sb.Initialize
sb.append(chr(A)) .append(chr(B)) .append(chr(C))
cmd_String = sb.ToString

buffer=cmd_String.GetBytes("UTF8")
AStream.Write(buffer)
End Sub

Thanks everyone for your help!
 
Upvote 0
Top