Shop OBEX P1 Docs P2 Docs Learn Events
Need help with Method coding, see attached "Spin" file. — Parallax Forums

Need help with Method coding, see attached "Spin" file.

JMLStamp2pJMLStamp2p Posts: 259
edited 2008-03-08 11:45 in Propeller 1
Hello,
Please see attached files.

The attached files·are running in my "Transmitter" and·"Reciever" Prop's. I am transmitting (9) bytes that are being saved into an array to the reciever. I can monitor the data as it is being recieved via a LCD and via the transmit & recieve lights on my trancievers.

My problem is this:

1) I am entering (3) sets of 3 digit numbers on the "Transmitting end", into a (9) byte array. As the last digit is entered it transmits the bytes to the reciever.

2) On the recieving end I can see via my tranciever that it has recieved the data but it is not being sent to the LCD until I send a "second set of 3 digit numbers". I am assuming that I·have coding errors in my "Recieve method" since it is taking exactly Twice the number of bytes recieved before the data is sent to the LCD, Probally te reason for the data confusion showing up on my LCD also. Please let me know if you see something wrong.

3) I am getting the numbers on my LCD on the recieving end after the second set of "3" digit numbers are sent. But sometimes they are in the correct order and sometimes they are not.

4) For example: When I enter 214, 213, & 215 on the keypad on my transmitting end I get the correct numbers in the correct order on my reciever. By this I mean that I get 123, 124 & 125. For some reason the 1 and
the 2 are swaped when it is sent to the LCD.

5) If I send all 1's for the first set of (3) digit numbers, I see them transmitted to the reciever. When I send the second set of (3) digit numbers all (2's) I get
1's and 2's when the data shows on the LCD, recieving end.

Note: The data is suppose to be sent to the LCD on the recieving end after
the first set of 3 digit numbers are recieved or the first "9" bytes. Therefore I believe that my problem is most likely in my "Recieve" code.

Thanks for any help that you can give,
JMLStamp2p

Comments

  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-03-07 06:03
    I think your problem is in this section of code
    Pub Recieved_Data(Num_of_nums, datains) : rxbyte 
    
    
      repeat
    
        if Num_of_nums-- == 0
          
            byte[noparse][[/noparse]datains] := 0     
            return
    
         
        data.rx
        rxbyte := data.rx
    


    The first data.rx is simply ignoring every first byte sent and the second one only getting every second byte. Also, why are you making byte[noparse][[/noparse]datains]:=0? I can't see that the zero at the end is used anywhere. Hope this helps.
  • JMLStamp2pJMLStamp2p Posts: 259
    edited 2008-03-07 12:09
    stevenmess,
    I must be misundestanding this code completely. I thought that " byte[noparse][[/noparse]datains] := 0 "
    was reseting the array pointer to location [noparse][[/noparse]0] after " Num_of_nums-- == 0 " had become true. If Recieved_Data is called and Num_of_nums starts out at "9" which would make the the statement False
    is data.rx not waiting for a byte via FullDuplexSerial and then assign that byte to " rxbyte " the return varible ? The line below this " byte[noparse][[/noparse]datains++] := rxbyte " I thought wrote the first byte coming in to location "0" in the array then incremented the array pointer and looped back for the second byte, ect. When Num_of_nums is true or equal to "9" the indented code below it would execute,
    set the array pointer to "0" and return to Main.
    This may be the problem, would you please give me an example of how it should be. I have been pulling my hair out trying to get this block of code correct :>)
    Thanks for taking the time to look at the code and reply. It is greatly appreciated !
    JMLStamp2p
  • JMLStamp2pJMLStamp2p Posts: 259
    edited 2008-03-07 14:26
    stevenmess,
    You were right, I simply took out the line "data.rx" as I realized that rxbyte := data.rx
    was already calling the rx method and assigning the recieved byte to rxbyte.
    Everything is working correctly now, I get the bytes showing on the recieve end after 9 bytes are sent and they are in the correct order,ect.
    Thank You so much for your help, I can't begin to tell you how much this simple fix does
    for my program.
    Sincerely,
    JMLStamp2p
  • JMLStamp2pJMLStamp2p Posts: 259
    edited 2008-03-07 15:59
    stevenmess,
    A simple question :>)
    How do you post code as you have showing in the gray box with the Blue letters
    above ?
    JMLStamp2p
  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-03-07 22:25
    You just put a [noparse][[/noparse] code ] at the start and a [noparse][[/noparse] /code ] at the end without the spaces. If you use the post reply there is even a button to do it.
    JMLStamp2p said...
    I thought that " byte[noparse][[/noparse]datains] := 0 "
    was reseting the array pointer to location [noparse][[/noparse]0] after " Num_of_nums-- == 0 " had become true. If Recieved_Data is called and Num_of_nums starts out at "9" which would make the the statement False
    is data.rx not waiting for a byte via FullDuplexSerial and then assign that byte to " rxbyte " the return varible ? The line below this " byte[noparse][[/noparse]datains++] := rxbyte " I thought wrote the first byte coming in to location "0" in the array then incremented the array pointer and looped back for the second byte, ect. When Num_of_nums is true or equal to "9" the indented code below it would execute,
    set the array pointer to "0" and return to Main.
    byte[noparse][[/noparse]datains]:=0 is writing 0 to the byte at the address that is in datains. This only gets run when you are exiting your routine and will be the 10th byte in your array which is fortunately not used. I think what you are trying to do is set the location back to the start of the array but this is done every time you call the method because it is passed in in the parameter list.
  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-03-07 22:34
    I would probably use something like this
    [b]Pub[/b] Recieved_Data(Num_of_nums, datains)|i,rxbyte 
      [b]repeat[/b] i [b]from[/b] 0 to 8 'loops 9 times
    
        rxbyte := data.rx 'get byte from serial
    
        [b]if[/b] rxbyte == (85) '            
          rxbyte := 0
         
        [b]if[/b] rxbyte == (49) 'you could replace all of these with rxbyte-=48         
          rxbyte := 1           
                                                        
        [b]if[/b] rxbyte == (50)         
          rxbyte := 2                                   
          
        [b]if[/b] rxbyte == (51)             
          rxbyte := 3                                  
         
        [b]if[/b] rxbyte == (52)                                                                
          rxbyte := 4                                  
              
        [b]if[/b] rxbyte == (53)                                                               
          rxbyte := 5                                  
    
        [b]if[/b] rxbyte == (54)                                                                
          rxbyte := 6                                  
       
        [b]if[/b] rxbyte == (55)                                                                
          rxbyte := 7                                  
        
        [b]if[/b] rxbyte == (56)                                                                
          rxbyte := 8                                  
          
        [b]if[/b] rxbyte == (57)                                                                
          rxbyte := 9                                  
         
        [b]if[/b] rxbyte == (80) 'why do you have two inputs that make 0?                                                               
          rxbyte := 0                                  
        
        [b]byte[/b][noparse][[/noparse] datains][noparse][[/noparse] i] := rxbyte
    
    
    


    Edit: you should now be able to see the [noparse][[/noparse] i], it got me againsmile.gif Whenever you put something in brackets put a space after the opening bracket otherwise it might get eaten by the forumsmile.gif

    Post Edited (stevenmess2004) : 3/7/2008 11:07:45 PM GMT
  • deSilvadeSilva Posts: 2,967
    edited 2008-03-07 22:40
    Just BTW: Whenever you read italic in a code-section than you have some overlooked [noparse][[/noparse] i ] there smile.gif

    Also BTW: Wouldn't it now be time to get rid of this eye hurting if cascade?
    Get out your Manual and read what it has to say about LOOKDOWNZ !
  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-03-07 23:13
    For a much smaller version
    [b]Pub[/b] Recieved_Data(Num_of_nums, datains)|i,rxbyte 
      [b]repeat[/b] i [b]from[/b] 0 to 8 'loops 9 times
    
        rxbyte := data.rx 'get byte from serial
    
        [b]case[/b] rxbyte
          80:
                 [b]byte[/b][noparse][[/noparse]datains][noparse][[/noparse]i]:=0
          85:
                 [b]byte[/b][noparse][[/noparse]datains][noparse][[/noparse]i]:=0
          49..57:
                [b]byte[/b][noparse][[/noparse]datains][noparse][[/noparse]i]:=rxbyte-48
    
    
    


    This was formatted using this www.phipi.com/format/ page which looks after everything. Just past your code, press format and copy into your post.
  • JMLStamp2pJMLStamp2p Posts: 259
    edited 2008-03-08 11:45
    stevenmess,
    Got it fixed thanks to your post.
    Very much appreciated !
    JMLStamp2p
Sign In or Register to comment.