..produces the previous behaviour, and setting the last parameter to other values does indeed read the corresponding number of bytes. Mystery solved, thanks.
Hmm, what comes out of it? I would expect it to block until there was actual data available.
"What comes out of it.." depend on what I am trying to connect to.. If I use a pre-existing text file say "A/SOMEFILE.TXT" I can read without any trouble. For what is is worth, in my experiments, I was usually allocated file descriptor 8. I can continue to read past EOF without crashing (I simply get a -1 result code and zero bytes of data).
If I set the mode to 1 (write mode) I can write to the file, over writing the data at the start of the file, rather than appending to it, presumably I need to be a little more sophisticated than basic io allows if I want to find the file length, and append to the file..
Setting the file mode to 2 (rw mode), appears to allow me to write to and read from the file, but I don't see the results of the write, probably I am going about this incorrectly, or perhaps mode 2 is not supported.
If I select file descriptor 0..5 for reading the script does block (I haven't yet tried opening these fds mode 1 or mode 2 (w, or r/w) yet. The camera doesn't completely crash, for example the console timeout kicks in after 10 seconds, but none of the switches work (presumably we are blocking the keyboard task).
If I attempt to open file descriptors 9 onwards, they will open, but beyond 13 I get an error. Presumably we are limited to 12 fds per task.
I tried a couple of other file descriptor names.
/tyCo/0 as discussed before, allows me to both read and write, and honours ioctl , however with nothing on the other end of the UART, the results are unknown...
Presumably however I could wire up the serial port and talk to the camera with a script on the lua end, and a terminal on the other, which opens up some interesting possibilities, for example wiring one of the many cheap blue-tooth modules to any camera and talking to it this way.
I can write to /null (so if you need any data sent down a deep dark hole... )
One other note, perhaps this is already known, malloc() exists, but free() doesn't appear to, at least I couldn't see it in the stubs, however AllocateMemory() and FreeMemory() work for the purposes of this exercise, and this is what I used to allocate the read and write buffers.
Current very messy and hacky lua script attached.