67 lines
2.3 KiB
C++
67 lines
2.3 KiB
C++
//---------------------------------------------------------------------------
|
|
|
|
#ifndef SocketPortH
|
|
#define SocketPortH
|
|
//---------------------------------------------------------------------------
|
|
#if defined( _BORLAND )
|
|
#include <vcl.h>
|
|
#endif
|
|
|
|
|
|
#include <string>
|
|
#if defined(_WIN32) || defined(_WINDOWS)
|
|
#include <winsock2.h>
|
|
#else
|
|
#include <sys/socket.h>
|
|
#include <sys/stat.h>
|
|
#include <sys/types.h>
|
|
#include <arpa/inet.h> //inet_addr
|
|
#include <unistd.h>
|
|
#include <stdio.h>
|
|
#endif
|
|
|
|
#include "Port.h"
|
|
//---------------------------------------------------------------------------
|
|
//typedef void *HANDLE;
|
|
//---------------------------------------------------------------------------
|
|
//std::string getComName(int num);
|
|
//---------------------------------------------------------------------------
|
|
class SocketPort: public Port
|
|
{ private:
|
|
#if defined(_WIN32) || defined(_WINDOWS)
|
|
SOCKET my_sock; //Socket handle
|
|
#else
|
|
int my_sock;
|
|
#endif
|
|
protected:
|
|
bool bOpen; //Состояние порта
|
|
public:
|
|
//std::string ComNumber; //Номер ком порта
|
|
//int BaudRate; //Скорость ком порта DWORD
|
|
|
|
SocketPort();
|
|
virtual ~SocketPort();
|
|
bool Open(const char* IPAddress,int PortNo);
|
|
//bool Open(std::string ComNumber);
|
|
//bool Open(std::wstring ComNumber);
|
|
//bool setBaudRate();
|
|
bool SetTimeout(unsigned long time); //Сколько ждать данных (Для чтения и запииси)
|
|
bool isOpen(){ return bOpen; };
|
|
|
|
bool Close(); //Разорвать связь
|
|
//bool Setup(int num = -1); //Настройка параметров ком порта
|
|
unsigned long Write(const void* lpBuffer,unsigned long nNumberOfBytesToWrite);
|
|
//unsigned long WriteString(std::string str);
|
|
unsigned char WriteChar(signed char ch);
|
|
unsigned char WriteUChar(unsigned char ch);
|
|
unsigned char WriteUInt(unsigned int val);
|
|
int writeUTF8(std::string str);
|
|
int Read(void* lpBuffer,unsigned long nNumberOfBytesToRead);
|
|
int ReadAll(void* lpBuffer,unsigned long nNumberOfBytesToRead); //Попытаться прочесть данные за несколько проходов
|
|
int ReadR(void* lpBuffer,unsigned long nNumberOfBytesToRead);
|
|
|
|
//unsigned char ReadUInt1(bool* b);
|
|
};
|
|
//---------------------------------------------------------------------------
|
|
#endif
|