Shop OBEX P1 Docs P2 Docs Learn Events
Question about VAR — Parallax Forums

Question about VAR

samsearchersamsearcher Posts: 13
edited 2006-12-08 07:23 in Propeller 1
I need a little help with this. I trying to assign a three digit number to the VAR pulsDuration from a terminal program. For example when I send 170 from the terminal program with the code as it is now it displays back in the terminal program fine but doesn't work with Turn.Start(pulsDuration). When I remove the comment out from the line pulsDuration := 170 and comment out
pulsDiration := pDuration it works.





CON
  _clkmode = xtal1' + pll16x   
  _xinfreq = 5_000_000   
  
OBJ
  Comm : "FullDuplexSerial"
  Turn : "ServoSteer"

VAR
   pulsDuration long
   
DAT
  pDuration long

PUB Main  
     Comm.start(31,30,%0000, 2_400)
     
     bytefill(@pDuration[noparse][[/noparse]0], Comm.rx,1)
     bytefill(@pDuration, Comm.rx,1)
     bytefill(@pDuration, Comm.rx,1)
            
            
     Comm.tx(byte[noparse][[/noparse]@pDuration[noparse][[/noparse]0]])           
     Comm.tx(byte[noparse][[/noparse]@pDuration])          
     Comm.tx(byte[noparse][[/noparse]@pDuration])           
           
      'pulsDuration := 170

     pulsDuration := pDuration
     Comm.rxtime(50)                         
     Comm.tx($0D)                            
     Comm.tx($0D)                            
     Comm.rxtime(50)
     Turn.Start(pulsDuration)           


Comments

  • [Deleted User][Deleted User] Posts: 0
    edited 2006-12-07 04:26
    Try,
    VAR
    LONG PulsDuration, PDuration

    Brian

    Post Edited (truckwiz) : 12/7/2006 4:31:22 AM GMT
  • samsearchersamsearcher Posts: 13
    edited 2006-12-07 04:51
    I tried

    VAR
    Long PulsDuration, PDuration

    but I still get the same resaults.

    You might have noticed that under VAR in the sample code I have VAR PulsDuration long not VAR long PulsDuration as it should be. Somehow this go reversed when I was cutting and pasting the sample code. It is in the proper order in the actual code.

    Thanks
  • SSteveSSteve Posts: 808
    edited 2006-12-07 06:22
    samsearcher said...
    when I send 170 from the terminal program with the code as it is now it displays back in the terminal program fine but doesn't work with Turn.Start(pulsDuration). When I remove the comment out from the line pulsDuration := 170 and comment out
    pulsDiration := pDuration it works.

         bytefill(@pDuration[noparse][[/noparse] 0], Comm.rx,1)
         bytefill(@pDuration[noparse][[/noparse] 1], Comm.rx,1)
         bytefill(@pDuration[noparse][[/noparse] 2], Comm.rx,1)
    
    

    I believe the values stored in pDuration are the ASCII values of the characters you typed. Try this instead of "pulsDuration := pDuration"
      pulsDuration := 0
      repeat idx from 0 to 2
        pulsDuration := pulsDuration * 10 + (pDuration[noparse][[/noparse]idx] - '0')
    
    


    I'm pretty sure I have the syntax wrong for getting the ASCII value of zero, but I hope you understand my meaning.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    OS-X: because making Unix user-friendly was easier than debugging Windows

    links:
    My band's website
    Our album on the iTunes Music Store
  • samsearchersamsearcher Posts: 13
    edited 2006-12-07 23:43
    Thanks for the reply SSeve I didn't understand what idx is but it got me thinking about the fact that the received bytes are ASCII "Give me a break I just beginner at this" its ok to laugh out loud. Here's what I came up with that works. Any input on a better way to do this would be great.

    CON
      _clkmode = xtal1' + pll16x   
      _xinfreq = 5_000_000   
      
    OBJ
      Comm : "FullDuplexSerial"
      Turn : "ServoSteer"
      Num  : "Numbers"
      
    VAR
       long pulsDuration[noparse][[/noparse]2], pDuration[noparse][[/noparse]2]
    PUB Main  
         Comm.start(31,30,%0000, 2_400)
         Num.Init
         
         bytefill(@pDuration[noparse][[/noparse]0], Comm.rx,1)
         bytefill(@pDuration[noparse][[/noparse]1], Comm.rx,1)
         bytefill(@pDuration[noparse][[/noparse]2], Comm.rx,1)
              
         Comm.tx(byte[noparse][[/noparse]@pDuration[noparse][[/noparse]0]])           
         Comm.tx(byte[noparse][[/noparse]@pDuration[noparse][[/noparse]1]])          
         Comm.tx(byte[noparse][[/noparse]@pDuration[noparse][[/noparse]2]])
                    
         pulsDuration := Num.FromStr(@pDuration[noparse][[/noparse]0],Num#DEC)*100+Num.FromStr(@pduration[noparse][[/noparse]1],Num#DEC)*10+Num.FromStr(@pduration[noparse][[/noparse]3],Num#DEC)
                          
         Comm.tx($0D)                            
         Comm.tx($0D)                            
         Comm.rxtime(50)
         Turn.Start(pulsDuration)                              
    
  • SSteveSSteve Posts: 808
    edited 2006-12-08 07:23
    samsearcher said...
    I didn't understand what idx is but it got me thinking about the fact that the received bytes are ASCII
    "idx" was just a loop variable used as an array index. Your solution does the same thing without a loop. Using a loop is a little more flexible in case the number of digits changes, but that's probably not too big a deal.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    OS-X: because making Unix user-friendly was easier than debugging Windows

    links:
    My band's website
    Our album on the iTunes Music Store
Sign In or Register to comment.