Working with variables across cogs- what am I missing?
Rforbes
Posts: 281
Hey all,
I'm trying to figure out a better/more efficient way of working with variables.
My main object looks like this:
My Comms object looks like this:
I actually need to get about 60 longs into my "Main_comms" method for transmission via the serial.
What can I do to get my Main_comms method to have access to all 60 longs without passing them via parameters? Is there a simple way to achieve this? (Main_comms needs to be ran in a separate cog so that the loop continually monitors for an incoming start signal.)
Thanks in advance
Robert
I'm trying to figure out a better/more efficient way of working with variables.
My main object looks like this:
PUB Main Comms.Start(@Level_Status,@Sigstr,@IO_0_Status[2],@IO_1_Status[2],@IO_2_Status[2],@IO_3_Status[2],@IO_4_Status[2],@IO_5_Status[2],@IO_6_Status[2],@IO_7_Status[2],@IO_8_Status[2],@IO_9_Status[2],@IO_10_Status[2],@IO_11_Status[2])
My Comms object looks like this:
OBJ xfds: "FullDuplexSerial" VAR long Cog long Stack[60] PUB Start(Level,Signal,IO0,IO1,IO2,IO3,IO4,IO5,IO6,IO7,IO8,IO9,IO10,IO11) Stop Cog:=cognew(Main_comms(Level,Signal,IO0,IO1,IO2,IO3,IO4,IO5,IO6,IO7,IO8,IO9,IO10,IO11),@Stack)+1 PUB Stop if Cog cogstop(Cog~-1) PUB Main_comms(Level,Signal,IO0,IO1,IO2,IO3,IO4,IO5,IO6,IO7,IO8,IO9,IO10,IO11)|Poke xfds.Start(26,27,0,9600) '(RXpin, TXpin, Mode, Baud) ' This gets FullDuplexSerial going repeat Poke:=xfds.rxTime(10) If Poke=="!" xfds.tx(long[Level]) xfds.tx(long[Signal]) ''etc etc
I actually need to get about 60 longs into my "Main_comms" method for transmission via the serial.
What can I do to get my Main_comms method to have access to all 60 longs without passing them via parameters? Is there a simple way to achieve this? (Main_comms needs to be ran in a separate cog so that the loop continually monitors for an incoming start signal.)
Thanks in advance
Robert
Comments
(Thanks for looking! Hopefully I got this figured out.)
Then instead of:
Use:
If you increase the index by one instead of four, you'll send all the data.
If you want to use ASCII characters for your data, the infor is usually kept in arrays of bytes.
If you used "dec" instead of "tx" you'd send ASCII characters (up to ten) of the decimal value.