Incorrect characters in transmitted data string

lscott

Member
Licensed User
Longtime User
Very new to B4A but starting to make good progress.

I have a simple network program to transmitt a built up string.
The string includes some hex characters and some text characters.The character string I should be receiving at the PC server end is:
Hex 02D0000C01013030C086 but what I receive is: Hex 023F000C0101303030303F3F.
The vairables I have defined as CMD_LOGIN (0xD0),crcu(0hC0) and crcl (0x86) all get converted to 0x3f the ? character. Not sure if the accures in the building of the string or at time of transmitting the buffer.

Thanks for any ideals.
ScttH.
 

Attachments

Array of Bytes

Thanks Erel for the info.

I built my command packet into an array of bytes. When I pass this to the Astream.write I get an exception message (java.lang.number format exception). I guess I am doing something fairly stupid. One other thing I was trying to send packet to a sub (SendData) but also had a number format issue.
Any direction would help.Thanks again

Sub btnSendMsg_Click


Dim packet(10) As Byte

Dim crcu As Byte:crcu = 0xc0
Dim crcl As Byte:crcl = 0x86
Dim STX As Byte:STX = 0x02
Dim CMD_LOGIN As Byte:CMD_LOGIN = 0xD0

' original string
'login_str = Chr(STX) & Chr(CMD_LOGIN) & Chr(0) & Chr(12) & Chr(1) & Chr(1) & "0000" & Chr(crcu) & Chr(crcl)
' build a packet array of bytes
packet(0) = STX
packet(1) = CMD_LOGIN
packet(2) = 0x00
packet(3) = 0x0C
packet(4) = 0x01
packet(5) = 0x01
packet(6) = "0000"
packet(7) = crcu
packet(8) = crcl

Dim bconv As ByteConverter
Dim buffer As Byte
If Socket1.Connected = True Then
Try
btnSendMsg.Text = buffer
TcpStreams.Write(packet)
Catch
Log("TcpStreams.Write Error")
Msgbox(LastException.Message, "Error connecting")
End Try
Else
Log("Connection lost")
Socket1.Close
Msgbox("Closing Socket", "Connection:")

End If

'SendData (packet)

End Sub
 
Upvote 0
Back
Top