Android Question Sending ASCII Bytes 0 - 255 on bluetooth

dara hayes

Member
Licensed User
Longtime User
As i am using the Bluetooth Async stream I am using Byte arrays to send my data , I need to send values from 0-255 values and have been looking on the various posts regarding sending ASCII values , many of the examples I have tried , .GetBytes(UTF-8) etc etc don't seem to work for me , I dont get the simple ASCII values I need, so I have reverted to defining an array the particular length of each of my various length command strings that I need for the individaul commands and manually filling each byte with the values required , e.g

code

Dim buff(4) as byte array
Buff(0) =0xF0
Buff(1)= 0x02
Buff(2)= 0x80
Buff(3)= 0x0A 'terminator value

AStream.Write(buffer)
____________________________________________

This method works fine but I would like to 'programatically' stuff my command strings with ASCII values and I have tried the following

code

Dim sb As StringBuilder
Dim cmd_String As String
Dim buffer() As Byte
sb.Initialize

sb.append( Chr(0xF0)) .append(Chr(0x02)) .append(Chr(0x80)) .append(Chr(0x0A))
cmd_String = sb.ToString

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

I now understand why this second method doesn't work but can anyone suggest a means of doing it so I only get my ASCII values in the command string (byte array) to transmit across the Bluetooth link other manual byte array stuffing methods I have tried work but always send the full declared length of the buffer which I define for the longest possible command string I will need , however when I only use 6 bytes of out a possible 16 it always sends a pile of zeros after the 6 bytes so do I have to declare the exactly length of byte array each time and fill them manually ... .in order to get 0-255 values sent across the link when I write an array of bytes to the output stream.
 

dara hayes

Member
Licensed User
Longtime User
ok thats fine
simply declare it every time I want to send a command message
and the buffer will only be as long as one needs
and I assume it is discarded as soon as the procedure completes
that is great thanks for that Erel
 
Upvote 0
Top