Hi Everyone,
If function A opens a device as a file then calls function B that opens this same device, writes, closes, and returns what is the state of the file that function A is referencing?
Something like:
f = open()
B(); // Opens same file, writes and closes.
write(f, ...)
close(f)
Thanks,
K
解決済! 解決策の投稿を見る。
In fact, open (fopen) creates data (file pointer) in RAM, therefore you have to call close (fclose) in both functions.
However current version of MFS doesn’t allow you to open one file twice for write. MFS isn’t prepared for simultaneous write to one file and this situation should be handled by error code when you try opening file for write for the second time (I didn’t test it).
For now, I do not see any reason why I would like to open one file twice in the same task.
Anyway, next version of MFS will contain this feature (you can write simultaneously) and this new version of MFS will be available in next MQX release (probably MQX 4.2).
Have a great day,
RadekS
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
And about a fopen for write and another fopen to read in the same file, is any problem is MQX4.1.1 ?
In fact, open (fopen) creates data (file pointer) in RAM, therefore you have to call close (fclose) in both functions.
However current version of MFS doesn’t allow you to open one file twice for write. MFS isn’t prepared for simultaneous write to one file and this situation should be handled by error code when you try opening file for write for the second time (I didn’t test it).
For now, I do not see any reason why I would like to open one file twice in the same task.
Anyway, next version of MFS will contain this feature (you can write simultaneously) and this new version of MFS will be available in next MQX release (probably MQX 4.2).
Have a great day,
RadekS
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
I had written a class for debug output that I might want to instantiate on the stack as any random point. I was trying to figure out how to handle the case where I might already have the file open.
Thanks for responding.