Major update:

- Convert PortCore functions into Class
Bug fixes:
  - Correctly handle socket close event (return false on read)
  - Only write to port/socket if valid file handle
This commit is contained in:
Charl Wentzel
2016-05-17 07:44:08 +02:00
parent 264169e525
commit d7facce4de
3 changed files with 163 additions and 112 deletions

View File

@@ -12,7 +12,7 @@
/* none */
// Standard C/C++ Libraries
/* none */
#include <sys/time.h>
//---------------------------------------------------------------------------
@@ -28,13 +28,36 @@
#define SW_FLOWCTRL 2
//---------------------------------------------------------------------------
// Port Functions
int OpenPort( const char * PortName );
bool ClosePort();
bool ConfigSerialPort( int Baud, short DataBits, short StopBits, short Parity, short FlowCtrl, int Wait );
// Port Core Class
class CPortCore
{
private:
// Port Def
int Handle;
char * Name;
bool ReadPort();
bool MaintainPort( int SocketHandle );
// PortIn buffer
char * InBuffer;
int InBufLen;
int InLen;
int BytesRead;
// PortIn Timer
timeval InStart;
long InTimeout; // millisecs
public:
CPortCore( const char * PortName, const int PortInBufLen );
~CPortCore();
bool Open();
bool Close();
bool Config( int Baud, short DataBits, short StopBits, short Parity, short FlowCtrl, int Wait );
int GetHandle() { return Handle; };
bool Read();
bool Maintain( int SocketHandle );
};
//---------------------------------------------------------------------------
#endif /* PORTCORE_H_ */