Shop OBEX P1 Docs P2 Docs Learn Events
PropBasic: Using multiple instances of lib — Parallax Forums

PropBasic: Using multiple instances of lib

VonSzarvasVonSzarvas Posts: 3,525
edited 2010-09-15 05:10 in Propeller 1
Asking a question with an example:

A main cog and 2 tasks(cogs) all require separate serial ability.

The serial.lib library is a very useful import. However, it can only be imported once to the entire project - it means the PIN (tx/rx) & CON (baud) are the same.

If the different cogs/tasks required serial "action" to different external serial devices, then the lib stradegy falls short.

As I can see, I would need to copy the serial.lib and search/rename all the CON,PIN,VAR and SUB/FUNC definitions (perhaps serial1.lib, serial2.lib, serial3.lib)

Is this the only way to handle this at the moment ?

__________________________________________________________________________

-- Idea:

Could the library be LOADed with an option, such as:

LOAD "serial.lib" { prefix="debug", TX="10", BAUD="T57600" }

So during the LOAD, all VAR,CON,PIN,SUB,FUNCS are prefixed (ie. TX_BYTE becomes debugTX_BYTE) and obviously TX PIN is set to 10, etc... )

Now we can use our serial lib, ie. debugTX_DEC tmp

Would this be useful... am I making a mountain from a molehill ?!

Comments

  • BeanBean Posts: 8,129
    edited 2010-09-15 04:32
    Right now the only way would be to create a copy of the lib and prefix everything like you had suggested.

    What I might try to do (if it's possible) is to allow something like:
    debug_TX PIN 10
    debug_Baud CON "T115200"
    
    LOAD "serial.lib" AS debug
    
    debug_TX_Hex value
    

    Bean
  • VonSzarvasVonSzarvas Posts: 3,525
    edited 2010-09-15 05:10
    sounds good.

    One thought... The "AS" name could be "debug_" or "debug",
    thus the PIN would be defined debug_TX or debugTX

    So, the user could decide if they wanted the underscore or not by specify the prefix at the AS statement. I mean, perhaps it should not (nor need not) be forced.

    ...anyhow, don't want to make a meal of it! If you come across a solution and have time to implement, it would be very gratefully received. Hopefully from some other angles there are not issues with this productivity concept.
Sign In or Register to comment.