To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.nxtOpen lugnet.robotics.nxt in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / NXT / 1009
1008  |  1010
Subject: 
NXT iterate files
Newsgroups: 
lugnet.robotics.nxt, lugnet.robotics
Date: 
Sun, 30 Dec 2007 21:56:28 GMT
Viewed: 
30007 times
  
I wrote some NXC code that runs on the enhanced NBC/NXC firmware.  It
demonstrates how to iterate files on the filesystem.

Let me know if you have any questions.

John Hansen


#define LOADER_HANDLE(_x) (_x&0xff)
#define LOADER_ERR_BYTE(_x) ((_x&0xff00)>>8)

unsigned int FindFirst(string pattern, string & output) {
  LoaderExecuteFunctionType lef;
  lef.Cmd = LDR_CMD_FINDFIRST;
  lef.Filename = pattern;
  ArrayInit(lef.Buffer, 0, 20);
  SysLoaderExecuteFunction(lef);
  if (LOADER_ERR_BYTE(lef.Result) == LDR_SUCCESS)
    output = ByteArrayToStr(lef.Buffer);
  else
    output = "File Not Found";
  return lef.Result;
}

unsigned int FindNext(byte handle, string & output) {
  LoaderExecuteFunctionType lef;
  lef.Cmd = LDR_CMD_FINDNEXT;
  ArrayInit(lef.Filename, 0, 20);
  ArrayInit(lef.Buffer, 0, 20);
  lef.Filename[0] = handle;
  SysLoaderExecuteFunction(lef);
  output = ByteArrayToStr(lef.Buffer);
  return lef.Result;
}

task main() {
  byte handle;
  unsigned int result;
  string fname;
  result = FindFirst("*.ric", fname);
  NumOut(0, LCD_LINE1, result, true);
  int i=1;
  while (LOADER_ERR_BYTE(result) == LDR_SUCCESS) {
    NumOut(0, LCD_LINE2, i, false);
    TextOut(0, LCD_LINE3, fname, false);
    Wait(500);
    handle = LOADER_HANDLE(result);
    result = FindNext(handle, fname);
    NumOut(0, LCD_LINE1, result, true);
    i++;
  }
  CloseFile(handle);
  Wait(3000);
}



1 Message in This Thread:

Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR