Hello All,
I am implementing a communications routine with an ATM pinpad.
I receive a string of bytes thru the socket newdata event, but I need to convert the first 4 bytes to int + the next 4 bytes to int and the remaining ones to charachters to read the receipt in plain text
The first 4 bytes contain the ResultCode of the transaction
the next 4 bytes contain the lenght of the following data
the remaining bytes are to be converted to text and contain the receipt data
Hi Erel,
I just did that, but when i read the int at position 1 i should get 10, equivalente to 0A in hex, but I get 0.
but the hexfrombytes functions reads the correct value in Hex. Any idea Why ?
B4X:
Dim Raf As RandomAccessFile
Raf.Initialize3(Buffer,True)
Dim ResCode As Int=Raf.ReadInt(1)
Log(ResCode)
Private IngenicoReply As String=BtCvt.HexFromBytes(Buffer)
Log(IngenicoReply)
It All works now woth the exception of String,as I said earler I need to read:
The first 4 bytes contain the ResultCode of the transaction (Int)
the next 4 bytes contain the lenght of the following data (Int)
the remaining bytes are to be converted to text and contain the receipt data (String)
I am using the following code But I keep getting a out of bounds error due to the size of the text
B4X:
Dim Raf As RandomAccessFile
Raf.Initialize3(Buffer,True)
Dim OperationResult As Int=Raf.ReadInt(0)' Reads the first 4 bytes
Dim TextLen As Int=Raf.ReadInt(4) 'read the second 4 bytes
Dim Receipt As String=Raf.ReadObject(8) ' should read all text from postion 8 until the end of the array, right ?
1. ReadObject has nothing to do with strings. Tip: there is never a good reason to use raf.ReadObject.
2. You should use RAF.CurrentPosition.
3.
B4X:
Dim Raf As RandomAccessFile
Raf.Initialize3(Buffer,True)
Dim OperationResult As Int=Raf.ReadInt(Raf.CurrentPosition)' Reads the first 4 bytes
Dim TextLen As Int=Raf.ReadInt(Raf.CurrentPosition) 'read the second 4 bytes
Dim b(Raf.Size - Raf.CurrentPosition) As Byte
raf.ReadBytes(b, 0, b.Length, Raf.CurrentPosition)
Log(BytesToString(b, 0, b.Length, "ASCII"))