NXC File commands

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
Post Reply
borntoown
Posts: 58
Joined: 14 Nov 2010, 16:58

NXC File commands

Post by borntoown »

Hello.
How to create, read, write, write from variable to file and the other way, a file using NXC?
Thanks.
Last edited by borntoown on 26 Nov 2010, 17:53, edited 1 time in total.
B2O productions are the best for the best.
dudmaster
Posts: 171
Joined: 06 Oct 2010, 02:38
Location: Texas, Santa Fe
Contact:

Re: NXC File commands

Post by dudmaster »

Oh, Hi!

Here is a test program that writes a deletes a file, creates a file, and writes to a file:

Code: Select all

task main() {
byte handle;
int cnt;
string str = "For AnotherRandomPerson C=";
DeleteFile ("Hello.txt");
CreateFile("Hello.txt", 300, handle);
WriteString(handle, str, cnt);
CloseFile(handle);
}
Questions accepted!
2Labz.com, My Website
borntoown
Posts: 58
Joined: 14 Nov 2010, 16:58

Re: NXC File commands

Post by borntoown »

You should have explained. I'm asking about that...
Ok:

1) Why there is a byte variable?
2)What's handle?
3)300 what?
4)WriteString for text, what about numbers? logic?
5) what is cnt?
6)WriteString(handle, STR?, CNT?)? Why is those?

thanks
B2O productions are the best for the best.
physics-matt
Posts: 76
Joined: 29 Sep 2010, 06:57

Re: NXC File commands

Post by physics-matt »

Have you looked at the documentation?

http://bricxcc.sourceforge.net/nbc/nxcd ... index.html

Also, have a look at the guide

http://www.hsu-hh.de/download-1.4.1.php ... XwQ3q7fePG

section 3.8, "Loader Module".

There's also been a discussion on this sort of thing in another thread:

https://sourceforge.net/apps/phpbb/mind ... ?f=1&t=255

Hopefully you will find the answers you need in there somewhere!

Matt
borntoown
Posts: 58
Joined: 14 Nov 2010, 16:58

Re: NXC File commands

Post by borntoown »

Nope, sorry. I didnt get it yet.
B2O productions are the best for the best.
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: NXC File commands

Post by afanofosc »

physics-matt wrote: Also, have a look at the guide

http://www.hsu-hh.de/download-1.4.1.php ... XwQ3q7fePG
I would recommend getting the NXC Guide from the NBC/NXC website rather than from another site.

http://bricxcc.sourceforge.net/nbc/

You'll find the guide in the NXC Docs section.

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: NXC File commands

Post by afanofosc »

Also, the NXC help files include a number of examples that show how to do file i/o in NXC. If you have specific questions about specific API functions it would be easier to help you than trying to guess exactly what information you need in order to get you going.

The API functions generally all use a file handle which can be stored in a byte variable. If you open an existing file or create a new file you have to keep the handle if you want to do anything else with the file, such as close it or write to it or read from it. When you create a new file on the NXT you have to provide the size of the file. That's the "300" that was used in the example code posted above. You can use whatever size you like. Once you write that many bytes to the file you create then you can't write any more data to the file. The API functions that let you write to a file return status codes that help you determine whether the operation succeeded or if something went wrong what exactly went wrong.

The NXC Guide and help files do a reasonably decent job of explaining a lot of this. Definitely read the loader module section.

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
physics-matt
Posts: 76
Joined: 29 Sep 2010, 06:57

Re: NXC File commands

Post by physics-matt »

afanofosc wrote: http://bricxcc.sourceforge.net/nbc/

You'll find the guide in the NXC Docs section.
I could't find the old version of the NXC guide on the BricxCC site - before it became 2000 something pages of function definitions. I like the old version because I thought it had quite a lot more explanation in it (or perhaps I just haven't found it in the new version?).

Any particular reason you changed it, other than the fact it is probably now quite out of date?

Matt
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: NXC File commands

Post by afanofosc »

To the best of my knowledge the larger guide contains everything that the old guide had in it. If not then I would like to know about it. Though the PDF is many pages longer the bulk of the old guide content should be right at the start of the new guide. And there is always PDF search and bookmarks for the sections of interest.

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests