NXC File commands
NXC File commands
Hello.
How to create, read, write, write from variable to file and the other way, a file using NXC?
Thanks.
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.
Re: NXC File commands
Oh, Hi!
Here is a test program that writes a deletes a file, creates a file, and writes to a file:
Questions accepted!
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);
}
2Labz.com, My Website
Re: NXC File commands
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
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.
-
- Posts: 76
- Joined: 29 Sep 2010, 06:57
Re: NXC File commands
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
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
Re: NXC File commands
I would recommend getting the NXC Guide from the NBC/NXC website rather than from another site.physics-matt wrote: Also, have a look at the guide
http://www.hsu-hh.de/download-1.4.1.php ... XwQ3q7fePG
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/
http://bricxcc.sourceforge.net/
Re: NXC File commands
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
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/
http://bricxcc.sourceforge.net/
-
- Posts: 76
- Joined: 29 Sep 2010, 06:57
Re: NXC File commands
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
Re: NXC File commands
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
John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
http://bricxcc.sourceforge.net/
Who is online
Users browsing this forum: No registered users and 3 guests