Shop OBEX P1 Docs P2 Docs Learn Events
function passing error — Parallax Forums

function passing error

chris joneschris jones Posts: 391
edited 2009-11-02 21:41 in Propeller 1
when i try to pas a function from another file i get an error (( expected end of line)) i am just tryting to test to see if a varable is geting placed into my varable.

CON

  _clkmode = xtal1 + pll16x                             ' use crystal x 16
  _xinfreq = 5_000_000                                  ' 5 MHz cyrstal (sys clock = 80 MHz)

  LCD_PIN   = 0                                         ' for Parallax 4x20 serial LCD on P0
  LCD_BAUD  = 19_200
  LCD_LINES = 4    


OBJ

  lcd : "debug_lcd"
  rf  : "RF_Units"


PUB main | idx
                                                
  if lcd.init(LCD_PIN, LCD_BAUD, LCD_LINES)             ' start lcd
    lcd.cursor(0)                                       ' cursor off
    lcd.backLight(true)                                 ' backlight on (if available)
    lcd.custom(0, @Bullet)                              ' create custom character 0
    lcd.cls                                             ' clear the lcd
    lcd.str(string(" WSN", 13))
    lcd.putc(0)                                         ' display custom bullet character
    lcd.str(string("Sensor", 13))
    lcd.putc(0)
    lcd.str(string("Energy", 13)) 
    lcd.putc(0)
    lcd.str(string("RXBit"))     

    repeat
      repeat idx from 0 to 255
        updateLcd(idx)
        waitcnt(clkfreq / 5 + cnt)                      ' pad with 1/5 sec

      repeat idx from -255 to 0
        updatelcd(idx)
        waitcnt(clkfreq / 5 + cnt)
        

PRI updateLcd(value)

  lcd.gotoxy(12, 1)
  rf.start(string(myStr, 8))                        ' print right-justified decimal value

DAT

  Bullet      byte      $00, $04, $0E, $1F, $0E, $04, $00, $00


Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-10-31 06:03
    It would be helpful if you showed where you got the error.

    -Phil
  • W9GFOW9GFO Posts: 4,010
    edited 2009-10-31 06:17
    You are passing idx to the updateLcd method where it is called "value" but no use is made of it.

    Where is myStr? Perhaps "value" should be called "myStr"?

    Rich H

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The Simple Servo Tester, a kit from Gadget Gangster.

    Post Edited (W9GFO) : 10/31/2009 6:23:21 AM GMT
  • StefanL38StefanL38 Posts: 2,292
    edited 2009-10-31 06:54
    I guess the bug is related to the file rf_unit.spin as you call a function of it

    so please archive your project and use the "Post Reply" and the Attachement Manager button
    to provide your COMPLETE source-code
  • StefanL38StefanL38 Posts: 2,292
    edited 2009-10-31 07:05
    best regards

    Stefan
    1582 x 470 - 46K
  • chris joneschris jones Posts: 391
    edited 2009-10-31 15:24
    ok here is my full .zip of code i have a lot of objects about 4 i added
  • StefanL38StefanL38 Posts: 2,292
    edited 2009-10-31 17:57
    OK I donloaded it.

    woo wow lot's of spinfiles glued together. Pretty normal in complex projects.
    But as you are asking for very basic things you should start with much less complex things

    Don't get me wrong - I'm willing to help. But this forum is not a replacement for your homework.
    It's not called the I write postings for everything you can read in the manual or the PE-kit-lab.

    From your code I can see that you haven't understand what objects are. Maybe you can glue them together
    but the compiler reports compile-errors.

    I will give you an answer if

    1) you post a detailed description of what your project should do use normal words NO pseudo-code

    2) you post a suggestion what MIGHT be the bug.
    It doesn't matter if your suggestion is right or wrong just take a look onto the picture I posted above
    and then post a suggestion. I will refuse to help until you posted these two points.

    Anybody else can post whatever he wants as this is a free forum. At this point I have conditions to go on helping

    best regards

    Stefan
  • chris joneschris jones Posts: 391
    edited 2009-10-31 18:35
    thanks Stefan i will get these things to you in a timely maner, NOte this is not a class project or homework just an ideal. i know A a lot of pepole get on here wanting there homework done but i am not one. Also you stated that "I can see that you haven't understand what objects are." From what i read an object is like a driver or include file as C++ has includes stdio.h etc.....

    but i will have a detailed reply with what i need my project to do, Also a reason i might be geting the bugs.

    i have a few questions for you....

    1. is there a way i can get a debug screen like in the bs2 chip
    2. is it bad to have a lot of objects or do i just have the concept of objects wrong
    3. is there other books i can read that will help e with the propeller chip i have the manual and the ref sheet and all the smaple programs, but it will be great if i had a debug screen to see what my vartables are doing or something displayed to the screen.


    Also thanks or your help and suggestions

    best regards

    CJ
  • StefanL38StefanL38 Posts: 2,292
    edited 2009-10-31 19:10
    Hello Chris,

    I didn't meant homework for school. I mean that kind of homework that you can read in the manual or at least the small piece in the picture I posted above
    where I already did the work to point on the page wich is important and cutted out the one sentence that is important.
    what do you guess what the error might be. Come on ! Post a quick guessing !

    What will be helpful additional are two things:

    1) the PE Kit Lab wich can be found here
    If you have read other threads you might already found this there.

    2) A style of writing postings that makes clear what you have already done on YOUR OWN (homework)

    example: I read the table of contents of the prop-manual but I don't know wich item is related to my problem with the function call
    can somebody point me to where I will find information about calling functions ?

    This is a pollite style that will make other forum-member go beyond that, what you are asking for as you show that you are willing to do
    what is your "homework" = things you can do on your own.

    That's a complete different style than just do a quick ask

    my program does not work - what's wrong ?
    (and between the lines this could be interpreted as "hurry up posting a working program for me !!! avanti presto avanti !!)

    best regards

    Stefan

    Post Edited (StefanL38) : 10/31/2009 7:16:26 PM GMT
  • chris joneschris jones Posts: 391
    edited 2009-11-01 23:29
    ok i het it sorry i am not the forum kind of person i have been re-reading a lot of things and i found the answers to a few of my questions. still working on your questions to my question
  • StefanL38StefanL38 Posts: 2,292
    edited 2009-11-02 17:43
    OK,

    the method "str" expects ONE long.
    umh ? How can ONE long make the program send a complete string ??

    The long holds a very certain value. The value of the long is a RAM-adress.

    Imagine a big house with a lot of chambers. You have a butler. You have papers to write commands on them
    and pass the paper to the butler.

    The papers are really small so you can write just one number on it.

    You can make the butler shout just this number
    But there is a second variant.
    You can make the butler walk through the house to the chamber with the number on the paper.
    Inside the chamber the butler will find a BIG piece of paper with a lot of characters on it and then this is what he should shout

    That's a picture how strings are realized in SPIN. Somewhere in the RAM you store a bytesequence with all the characters.
    The place in RAM has a certain adress. Now you pass the RAM-adress to the method str
    Then the method str takes the bytes stored in the RAM beginning at the given adress.

    OK and how does the method str now when to stop reading bytes from RAM ?

    The bytesequence ends with value zero. Whenever method str cames across value zero it stops

    This is called zero-terminated strings (it is the same as when programming in C)

    string("abcdef")) is transformed by the compiler to
    a) a bytesequence a,b,c,d,e,f,zero and it passes the adress of this bytesequence to the method str
    b) bytesequence ends with an ADDITIONAL zero

    You tried to pass the bytearray-variable mystring to the "method" string

      rf.start(string(myStr, 8)) 
    
    



    but string accepts only characters in doublehyphens example string("hi Paul!")
    it does NOT accepts variables like string(MyVariable)

    your method

    PUB Start
       BS2.start (2,1) ' Initialize BS2 Object timing, Rx and Tx pins for DEBUG
       SetString( @myStr, String("ABC") )
    
    



    has NO parameters but you call the method with a parameter

    It seems that you wrote a lot of lines of code at once
    and then started testing it. My recommendation is to divide your code
    in small pieces. Add a small part and immediatly test it. If it works properly
    add the next SMALL part and test again.

    This way you will succed faster, Because the area to search through for bugs is always small.
    It's a mystery to believe that writing big pieces of code save time.
    It eats up more and more time when the untested but nested code gets longer and longer

    So what is the most important part of your prgram ?
    Start with this part and add a small piece. If this does not work come here into the forum
    posting a concrete question

    best regards

    Stefan
  • chris joneschris jones Posts: 391
    edited 2009-11-02 21:41
    hello Stefan

    can you tell me now i can get a debug window on my computer to see whats going where. I have removed the object i created RF_Units i found ouyt i was using this wrong, but now i am stuck i dont know how to tell the reciver to take in the string that i am passing.

    CON
    
      _clkmode = xtal1 + pll16x                             ' use crystal x 16
      _xinfreq = 5_000_000                                  ' 5 MHz cyrstal (sys clock = 80 MHz)
    
      LCD_PIN   = 0                                         ' for Parallax 4x20 serial LCD on P0
      LCD_BAUD  = 19_200
      LCD_LINES = 4
      RF_TX     = 2
      RF_RX     = 1     
    
    
    OBJ
    
      lcd : "debug_lcd"           ' Serial LCD Communication for debuging
      BS2 : "BS2_Functions"       ' basic stamp 2 functions for serial comms
      ser : "FullDuplexSerial"    ' Full Duplex Serial Controller      
    
    VAR
    
            Byte strings[noparse][[/noparse]16]         'Array to hold received data
            Byte myString[noparse][[/noparse]50]        'holds data for the reciver
            word idxe                'Index into message data
            byte StrLen              'Length of string received
            byte char                'Current character from message
            byte cValue              'Holder for CRC calculation
            word crc                 'Calculate Crc value
    
    
    PUB main | idx
    
      ' Start the serial communications for the RF Transmiter
      ser.Start(RF_TX, -1, 1, 9600)
          
      ' Wait a bit
      Pause_ms(1000)
    
      ' Start the serial communications for the RF receiver
      ser.Start(RF_RX, -1, 1, 9600)
          
      ' Wait a bit
      Pause_ms(1000)
                                                    
      if lcd.init(LCD_PIN, LCD_BAUD, LCD_LINES)             ' start lcd
        lcd.cursor(0)                                       ' cursor off
        lcd.backLight(true)                                 ' backlight on (if available)
        lcd.custom(0, @Bullet)                              ' create custom character 0
        lcd.cls                                             ' clear the lcd
        lcd.str(string(" WSN", 13))
        lcd.putc(0)                                         ' display custom bullet character
        lcd.str(string("Sensor", 13))
        lcd.putc(0)
        lcd.str(string("Energy", 13)) 
        lcd.putc(0)
        lcd.str(string("RXBit"))     
    
        repeat
        
         BS2.Serout_Str(5,string("UUUUU!",13),9600,1,8)    ' send out message
         ' Wait a bit
          Pause_ms(1000)
          BS2.Serout_Str(5,string("Spin-Up World!",13),9600,1,8)
         ' Wait a bit
          Pause_ms(1000)
          repeat idx from 0 to 255
            updateLcd(idx)
            waitcnt(clkfreq / 5 + cnt)                      ' pad with 1/5 sec
    
          repeat idx from -255 to 0
            updatelcd(idx)
            waitcnt(clkfreq / 5 + cnt)
            
    
    PRI updateLcd(value)
    
      lcd.gotoxy(12, 1)
     ' rf.start(string(myStr, 8))                        ' print right-justified decimal value
     ' lcd.gotoxy(11, 2)
     ' lcd.ihex(value, 8)                                    ' print indicated (with $) hex
      'lcd.gotoxy(7, 3)
     ' lcd.ibin(value, 12)                                   ' print indicated (with %) binary                
                    
    PRI Pause_ms(msDelay)
      waitcnt(cnt + ((clkfreq / 1000) * msDelay))
                
    DAT
    
      Bullet      byte      $00, $04, $0E, $1F, $0E, $04, $00, $00
    
    

    ALSO you said i had errors in my code where are you seeing the errors is there a debug error screen

    Post Edited (chris jones) : 11/2/2009 9:47:55 PM GMT
Sign In or Register to comment.