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
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'
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
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