Shop OBEX P1 Docs P2 Docs Learn Events
PropBasic SUB, Parameter passing — Parallax Forums

PropBasic SUB, Parameter passing

FriedVFriedV Posts: 77
edited 2011-08-19 09:57 in Propeller 1
In PropBasic Subroutines, how can I calculate the lenght of a HUB string?
Address is passed as __param1, but LEN does not work?
Is there a PropBasic Forum?
Regards, Fried



SendDate SUB 1

SUB SendData

bcc VAR LONG
i VAR LONG
bufadr VAR LONG
ch VAR LONG
lenght VAR LONG

bufadr = __param1
lenght = len bufadr
I2CSTART SDA, SCL
i2cwrite SDA,SCL,$DE
i2cwrite SDA,SCL,$11
bcc = $11
i2cwrite SDA,SCL,length
bcc = bcc + length
for i = 1 to lenght
RDBYTE bufadr, ch
i2cwrite SDA,SCL,ch
bcc = bcc + ch
INC bufadr
next
i2cwrite SDA,SCL,bcc
i2cstop SDA,SCL
i2cstart SDA, SCL
i2cwrite SDA,SCL,$DF
i2cread SDA,SCL,ch,0
i2cstop SDA, SCL


ENDSUB

Comments

  • BeanBean Posts: 8,129
    edited 2011-08-03 14:01
    Fried, (This that really your name ???)
    The LEN function works with strings. What you have is the "address" of the string. So you need to defererence the variable like this:
    length = len __STRING(bufadr)
    

    Here is the note from the PDF file
    * To deference a string use the system array __STRING(var). Note there are two underscores.
    Strings are passed to subroutines as the location of the string in HUB RAM. Using __STRING(__paramx) allows
    subroutines to access the strings that were passed.
    

    Bean
  • FriedVFriedV Posts: 77
    edited 2011-08-04 02:42
    Thanks very much Bean!
    Yes, Fried is my real name, it is short for Friedrich in German.
    BTW is it possible to use ViewPort to debug PropBasic? I tried some tricks with inline ASM (OBJ vp:"Conduit"), but no succes.
    Fried
  • BeanBean Posts: 8,129
    edited 2011-08-04 04:12
    I've not used ViewPort, but from what I remember it can only show variables stored in the HUB.
    So you would have to RDLONG a variable to a HUB var, so ViewPort could "see" it.

    I'll look into it when I get a chance.

    Bean
  • HannoHanno Posts: 1,130
    edited 2011-08-09 22:18
    Hi Fried,
    Yes, Bean is correct (as usual). ViewPort works by sharing variables stored in HUB with the PC using the "conduit" object. To get VP to work you would need to:
    - ensure Prop is running at full speed by setting clock constants (PropBasic may do this for you?)
    - reference the "Conduit" object
    - call the "share" function with the begin and end of memory you would like to share.
    Is that enough to get you going?
    Hanno
  • BeanBean Posts: 8,129
    edited 2011-08-10 03:39
    Hanno,
    Thanks for those tips. I'll give it a try when I get the chance. And let everyone know how to do it.

    Bean
  • FriedVFriedV Posts: 77
    edited 2011-08-19 09:57
    Thx Bean & Hanno,
    up to now I'm working my way trough Spin and the objects.
    But I intend to use Propbasic in the long run, I just got the feeling that it is useful (necessary?) to gain some knowledge about Spin and the underlying object model.
    Fried
Sign In or Register to comment.