#pragma once
#include <functional>
#include <vector>
#include <string>
#include <list>
#ifdef LIBSERIALWIN_EXPORTS
#define LIBSERIAL_PORT_API __declspec(dllexport)
#else
#define LIBSERIAL_PORT_API __declspec(dllimport)
#endif
#define BYTE unsigned char
#define DWORD unsigned long
class LIBSERIAL_PORT_API WinSerial
{
public:
WinSerial();
~WinSerial();
/*
Result值参考:
enum {
SERIALPORT_ENUMFAILED = -6,
SERIALPORT_USER_TIMEOUT = -5,
SERIALPORT_HARD_TIMEOUT = -4,
SERIALPORT_PARMERR = -3,
SERIALPORT_NOTEXIST = -2,
SERIALPORT_OPENERR = -1,
SERIALPORT_SUCCESS = 0,
SERIALPORT_OPENED = 1
};
*/
void* gSerialPort(int nCom, int& result, DWORD baudRate = 38400,
BYTE byteParity = 0, //0为无奇偶校验
BYTE nByteWidth = 8,
BYTE byteStopBits = 0
);
int GetAllPortName(std::list<std::string>& ListPort);
/*
状态查询返回值参考:
{
EPortUnknownError = -1, // 未知错误
EPortAvailable = 0, // 可用
EPortNotAvailable = 1, // 不可用
EPortInUse = 2 // 被占用
}*/
int CheckPort(int portNo);
bool IsOpen(void* pts) const;
void Close(void* pts);
long Read(void* pts,void *pData, int nNumberOfBytesToRead, DWORD dwMsTimeout = 3000);
long Write(void* pts, const void *pData, int nNumberOfBytesToWrite, DWORD dwMsTimeout = 3000);
static WinSerial* ginstance();
};
#define WSerial WinSerial::ginstance()