View unanswered posts | View active topics It is currently Tue Feb 28, 2017 10:59 am

Reply to topic  [ 6 posts ] 
Help with file access usage 
Author Message

Joined: Thu Oct 28, 2010 12:23 am
Posts: 2
Post Help with file access usage

Last year, my school's FTC robotics team had trouble making an autonomous program, and so we didn't get as many points as we wanted to. This year, I am trying to implement the autonomous section of the match into the robot's program. I thought that it would be a good idea to have a pre-match configuration program that would create a file that the autonomous program could then read before the waitForStart() function. I would like some help with this due to the fact that the RobotC help file doesn't really say all that much (no examples) about the file access section of the nxt functions.

Robert Allen, Glencoe High School

Sat Dec 03, 2011 9:17 pm
Site Admin
Site Admin

Joined: Mon Jun 08, 2009 4:50 pm
Posts: 70
Post Re: Help with file access usage
Hi Robert Allen,

Below is a small sample for reading and writing strings and bytes. If you are working with numbers but like to read in chars you can always store your numbers as a string and then convert them back to ints and floats after reading them with atoi("3.14") and atof("3.14"). Anyways, have a look at the code below and feel free to respond with any questions. We are currently working on an API revamp that we hope everybody will find much more useful than our current documentation.

task main()
  TFileHandle   hFileHandle;              // will keep track of our file
  TFileIOResult nIOResult;                // will store our IO results
  string        sFileName = "test.txt";   // the name of our file
  int           nFileSize = 100;          // will store our file size
  byte CR = 0x13;   // define CR (carriage return)
  byte LF = 0x10;   // define LF (line feed)
  string        sMessageToWrite = "ROBOTC IO test!";    // we will write this to the file
  string        sMesageToWrite_2 = "A new line!";       // we will also write this to the file on the next line
  char          incommingChar;                          // this will store each char as we read back in from the file
  string        incommingString[5];                     // this will store the final, fully-read strings (with new strings getting put into new indexes
  int           nLineCounter = 0;                       // this will let us know which line we are on when reading and writing (used as the index to 'incommingString[]')
  OpenWrite(hFileHandle, nIOResult, sFileName, nFileSize);    // open the file for writing (creates the file if it does not exist)
  WriteText(hFileHandle, nIOResult, sMessageToWrite);         // write 'sMessageToWrite' to the file
  WriteByte(hFileHandle, nIOResult, CR);                      // write 'CR' to the file (carriage return)
  WriteByte(hFileHandle, nIOResult, LF);                      // write 'LF' to the file (line feed)
  WriteText(hFileHandle, nIOResult, sMesageToWrite_2);        // write 'sMesageToWrite_2' to the file
  Close(hFileHandle, nIOResult);                              // close the file (DON'T FORGET THIS STEP!)

  wait1Msec(1000);  // just a wait so we can see the variables updating in the ROBOTC debugger in order (this is not necessary)
  OpenRead(hFileHandle, nIOResult, sFileName, nFileSize);     // open our file 'sFileName' for reading
  for(int i = 0; i < nFileSize; i++)                          // iterate through the file until we've hit the end:
    ReadByte(hFileHandle, nIOResult, incommingChar);            // read in a single byte
    if(incommingChar == CR || incommingChar == LF)              // if the incomming byte is a carriage return or a line feed:
      if(incommingChar == LF)                                     // if it's a line feed:
        nLineCounter++;                                             // increment our index (will now store next char on a 'new line' (a new index into our 'incommingString[]')
      incommingString[nLineCounter] += incommingChar;             // append that byte (char) to the end of our final string, at the right index
  Close(hFileHandle, nIOResult);                              // close our file (DON'T FORGET THIS STEP!)
  for(int i = 1; i <= 5; i++)
    nxtDisplayCenteredTextLine(i, incommingString[i-1]);
  while(true);  // infinite loop to keep our program running so that we can view the ROBOTC debugger variables

Bence Feher

Undergraduate Intern - NREC, Robotics Academy
ROBOTC - Testing/Documentation/Developer

Computer Science, Japanese, East Asian Studies
University of Pittsburgh, Konan University 甲南大学

Mon Dec 05, 2011 12:58 pm

Joined: Thu Nov 20, 2014 12:12 pm
Posts: 3
Post Re: Help with file access usage
Is this code fragment compatible with the EV3 as well?

Mon Dec 08, 2014 1:35 pm
Site Admin
Site Admin

Joined: Thu May 24, 2012 12:15 pm
Posts: 722
Post Re: Help with file access usage
Per the ROBOTC for LEGO Mindstorms 4.X downloads page:

Functionality Missing/Still in Development:

EV3 External Controller (TETRIX, MATRIX) Support
Daisy Chaining EV3's together and using chained motors/sensors
Wifi Download and Debugging
Joystick Support for EV3
File System Commands (Read/Write files in a ROBOTC program)

As of right now, file system commands are not fully compatible with the EV3 platform. It is on our list of things to develop, however, and we hope to have a build with this functionality available as soon as possible.

Thank you!

Check out our Blog! And our Facebook page!
Need help? Take a look at our updated help documentation and the ROBOTC Forums.

Mon Dec 08, 2014 2:09 pm

Joined: Sun Nov 30, 2014 4:56 am
Posts: 14
Post Re: Help with file access usage
Hello there,

Well I was playing around with that code sample, and when I tried to compile it it gave me these 2 errors:

**Error**:Procedure call Parameters don't match declaration for 'OpenWrite(TFileHandle & hFileHandle, TFileIOResult & nIoResult, char * pzFileName, short & nFileSize)'
**Error**:Procedure call Parameters don't match declaration for 'OpenRead(TFileHandle & hFileHandle, TFileIOResult & nIoResult, char * pzFileName, short & nFileSize)'

I fixed it by changing thet type of the nFileSize variable to be short, but is there any other way to overcome this problem and make it work with int as well as short?

Sat May 23, 2015 11:13 pm

Joined: Thu Jun 30, 2016 3:10 am
Posts: 4
Post Re: Help with file access usage
I have a friend who owns some websites, one is an info site and two are forums and he got a message from the host that it's getting too big in CPU usage and there is a problem that it could be shut down. He has been working very hard on these sites and has been paying for them out of his own pocket but he really can't afford to pay any more then he already is. Many people use his sites and it would be very disappointing if it was to go down.
He was told by the hosts that if they moved to a RootDS Server they would be able to keep the sites but the problem is that the cost would be much more.
I was just wondering if any of you had any solutions or any suggestions that would help out with the amount of usuage being used. People are already willing to donate some, but I don't think that will be enough. We are guide to u.

Android Training in Chennai | Android Training in Chennai | Android Training in Chennai
Any help would be appreciated.

R Programming Training | DataStage Training | SQL Training | SAS Training | Android Training |

Wed Jan 11, 2017 7:44 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 6 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.