PDA

View Full Version : propBASIC 'TASK ... ENDTASK'



Rsadeika
05-16-2010, 03:14 AM
"* SUBs and FUNCs are not shared between cogs." Does anybody have any ideas of how to get around this problem. I would like to declare a FUNC in the main cog, but be able to use it, or call it in different TASKs. I would like to create one 'serin', 'serout' function, and be able to use it, or call it, in multiple TASKs. It looks like a lot of duplicate code being used if you have to declare a new 'serin/serout' FUNC in the different TASKs. Any code snippets for achieving this would be appreciated.

Thanks

Ray

Bean
05-16-2010, 04:54 AM
Ray,
You can't do that. TASKs are in a different cog. One cog cannot "see" the code in a different cog.
Just create the same subroutine for the TASK that needs it.

Bean

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Use BASIC on the Propeller with the speed of assembly language.
PropBASIC thread http://forums.parallax.com/showthread.php?p=867134

March 2010 Nuts and Volts article·http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
There are two rules in life:
· 1) Never divulge all information
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If you choose not to decide, you still have made a choice. [RUSH - Freewill]

JonnyMac
05-16-2010, 06:11 AM
This is where the LOAD command is used; if you have a subroutine or function that is handy, save a copy to a separate file and load it as needed in the cogs that need the functionality.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon McPhalen
Hollywood, CA

Rsadeika
05-16-2010, 04:45 PM
I am still not sure how the 'load' command is to be used. Does it insert the code at the place where 'load xxxx' is placed in the program? If that is the case, then the duplication of code still exits through out the total program. JonnyMac had mentioned that 'serin' creates a lot of assembly code, so if you use that in a couple of different spots ... I guess maybe I will have to consider a 'TASK' for 'serin/serout', and try to make it so other cogs can get access to that 'TASK' via hub variables, so I guess this 'TASK' will constantly be in a 'do ... loop', or something along those lines. I wonder if that would work?

Ray

Bean
05-16-2010, 06:12 PM
Ray,
Yes, LOAD just inserts the code.

You COULD use a seperate task for SERIN and SEROUT, but I think you are making it more complecated than it needs to be. The amount of code generated by SERIN or SEROUT is not that much. If you use it alot, put it in a subroutine. If you use SERIN or SEROUT in multiple cogs, just put the subroutine in each of them.

Now putting SERIN in a seperate task will have the advantage of not missing any incoming characters.

And I do have one program that puts SEROUT in a seperate cog because it needs to acquire data in real-time and it cannot afford to wait for SEROUT to finish sending the data string.

Bean

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Use BASIC on the Propeller with the speed of assembly language.
PropBASIC thread http://forums.parallax.com/showthread.php?p=867134

March 2010 Nuts and Volts article·http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
There are two rules in life:
· 1) Never divulge all information
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If you choose not to decide, you still have made a choice. [RUSH - Freewill]

Rsadeika
05-16-2010, 06:41 PM
Which demo program is that? I thought I glanced at all of them, but I did not notice what you had described.

Ray

JonnyMac
05-16-2010, 07:28 PM
In my N&V column on PropBASIC I show how to put SERIN into a TASK so that it is only compiled once and you end up with buffering.

www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf (http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf)

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon McPhalen
Hollywood, CA

Rsadeika
05-18-2010, 02:46 AM
Below is a 'TASK' snippet, the problem that I am having is, when 'message' gets displayed on the terminal, I get "+is the place!". The·'message' string is getting shorted,·did I miss something with the usage of data strings?

Ray

'==============
TASK BlueT LMM
message data "This is the place!",13
rxResult var long
do
serin 5, T57600, rxResult
if rxResult = 13 then exit
loop
serout 6, T57600, message
pause 1000
do
serin 5, T57600, rxResult
if rxResult = "a" then
high 0
high 3
endif
if rxResult = "b" then
low 0
low 3
endif
loop

ENDTASK

JonnyMac
05-18-2010, 03:39 AM
Perhaps it has something to do with your device; BlueTooth?

BTW, that's a very small task and there is no reason to make it LMM -- keep it in one cog and run it full speed.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon McPhalen
Hollywood, CA

Rsadeika
05-18-2010, 03:56 AM
I guess I will have find your SUB for doing strings one byte at a time, and see if there is an improvement. This TASK is going to grow into a UI of sorts, so I want to see at what point it all starts to bog down. The main cog is also making use of LMM, even though it is quite small in code lines. As for the BlueTooth, I was having the same problem with the bst terminal, and PST. I thought it would go away with BlueTooth.

Ray

Bean
05-18-2010, 04:02 AM
Ray,
· Try making the SEROUT pin high (idle) well before you try sending data.
· Also you need to put a zero at the end of the string. This is only done for you with in-line strings.




TASK BlueT

message data "This is the place!",13, 0 ' I added the zero to the end

rxResult var long

high 6 ' I added this line

do
serin 5, T57600, rxResult
loop until rxResult = 13

serout 6, T57600, message
pause 1000

do
serin 5, T57600, rxResult
if rxResult = "a" then
high 0
high 3
endif
if rxResult = "b" then
low 0
low 3
endif
loop

ENDTASK



Bean

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Use BASIC on the Propeller with the speed of assembly language.
PropBASIC thread http://forums.parallax.com/showthread.php?p=867134

March 2010 Nuts and Volts article·http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
There are two rules in life:
· 1) Never divulge all information
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If you choose not to decide, you still have made a choice. [RUSH - Freewill]

Post Edited (Bean) : 5/17/2010 9:09:04 PM GMT

Rsadeika
05-18-2010, 04:25 AM
Just tried your suggestions, and it works, thanks. I tried the string with a terminating zero, and without the terminating zero, both worked. So, to be on the safe side what problems would I run into if I did not use the terminating zero? Since I anticipate having a lot of string data, is there a better solution for handling the string data? I am going to be testing string input, and do a particular response, so there will be a lot of string data to deal with.


Ray

Bean
05-18-2010, 04:48 AM
Ray, If you don't have the zero, the SEROUT command will just keep sending characters until is happens to run across a zero in memory.

Bean

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Use BASIC on the Propeller with the speed of assembly language.
PropBASIC thread http://forums.parallax.com/showthread.php?p=867134

March 2010 Nuts and Volts article·http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
There are two rules in life:
· 1) Never divulge all information
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If you choose not to decide, you still have made a choice. [RUSH - Freewill]