Version 3 (modified by 15 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(); }
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 ¶
Returns true if successful or false if unsuccessful.
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 ¶
bool ReadLine(std::string& str);
DeleteFile ¶
static bool DeleteFile(std::string& filepath); static bool DeleteFile(const char* filepath);
bool DeleteFile(void);
IsReady ¶
bool IsReady(void);
SetRTS ¶
bool SetRTS(bool on = true);
GetFile ¶
FILE* GetFile(void);
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 ¶
void SetNonBlocking(void);
Read ¶
bool Read(void * ptr, size_t size);
Write ¶
bool Write(void * buf, size_t size);
GetBytesRead ¶
size_t GetBytesRead(void);
GetbytesWritten ¶
size_t GetBytesWritten(void);
Seek ¶
bool Seek(long int offset, long int origin = SEEK_SET);