Week 2 of the Function Block Friday posts is upon us and this week we are featuring ordinary file read and write blocks. Every programmer will be familiar with how files are accessed programmatically and Lucid does nothing unusual in this respect other than condense many lines of code into a single simple function block.

Let’s start with reading data from a file with the simple “File Read Block”. This function block allows you to read data from any file in your application’s user directory.

-> As with any programming language the process starts with opening the file, checking it is open and then requesting to read data which may be the entire file or in chunks. When you’re done make sure you close the file!

For writing data It’s just as straightforward – just drag it in the “File Write Block” and connect it to “open” then write your date (again in chunks or the whole thing) and close it.

The inxware platform provides file access on even the simplest flash-based devices using an ultralight file system.

-> Want to read a configuration file? Use the Read block to read simple delimited text, fixed width binary or structured data such as JSON or XML and write the same with external string formatting function blocks. (Slide 2)

-> Need to log sensor data? The Write block has you covered using automatic delimiter insertion of fixed width binary data, whichever suites best! (Slide 3)

-> Read files created by other programs, downloaded files, or write files that can be processed by different tools.

With Lucid’s File I/O blocks, managing data on your embedded device is as easy as on a server or desktop application.