CODE: xxxx.bas
'--------------------------------
' dumpBuff will dump in hex and char the content of an IOBuffer for length bytes
' Output on serial port
'
'------------------------------
demo:
IOBUFF.DIM(0,113)
for i=0 to IoBuff.len(0)-1
iobuff.write(0,i,rnd(255)) 'Demo: fill with random numbers
next i
dumpBuff 0,96 ' multiple of 16
dumpBuff 0,120 ' note 120 exeed buff length
dumpBuff 0,7 ' not multiple of 16
dumpBuff 1,16 ' empty (nil)
'
IOBUFF.DIM(2,90)
for i=0 to IoBuff.len(2)-1
iobuff.write(2,i,rnd(255)) 'Demo: fill with random numbers
next i
dumpBuff 2,35 ' multiple of 16
dumpBuff 2,120 ' note 120 exeed buff length
dumpBuff 2,27
enddemo:
End
'----------------------helper
Sub dumpBuff(number,length) 'Dump content of IOBuff number for length bytes
Local A$, B$, value, i, j, s, buffLen
buffLen=IoBuff.len(number)
Print "" : Print""
Print Space$(10)+"BUFFER :",number
Print " 0 1 2 3 4 5 6 7 8 9 A B C D E F 0 1 2 3 4 5 6 7 8 9 A B C D E F"
i=0
Do While (i+j < buffLen) And (i+j < length)
A$=Space$(0) : B$=A$
j=0
Do While ((i+j < buffLen) And (i+j < length) And (j<16))
value = IoBuff.Read(0,(i+j))
A$=A$ + " " + STR$(value, "%02X", 1)
If value < 32 Or value > 126 Then
B$=B$ + " " + "."
Else
B$=B$ + " " + Chr$(value)
EndIf
j=j+1
Loop
s=3
If j<> 15 Then s=(16-j)*3+s
A$=STR$((i), "%08X", 1) + " " + A$ + Space$(s) + B$
Print A$
i=i+16 : j=0
Loop
End Sub