Hello;
I read RFID tags by RDM6300 module, everything went fine years ago, but recently I've got strange error. I send tag number to serial port. I use NumberFormat to format tag number in 10 digits.
the problem:
this tag number '0009040399' rounded to '0009040400'. listed some read tags with no problems;
i noticed that the tag number starts with '90' unlike others!
here is the code i use to read tags
B4X:
private Sub ReadRFID(Buffer() As Byte)
Dim tmpBuffer (8) As Byte
Dim Str_HexNumber As String
Dim Int_Number As ULong
tmpBuffer= BC.SubString2(Buffer,3,11) 'get card bytes only
Str_HexNumber = BC.StringFromBytes(tmpBuffer)
Int_Number = Bit.ParseInt(Str_HexNumber, 16) 'convert hex to decimal string
Log(NumberFormat(Int_Number,10,0)) ' rounded to 0009040400
Log(Int_Number) ' no problems 9040399
End Sub
Sub Process_Globals
Public Serial1 As Serial
Private PadResult(10) As Byte
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
Pad("920566")
Log(PadResult)
Pad("1")
Log(PadResult)
Pad("1234567890")
Log(PadResult)
End Sub
Sub Pad(Input() As Byte)
For i = 0 To PadResult.Length - 1
If Input.Length - PadResult.Length + i < 0 Then
PadResult(i) = Asc("0")
Else
PadResult(i) = Input(Input.Length - PadResult.Length + i)
End If
Next
End Sub
many thanks Erel, a last question please, tag id is a Ulong variable, how can I pass it to Pad sub as array of bytes i.e. "9040399"? I used this code but i get array length error it seems that it passes 4 bytes of Ulong, not string represented Ulong!
B4X:
Dim strCardArray(10) As Byte = Pad(BC.ULongsToBytes(Array As ULong(Int_Number)))
and I passed it like this and I've got decimal point result
B4X:
Dim tmp_str As String = Int_Number
Dim strCardArray(10) As Byte = Pad(tmp_str.GetBytes)
Dim Number As ULong = 9040399
PadLong(Number)
Log(PadResult)
B4X:
Sub PadLong(Input As ULong)
Dim c As ULong = 1
For i = 0 To PadResult.Length - 1
Dim i2 As ULong = Input / c
PadResult(PadResult.Length - 1 - i) = Asc("0") + (i2 Mod 10)
c = c * 10
Next
End Sub