wiki:Docs/Prog/Manual/ApplicationLibraries/lib825ev/File/CFile

Version 6 (modified by Don Wilson, 14 years ago) ( diff )

--

CFile

CFile is a C++ class that is provided to simplify 825 file operations. CFile is a wrapper class around the standard C library FILE object. CFile also provides some useful features such as baud rate setting for the 825 serial ports.

Constructors

CFile(void);
CFile(const string& strFilename);
CFile(const char* pszfilename);

These constructors just create a CFile object without opening a file.

CFile(const string& strFilename, const string& strMode);
CFile(const string& strFilename, const char* pszMode);
CFile(const char* pszFilename, const string& strMode);
CFile(const char* pszFilename, const char* pszMode);

These constructors construct the file object and attempt to open the file.

CFile fileLog("/mnt/fl1/log.txt", "a");
if(fileLog.IsOpen())
{
     fileLog.Print("Gross %s Tare %s Net %s\r\n", FormatGrossWt(1).c_str(), FormatTareWt(1).c_str(), FormatNetWt(1).c_str()); 
     fileLog.Close();
}

Parameters

  • strFilename - filename
  • pszFilename - filename
  • strMode - mode
  • pszMode - mode

Member Functions

Open

Opens a specified file, or using the filename already stored in the object.

bool Open(const string& strFilename, const string& strMode);
bool Open(const string& strFilename, const char* pszMode);
bool Open(const char* pszFilename, const string& strMode);
bool Open(const char* pszFilename, const char* pszMode);
bool Open(const char* pszMode);

Parameters

  • strFilename - filename
  • pszFilename - filename
  • strMode - mode
  • pszMode - mode

Return Value

Returns true if successful or false if unsuccessful.

Remarks

Example

CFile file;
if(file.Open("/tmp/tmpfile", "w") == false)
{
    DisplayText(0, 0, "Error writing temporary file");
}

Close

Closes the file

void Close(void);

Parameters

Function does not accept any parameters

Result

Function does not return any result.

SetSerial

  • bool SetSerial(baud_index baud, data_bit_index = data8, parity_index = parityNone, stop_bit_index = stopOne);

ReadLine

DeleteFile

IsReady

Check the state of the serial CTS input

bool IsReady(void);

Parameters

Function does not accept any parameters.

Return Value

Function returns true if CTS is active, false if CTS is inactive.

Remarks

Example

CFile fileLogOutput("/dev/ttyS1", "w");
if(fileLogOutput.IsOpen())
{
   fileLogOutput.SetRTS(true);
   if(fileLogOutput.IsReady() == false)
   {
      DisplayText(0, 0, "Printer offline, or disconnected");
   }
}

SetRTS

Set the state of the serial RTS output

bool SetRTS(bool bRTSOn = true);

Parameters

  • bRTSOn - true to turn on RTS output, false to turn off RTS output

Return Value

  • Returns true if successfully set RTS state, false otherwise.

Remarks

Example

CFile fileLogOutput("/dev/ttyS1", "w");
fileLogOutput.SetRTS(true);

GetFile

Print

  • void Print(const std::string& fmt, ...);
  • void Print(const char * fmt, va_list& args);
  • void Print(const std::string& fmt, va_list& args);
  • void Print(const char * fmt, va_list& args);

SetNonBlocking

Read

  • bool Read(void * ptr, size_t size);

Write

  • bool Write(void * buf, size_t size);

GetBytesRead

GetbytesWritten

Seek

  • bool Seek(long int offset, long int origin = SEEK_SET);
Note: See TracWiki for help on using the wiki.