Writing to text files

Hey everyone,

Is it possible to write to text files in RobotC for Vex Cortex?

Thanks in advance for any assistance.

Unfortunately not. :frowning:

See this thread on the ROBOTC forums.
http://www.robotc.net/forums/viewtopic.php?f=11&t=4314

//Andrew

Hmmm, that is rather unfortunate. Thanks for the reply. Do you know if they are gonna have support for that feature anytime in the near future?

I don’t know. All I know is from the previously linked thread.

//Andrew

Does the cortex have any sort of instruction-set one can use to interface with the non-volatile memory on the cortex MCU? It could very easily be hacked into an easyc application using the __asm tags(which easyc does support)… I wouldn’t mind writing a module for it if someone directed me to a documentation on these instructions. If it could potentially be done in robotC, it can definitely be done with easyC. A filesystem wouldn’t be super difficult to setup - well, rather, a simple one.

Mind you, it could be significantly more difficult or even impossible to do with robotc. If the robotC developers choose not to expose the functionality, they might not have intermediate instruction for the operation - and since you’re stuck in the virtual machine there is really no way I can see you executing natively executable code. If the instructions do exist you’ll have to do a lot of digging to find it. (Mind you, some of you may know some hacks to get around the virtual machine…) I believe you’d also be unable to access memory outside of the virtual-machine. Hmm, I’m also thinking RobotC code is much larger when uploaded (Since it carries a Virtual Machine around with it) which might give you significantly less room to work with. Theroetically speaking though, the compiled .hex document should be much smaller (due to a higher-level instruction-set); but that plus the Virtual Machine would probably be much larger. (The general idea with virtual machines is you have say 20 applications using the same VM and one VM which would ultimately end up saving space. However if you have one VM and one very small (as most are here) application using it, you don’t save any and might even end up taking up more space)

I did some reading and apparently the Flash memory module may be mapped into the our virtual address space somewhere (I wouldn’t know where as I can’t find anything on the cortex). I doubt though that I would have write access to this region of memory, I haven’t worked too much with the ARM instruction-set so I wouldn’t know how to get into this region of memory. I’d have to do a lot of digging to find out I fear.

*As a side note: This is why I enjoy working in unmanaged languages when I am working close to computer hardware.

Annnyway: You wouldn’t want to write text. It would probably be loads easier to serialize your data into a SIMPLE structure(one with just primitive data-types, anything more than that (references\pointers) gets complicated very quickly) It would be easier to store your data into a structure that contains information, copy it into your file-system then load it directly into memory.

i.e


typedef struct RobotInformation
{
    char m_sName[20];
    unsigned int m_uiTeamNumber;
    unsigned char m_motor1;
    //etc...
} ROBOTINFORMATION, *PROBOTINFORMATION;

I can see now why RobotC might be hesitant to actually implement a file-system. All the information would need to be stored as text unless they implemented a serialization module(which IMHO is kind of overblown for robotics) - and text-parsing is hell(Something HTTP apparently forgot…)

I think easyC should take advantage of their situation and implement a file-system. - Or ANY API for IO to non-volatile memory, we can setup the file-system ourselfs!

Actually ROBOTC for Mindstorms has allowed you to write to and read from files on the NXT for a long time. There’s no reason that it can’t be implemented on the Cortex. This is the reason I got for its absence when I asked about it: http://robotc.net/forums/viewtopic.php?f=11&t=4039

Its not that RobotC can’t support it - only that if they hadn’t, there would be no way around it. They manage your interface with the Cortex MCU, opposed to easyC, where it is managed directly by the user. - which is why it might be possible with easyc, and (less likely) possible with RobotC(not that it can’t be implemented in the future).

I know it must be possible, but I am unsure how exactly one accesses the Flash memory module. I have tried looking around, and, as I said, I think it might be mapped somewhere in our virtual address space but I haven’t the slightest clue where. Maybe the RobotC team would know. It must be in some document somewhere :S

Well, I have found situations where ROBOTC crashes (though the debugger does catch it in run time sometimes). Perhaps there could be some sort of buffer-overflow exploit to allow native code to be run on the cortex :slight_smile:
The simpler way would be to just modify the ROBOTC Virtual Machine code to allow for file IO instructions, in the same way that John Hansen modified the NXT Firmware to allow for more features in his NXC language.

You know you shouldn’t be inside of a VM when you trying to escape your virtual-machine via buffer-overflow exploits. Lol, just kidding.

Yeah, I suppose the first step is to figure out how to do it in easyC, and then one could try translating that into the proper instructions for robotc.

Some relavent information on the topic that I found: https://vexforum.com/t/anyone-want-to-give-this-code-a-try/21107/1

In case any interested users land here.