- Tue Aug 09, 2016 12:13 pm
#52570
Bugs-
Below is my current code which has your suggestions as well as 2 new serial commands courtesy from Mike.
Code: Select allserialbranch [serialin]
wait
[serialin]
ID$ = ""
Do
ID$ = str(serial.read.int()) & ID$
Loop while serial.available()
print "received:" & ID$
'dimension string and numeric arrays
dim a$(5)
dim b(5)
'split the input string into pairs of ASCII characters
'i = 0
for ptr = 0 to 4
a$(i) = mid(ID$,ptr,1)
'store the numeric values of the hex
b(ptr) = hextoint(a$(ptr))
' i = i+1
next ptr
'calculate the crc - using the DECIMAL equivilent characters (works with calculator)
crc = b(0) xor b(1) xor b(2) xor b(3)
if crc <> b(4) then
print "bad data"
else
print "ok"
'reconstruct the hex value (without the spaces)
tag$ = a$(0) & a$(1) & a$(2) & a$(3)
print "tag is:" & hextoint(tag$)
endif
end
The 2 new commands are
str(serial.read.int()
serial.available()
which come out of the ESP-duino stuff I was told.
When I run this my result is:
received:1341111071300 - I don't know why this is backwards.......
My serial eavesdropper gets this: 00 82 6B 6F 86 (spaces are for clarity only). 1st 4 bytes are for the Tag ID, 5th is checksum.
So the decimal equivalent should be: 8547183 which is exactly what the tag should read.
The program waits a bit and then prints:
ok
and then it prints
tag is:0
So, I understand what you are doing with the arrays but I still don't know how to get the hex correct so I can then strip off the 0x86 (in this example) and generate my own checksum for comparison to ensure a good read and good tag data.
THEN, generate the tag ID in decimal from the 4 hex digits.
BTW, without the 2 new commands, I was not getting anything from the reader - Thanks Mike!
If we knew what we were doing, it wouldn't be called research.
- Albert Einstein