Since we are reading and writing from MCS we will only create instances of the classes
CPReadMCSFile and CPWriteMCSFile to actually read and write. There are some
member functions in CPReadFile/CPWriteFile and CPFile that we will use, but you will
never instantiate these classes.
All CPFile derived classes of type IMU_MCS_TypeMem should have a header to
identify the application that uses the file and what kind of data it contains. In this section
we will go through an example of how to use the CPMEMFileHeader class to create a file
header as well as how to read and write a file using the CPFile classes.
Reading From MCS
To read from MCS you must create an instance of CPReadMCSFile. You can use one of
the following constructors:
CPReadMCSFile (UCHAR type)
CPReadMCSFile (const char *name, const char *path=NULL, UCHAR type=0)
The first constructor creates CPReadMCSFile without a name or folder. You have to set
these attributes before you can use the file.
The CPReadMCSFile does not have any functions to read data directly. It inherits a few
functions from CPReadFile to read some data types from MCS. These functions include:
int ReadBytes(void *buffer, int nBytes);
virtual char ReadByte();
WORD ReadWord();
int ReadInt();
OBCD ReadDouble();
int BytesRead();
There are also a few important inherited functions from CPFile that should be used before
trying to read a file:
bool IsNotError();
int FileExists();
Here is a simple example of how to open a file and read in an integer:
CPReadMCSFile f(FILE_NAME, FOLDER_NAME);
if (f.IsNotError() && f.FileExists())
{
118