Printing in COGS?
egeis
Posts: 5
I recently ran into an issue working with cogs and printing to the terminal and writing to the XBEE terminal. While the writeline and printf lines work inside of the int main(), I'm guessing this would be cog0, they ceased functioning when added to the other cogs.
This is a sample of the code i'm
I have tried finding information in learn.parallax and read some posts on this forum but cannot seem to find a solution. Without a book to refer to like the Boe-Bot or reference material beyond a sites.google entry for the propeller C files I am lost on how to solve this issue.
This is a sample of the code i'm
int main() { //Start up XBEE xb = fdserial_open(rx_pin, tx_pin, 0, baud); int cog_scan_id = cogstart(&scanner, NULL, stack, sizeof(stack)); while(1) { //Does other stuff } } void scanner(void *par) { while(1) { int i; for(i = 0;i<4;i++) //pins 0-3 { q[i] = qti(i); pause(1); } //TODO: Identify Changes. print("test\n"); sprintf(buf, "[QTI_DEBUG] %d %d %d %d", q[3], q[2], q[1], q[0]); writeLine(xb, buf); } }
I have tried finding information in learn.parallax and read some posts on this forum but cannot seem to find a solution. Without a book to refer to like the Boe-Bot or reference material beyond a sites.google entry for the propeller C files I am lost on how to solve this issue.
Comments
Welcome to the forums.
Function print() does not use a separate cog unless it is re-opened as fdserial. We are adding some things to make that easier to do.
Add this code.
Result: I get on the terminal "Start Main" followed by "SSttaarrtt bblliinnkk1500000" - it alternated the characters output from blink1000 and blink500. Sort of cool, but not desired.
My guess is cog1 and cog2 are using same port? In a hazy way I am thinking make two ports available? Currently is just the one re-directed from debug port?
Thanks.
John,
This is where you need to use mutex locks to ensure that output is coherent. I don't have any examples at the moment. Generally, one acquires a lock, does work, and then releases the lock.
Maybe you should ask Andy for some support in this.
My objective is a short guide for people coming from PBASIC to C. I am comfortable noting that certain things are hard in C - accept it and work around.
Andy is working these weeks on some teaching materials so I'll hold off on pursuing this with him.
Only a couple of topics left on my list for the guide and then ver 01 posted for feedback (and tested in a Prop class I'm trying on a trial run). Hopefully a lot of answers will be found there and less posted here. Most importantly I want someone from STAMP to be able to take the guide and have pretty quick success with Prop C.