Shop OBEX P1 Docs P2 Docs Learn Events
Reading File Fragment — Parallax Forums

Reading File Fragment

crgwbrcrgwbr Posts: 614
edited 2008-06-03 19:28 in Propeller 1
Currently, I have a Memory Stick Datalogger working with the propeller. On the Memory Stick, there is a file, say test.txt. What would be the best way to read a specific number of bytes from the file, but not necessarily from the beginning? For example, I want to read the 100th byte through the 114th byte into RAM. I thought about just reading the first ~150 bytes into a buffer, then bytemoving index 100-114 to the beginning, and bytefilling everything above index 14 with 0. This would probably work, but it seems rather memory inefficient? Any other methods of doing this?

Thanks,
Craig

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
My system: 1.6 GHz AMD Turion64 X2, 4GB DDR2, 256MB ATI Radeon Graphics card, 15.4" Widescreen HD Screen

I have a duel boot of Ubuntu Linux and Windows Vista. Vista, because it came with the PC, Ubuntu because I like software that works.

"Failure is not an option -- it comes bundled with Windows."

Use The Best...
Linux for Servers
Mac for Graphics
Palm for Mobility
Windows for Solitaire

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-06-03 19:13
    The Memory Stick Datalogger usually provides the data via a serial connection. You send a command, then receive the corresponding data. I believe you specify the number of bytes you want as part of the read command. Why not issue a read command to the device that specifies the number of bytes you want to ignore, then ignore the received data for that command. Issue a 2nd read command for the amount of data you actually want and store the received data in a buffer to examine later.

    If you have the most recent firmware, there is a Seek command that lets you set the file relative address of the next byte to read.

    Post Edited (Mike Green) : 6/3/2008 7:18:24 PM GMT
  • crgwbrcrgwbr Posts: 614
    edited 2008-06-03 19:16
    I may be mistaken, but I think the second read command would jump back to the beginning of the file; ie- read position is not stored.

    But I could be wrong, anyone know for sure?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    My system: 1.6 GHz AMD Turion64 X2, 4GB DDR2, 256MB ATI Radeon Graphics card, 15.4" Widescreen HD Screen

    I have a duel boot of Ubuntu Linux and Windows Vista. Vista, because it came with the PC, Ubuntu because I like software that works.

    "Failure is not an option -- it comes bundled with Windows."

    Use The Best...
    Linux for Servers
    Mac for Graphics
    Palm for Mobility
    Windows for Solitaire
  • Mike GreenMike Green Posts: 23,101
    edited 2008-06-03 19:17
    Why not read the firmware manual and see? I do believe the read position is stored while the file is open.

    All I know about this sort of stuff is from what I read in the manual. You too can be the repository of secret information.
  • crgwbrcrgwbr Posts: 614
    edited 2008-06-03 19:28
    Ok, I couldn't find anything in the VDAP specs about it. But I will take your word on it, and test it as soon as I can. If it does hold read position, this code should work:

      serial.rxFlush
      
      serial.str(string("RDF "))
      repeat count from 0 to 3
        serial.tx(skip.byte[noparse][[/noparse]count])
      serial.tx(13)
      
      serial.rxFlush
      
      serial.str(string("RDF "))
      repeat count from 0 to 3
        serial.tx(size.byte[noparse][[/noparse]count])
      serial.tx(13)
    
      serial.rxStr(addr)
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    My system: 1.6 GHz AMD Turion64 X2, 4GB DDR2, 256MB ATI Radeon Graphics card, 15.4" Widescreen HD Screen

    I have a duel boot of Ubuntu Linux and Windows Vista. Vista, because it came with the PC, Ubuntu because I like software that works.

    "Failure is not an option -- it comes bundled with Windows."

    Use The Best...
    Linux for Servers
    Mac for Graphics
    Palm for Mobility
    Windows for Solitaire
Sign In or Register to comment.