Shop OBEX P1 Docs P2 Docs Learn Events
I am not an entomologist :) — Parallax Forums

I am not an entomologist :)

idbruceidbruce Posts: 6,197
edited 2010-07-09 23:34 in Propeller 1
Hi All

I believe I found a bug, can you please help me to identify it?· If I am wrong, I apologize for the inconvenience.
CON
  _clkmode = xtal1 + pll16x
  _xinfreq = 5_000_000 
DAT
  {
        Test.txt is a single line text file
        containing a simple string of numbers
        eg... 0123456789
  }
  {
        The Problem:
        Serial Terminal outputs extra data 
        eg... 01234567895785
  }
   
  FileData File "Test.txt" 
        
OBJ
  DEBUG  : "FullDuplexSerial"
VAR
  Long nCharacterCounter
  Byte chFileCharacter
  
PUB main
  nCharacterCounter := 0
  
  DEBUG.start(31, 30, 0, 115_200)
  waitcnt(clkfreq + cnt)  
  repeat 
    chFileCharacter := FileData[noparse][[/noparse]nCharacterCounter++]
    if chFileCharacter == 48 {0 Character}
      DEBUG.tx(chFileCharacter)
      
    if chFileCharacter == 49 {1 Character}
      DEBUG.tx(chFileCharacter)
      
    if chFileCharacter == 50 {2 Character}
      DEBUG.tx(chFileCharacter)
      
    if chFileCharacter == 51 {3 Character}
      DEBUG.tx(chFileCharacter)
      
    if chFileCharacter == 52 {4 Character}
      DEBUG.tx(chFileCharacter)
      
    if chFileCharacter == 53 {5 Character}
      DEBUG.tx(chFileCharacter)
      
    if chFileCharacter == 54 {6 Character}
      DEBUG.tx(chFileCharacter)
      
    if chFileCharacter == 55 {7 Character}
      DEBUG.tx(chFileCharacter)
      
    if chFileCharacter == 56 {8 Character}
      DEBUG.tx(chFileCharacter)
      
    if chFileCharacter == 57 {9 Character}
      DEBUG.tx(chFileCharacter) 
  while chFileCharacter > 0

Thanks

Bruce

Comments

  • wjsteelewjsteele Posts: 697
    edited 2010-07-09 15:53
    Are you sure your file ends with a chr(0) null? I'm betting it doesn't. If that's the case, the code will keep right on going until it finds one.

    You might be able to add something like a "Str byte 0" right under the filename line to fix it.

    Bill
  • idbruceidbruce Posts: 6,197
    edited 2010-07-09 15:58
    Bill

    Thanks for the reply, but I know the code stops executing because I can write data to the serial terminal after exiting the loop.

    Bruce
  • idbruceidbruce Posts: 6,197
    edited 2010-07-09 16:16
    Bill and to all concerned
    Here is some updated code to verify that null has bee found and that the loop is exited.
    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000 
    DAT
      {
            Test.txt is a single line text file
            containing a simple string of numbers
            eg... 0123456789
      }
      {
            The Problem:
            Serial Terminal outputs extra data 
            eg... 01234567895785
      }
       
      FileData File "Test.txt" 
            
    OBJ
      DEBUG  : "FullDuplexSerial"
    VAR
      Long nCharacterCounter
      Byte chFileCharacter
      
    PUB main
      nCharacterCounter := 0
      
      DEBUG.start(31, 30, 0, 115_200)
      waitcnt(clkfreq + cnt)  
      repeat 
        chFileCharacter := FileData[noparse][[/noparse]nCharacterCounter++]
        if chFileCharacter == 48 {0 Character}
          DEBUG.tx(chFileCharacter)
          
        if chFileCharacter == 49 {1 Character}
          DEBUG.tx(chFileCharacter)
          
        if chFileCharacter == 50 {2 Character}
          DEBUG.tx(chFileCharacter)
          
        if chFileCharacter == 51 {3 Character}
          DEBUG.tx(chFileCharacter)
          
        if chFileCharacter == 52 {4 Character}
          DEBUG.tx(chFileCharacter)
          
        if chFileCharacter == 53 {5 Character}
          DEBUG.tx(chFileCharacter)
          
        if chFileCharacter == 54 {6 Character}
          DEBUG.tx(chFileCharacter)
          
        if chFileCharacter == 55 {7 Character}
          DEBUG.tx(chFileCharacter)
          
        if chFileCharacter == 56 {8 Character}
          DEBUG.tx(chFileCharacter)
          
        if chFileCharacter == 57 {9 Character}
          DEBUG.tx(chFileCharacter)
        if chFileCharacter == 0 {NULL Character}
          DEBUG.tx(13)
          DEBUG.str(String("NULL character, 0, End Of File, has been reached")) 
      while chFileCharacter > 0
      DEBUG.tx(13)
      DEBUG.str(String("Hello World"))
    
  • Mike GreenMike Green Posts: 23,101
    edited 2010-07-09 16:21
    Without a dump of the contents of "Test.txt" (and for that matter, a copy of the binary file to see what's actually compiled for "Test.txt"), it's impossible to say whether it's a bug in your code or the compilation process.

    There's other information that's missing. For example, when do the extra characters appear? Your main method runs in one cog and, when the main method exits, the cog is stopped. FullDuplexSerial runs in its own cog and it takes some time for it to finish sending the information in its transmit buffer.

    You mention that you can write data to the serial terminal after exiting the loop. That doesn't help unless you show what changes you make in the code so that happens.

    I'm with wjsteele. I think that you don't have a zero byte in your text file and there are some other characters following the end of your "0123456789" string that cause the output of the "5785" and maybe there's a zero byte somewhere after that in the file.

    Remember that some text editors use a non-zero specific control code to mark the end of the text file. The Propeller Tool doesn't know about this because the FILE directive might be used to include binary information and the Propeller Tool probably uses the file length information stored in the directory to tell it where the end of the file is. There could be all sorts of junk between the "end of file" control code and the actual end of the file. Your code only recognizes the digit characters and a zero byte. I think you'd see this if you added a couple of lines to display all non-digit characters as two hex digits.

    Post Edited (Mike Green) : 7/9/2010 4:27:51 PM GMT
  • idbruceidbruce Posts: 6,197
    edited 2010-07-09 16:31
    Mike

    I disagree.· Look at the updated source.

    Serial Terminal output now displays:

    01234567895785
    NULL character, 0, End Of File, has been reached
    Hello World

    Bruce
  • idbruceidbruce Posts: 6,197
    edited 2010-07-09 16:34
    Please test before jumping to conclusions.· It is a simple test.

    Bruce
  • idbruceidbruce Posts: 6,197
    edited 2010-07-09 16:46
    Mike

    Here is a compiled binary file.· I assume this is what you want to see.

    Bruce
  • wjsteelewjsteele Posts: 697
    edited 2010-07-09 16:48
    Personally, I don't see any difference in your code that would indicate any other conclusion. If the text file still has extra characters at the end of it, it'll still do the same thing... until it hits the null character.

    Now, I ran your test code and got the same result as you, so I looked at the memory map and sure enough, the only characters after the 9 and before the null that your code can display are the 5785 that you are getting.

    It is because your file is not terminated with a null, period. Our conclusions are exactly what is happening.

    Bill
  • wjsteelewjsteele Posts: 697
    edited 2010-07-09 16:53
    In fact, adding the "Str byte 0" under your FileName line, like I suggested fixes your code.

    Bill
  • idbruceidbruce Posts: 6,197
    edited 2010-07-09 17:10
    Bill

    Okay, I am humbled.· What the heck is a memory map?· And how did you find that?· Very impressive!

    I must admit that I assumed you guys were wrong.· I apologize.· Nice find.· The code now works perfectly and I can go forward.

    Thanks you Bill for the solution and the responses.

    Bruce

    P.S. Also thanks to Mike for his response.
  • wjsteelewjsteele Posts: 697
    edited 2010-07-09 17:13
    In the Propeller tool, press F8.

    I'd say (Mike and) I found it because of our experience, which you shouldn't underestimate. wink.gif It's why we're on this Forum... to get help and to help others.

    Bill
  • idbruceidbruce Posts: 6,197
    edited 2010-07-09 17:22
    Bill

    Thats what I thought you meant by the memory map, but I wish I knew how to read that stuff.· I have experience also, but I guess in this case I was outclassed smile.gif

    Bruce



    P.S.· I won't underestimate you anymore, or at least I will TRY not to. wink.gif· Thanks
  • mparkmpark Posts: 1,305
    edited 2010-07-09 17:24
    On an unrelated note, you can use character literals instead of numbers:

        if chFileCharacter == "0"
          DEBUG.tx(chFileCharacter)
          
        if chFileCharacter == "1"
          DEBUG.tx(chFileCharacter)
    
    
  • Mike GreenMike Green Posts: 23,101
    edited 2010-07-09 17:28
    If you open the .binary file in the Propeller Tool, you'll get the hexadecimal display of the binary file contents. If you look at the beginning of the file, you'll see your information from the "Test.txt" file. If you look past the "0123456789", you'll see that there's no zero byte for a while (there just by accident). If you note which bytes contain digit characters between the "9" and the zero byte, you'll see that they're exactly what you're seeing displayed.
  • hover1hover1 Posts: 1,929
    edited 2010-07-09 17:46
    @idbruce
    It is unwise to second guess the likes of Mike. Check out his total posts. He is a god on these forums. [noparse]:)[/noparse]

    Bill's not too shabby too [noparse]:)[/noparse]
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-07-09 18:07
    Bruce,

    BTW, your code can be made a lot more compact, viz:

    repeat while (chFileCharacter := FileData[noparse][[/noparse]nCharacterCounter++])
      if (chFileCharacter => "0" and chFileCharacter =< "9")
        debug.tx(chFileCharacter)
    debug.tx(13)
    
    
    



    -Phil
  • hover1hover1 Posts: 1,929
    edited 2010-07-09 18:13
    OK,
    It's against my religion to have more than one god, so I proclaim Mike and Phil as Saints [noparse]:)[/noparse]

    Phil Pilgrim (PhiPi) said...
    Bruce,

    BTW, your code can be made a lot more compact, viz:

    repeat while (chFileCharacter := FileData[noparse][[/noparse]nCharacterCounter++])
      if (chFileCharacter => "0" and chFileCharacter =< "9")
        debug.tx(chFileCharacter)
    debug.tx(13)
    
    
    



    -Phil
  • idbruceidbruce Posts: 6,197
    edited 2010-07-09 23:34
    Gee where to start.

    First off, thanks to everyone and there responses.

    Mike, I believe you that it is in there, I just don't own a pair of those xray glasses that you and Bill have.· smile.gif·· I just found a pair.· That's pretty cool!· I understand now.· Thanks Mike.



    Phil, yes I agree, that is a much simpler loop, but the real file data contains alpha-numeric characters and other symbols, so I must compare.· However, there are places within the file data that contain strings of nothing but numbers where your code snippet will come in handy.· Thanks for the snippet.



    hover1, they both look a little mischievous, are you sure they are saints?



    mpark, I must also do some other comparisons that do not allow chacter comparison, so I am using decimal comparison for all to be consistent.



    Thanks again everyone
Sign In or Register to comment.