Comunications help / using a repeat loop and I am screaming mad!!!!
Zap-o
Posts: 452
Below I am trying to run a loop that can eventiually do other task while waiting to fill a byte array. For some reason I am way out on this one.
Code
I am doing something horribly wrong. I know I can use the strings object but I want to learn on my own.
Code
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 USBRx = 31 USBTx = 30 OBJ Coms : "FullDuplex4" VAR Byte RxData[noparse][[/noparse] 20 ] ,Delimiter Pub Initialize {{Starts Cogs and sets some data structure }} Coms.AddPort(0,USBRX,USBTX,-1,-1,0, %000000,19200) Coms.start MainLoop Pub MainLoop | idx bytefill(@rxData,0,20) idx :=0 Delimiter := "," Repeat IF (Coms.rxCheck(0) > -1) RxData[noparse][[/noparse] idx ] := Coms.Rx(0) idx++ ' Coms.str(0,string("debug")) this works so far IF (RxData[noparse][[/noparse] idx ] == Delimiter) idx := 0 Coms.hex(0,rxData[noparse][[/noparse] 0 ],2) Coms.hex(0,rxData[noparse][[/noparse] 1 ],2) Coms.hex(0,rxData[noparse][[/noparse] 2 ],2) Coms.hex(0,rxData[noparse][[/noparse] 3 ],2) Coms.hex(0,rxData[noparse][[/noparse] 4 ],2) Coms.hex(0,rxData[noparse][[/noparse] 5 ],2) Coms.hex(0,rxData[noparse][[/noparse] 6 ],2) Coms.hex(0,rxData[noparse][[/noparse] 7 ],2) Coms.hex(0,rxData[noparse][[/noparse] 8 ],2) Coms.hex(0,rxData[noparse][[/noparse] 9 ],2) Coms.hex(0,rxData[noparse][[/noparse] 10 ],2)
I am doing something horribly wrong. I know I can use the strings object but I want to learn on my own.
Comments
John Abshier
PUB rxcheck(port) : rxbyte
'' Check if byte received (never waits)
'' returns -1 if no byte received, $00..$FF if byte
So I would use:
ch := com.rxcheck(0)
if ch+1
RxData[noparse][[/noparse] idx ] := ch
An easier way would be to modify you serial object so that you specify the buffer to use which would then be your array.
*Peter*
Peter what is this doing? Forgive me if it seems stupid.
I have never seen this before? I understand the rest of the code you posted but this line has me confused.
You could also use "if ++ch" I guess as this should preincrement then test.
*Peter*
*Peter*
IF (CH is a positive 1)
I was thinking it meant that CH was to be added to 1
I think I understand it now.
*Edited
Could I also sate this:
IF (CH == true)
*Peter*
Thank you kindly.