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:
37
PortCore.h
37
PortCore.h
@@ -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_ */
|
||||
|
||||
Reference in New Issue
Block a user