Whats wrong with my loop using the FullDuplexSerial and 6 other cogs
grasshopper
Posts: 438
I am using several cogs so far and this is my last bug. I am tring to run a display stand alone with main code, but yet keep the communications open on the cog that fullserialduplex is running on; instead of a infinite loop in my main code (with display and other code) with if statements that can break the loop.
here is the main code
but then i had to modify the FullSerialDuplex object because it runs on a stand alone cog so i figured i could streamline things by adding this little method to the object.
i also tryed doing a
That did not work either.
Let me know if there is a better way going about this. or if you see something that can help me.
Post Edited (grasshopper) : 6/24/2008 11:21:30 PM GMT
here is the main code
Pub main ser.start(31,30,0,baud) lcd.init REPEAT Display(0) if (ser.lib == 1) ser.str(string("ok")) if (ser.lib == 2) ser.str(string("ok2"))
but then i had to modify the FullSerialDuplex object because it runs on a stand alone cog so i figured i could streamline things by adding this little method to the object.
pub lib : Rxstring | RxDat [noparse][[/noparse] 18 ] , stringCount Rxstring~~ StringCount~ repeat until (RxDat[noparse][[/noparse]StringCount] := rx ) == ")" StringCount ++ IF (rxDat [noparse][[/noparse] 0 ] == "(")&(rxDat [noparse][[/noparse] 1 ] == "F")&(rxDat [noparse][[/noparse] 2 ] =="1")* (rxDat [noparse][[/noparse] 3 ] == $20) IF (rxDat [noparse][[/noparse] 4 ] == "I")&(rxDat [noparse][[/noparse] 5 ] == "D")&(rxDat [noparse][[/noparse] 6 ] ==$20)&(rxDat [noparse][[/noparse] 7 ] == "?") rxString := 1 IF (rxDat [noparse][[/noparse] 4 ] == "V")&(rxDat [noparse][[/noparse] 5 ] == "N")&(rxDat [noparse][[/noparse] 6 ] ==$20)&(rxDat [noparse][[/noparse] 7 ] == "?") rxString := 2
i also tryed doing a
if (ser.rxcheck > -1) < run commands here >
That did not work either.
Let me know if there is a better way going about this. or if you see something that can help me.
Post Edited (grasshopper) : 6/24/2008 11:21:30 PM GMT
Comments
I am running a "main" program that in turns monitors 7 other cogs and in the "main" program i had this statement
rxdat [noparse][[/noparse] 20 ] is my array
stringcount increments the array so the characters can be separated later for a command structure library.
the if statements do the logic "filtering" and RxString is my output command for "main" code to execute using more logic.
basically puts the ser.RX into an array where i can decipher it as various commands. The problem is that my "main" code will run until it gets to this line
Then it stops and waits. Well i want other things in my main code to keep running. For example: to up date my display. Also what if i get no command through the serial port. I don't want the code to sit her for ever unless I get a command. Ther must be a different way to use the FullDuplexSerial object and still filter out strings of commands. Some of this will include the example you helped me out with - numbers to floating point.
So I have tried to modify the FullDuplexSerial object by putting the above code (my first post) in the object. My logic was that since the cog was running may as well put this type of string filter in it. But i am still have the wait problem in my main code.
hope this is a better explanation
Post Edited (grasshopper) : 6/25/2008 12:06:56 AM GMT
repeat
if variable == waitforstart
if ser.rxcheck == startchar
variable := incommand
startcount := 0
buffer[noparse][[/noparse]startcount++] := startchar
else
if char := ser.rxcheck > -1
buffer[noparse][[/noparse]startcount++] := char
if char == endchar
processcommand in buffer
variable := waitingforstart
do other stuff
It's possible to have FullDuplexSerial do the format checking (like for the ")"), but you'd have to do it in assembly since that's what's running in the cog that FullDuplexSerial starts. The Spin code in FullDuplexSerial runs in the same cog as the part of your program that calls it (probably the main cog).
...stay tuned for more questions on this topic. I have actual done some of this type of checking and still it did not work correctly, however you both have cause a light bulb to shine brighter and thus i shall try yet again.
Special thanks to Mike Green - You have thought me more in the last few days than any book or person.
I have accomplished a PID controlled 4 channel temperature control station +/- .04 degrees, with 3 independent motors that have variable speeds, and 2 com ports 1 serial and 1 usb along with EEPROM read/write abilities and a 2x20 lcd display.
Phew thanks...
My confidence as a new electronics designer is growing.