123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- #pragma once
- // 下列 ifdef 块是创建使从 DLL 导出更简单的
- // 宏的标准方法。此 DLL 中的所有文件都是用命令行上定义的 TCPIPSCF_EXPORTS
- // 符号编译的。在使用此 DLL 的
- // 任何其他项目上不应定义此符号。这样,源文件中包含此文件的任何其他项目都会将
- // TCPIPSCF_API 函数视为是从 DLL 导入的,而此 DLL 则将用此宏定义的
- // 符号视为是被导出的。
- #ifndef TCPIPSCF_EXPORTS
- #ifdef _WIN64
- #ifdef _DEBUG
- #pragma comment(lib, "TcpipSCFX64D.lib")
- #else
- #pragma comment(lib, "TcpipSCFX64.lib")
- #endif
- #else
- #ifdef _DEBUG
- #pragma comment(lib, "TcpipSCFD.lib")
- #else
- #pragma comment(lib, "TcpipSCF.lib")
- #endif
- #endif
- #endif
- #ifdef TCPIPSCF_EXPORTS
- #define TCPIPSCF_API __declspec(dllexport)
- #define TCPIPSCF_C_API extern "C" __declspec(dllexport)
- #else
- #define TCPIPSCF_API __declspec(dllimport)
- #define TCPIPSCF_C_API extern "C" __declspec(dllimport)
- #endif
- #include "SCF.h"
- #include "ResDataObject.h"
- #include <winsock2.h>
- TCPIPSCF_C_API SCF* GetSCF();
- TCPIPSCF_C_API void ReleseSCF(SCF* p);
- // 此类是从 TcpipSCF.dll 导出的
- class TCPIPSCF_API TcpipSCF : public SCF{
- HANDLE hCom;
- int ConnectTcpip(const char *ip, WORD port, DWORD timeout);
- public:
- TcpipSCF(void);
- virtual ~TcpipSCF();
- //设置连接,参数也由json传过来
- /*
- {
- "connect":"COM",
- "port":"COM1",
- "baudrate":"3200",
- "bytesize":"8",
- "parity":"1",
- "stopbits":"1",
- }
- */
- int Connect(ResDataObject & Connectprameters, PacketParser callback = NULL, SCF_TRANSFERTYPE TransferType = SCF_NORMAL_TRANSFER, DWORD CommunicateTimeout = 75000);
- //断开连接
- void Disconnect();
- //判断是否连接
- bool isConnected();
- const char* GetConnectionType();
- //将数据包通过SCF进行发送
- int SendPacket(const char *pPacket, DWORD length, DWORD timeout);
- int SendPacket(SCFPacket *pPacket, DWORD timeout);
- protected:
- string *m_pIp;
- WORD m_Port;
- bool Connected;
- hostent hes;
- servent servs;
-
- SOCKET Socketfd;
- SOCKADDR_IN sa;
- unsigned long tulong;
- unsigned long *tulongptr;
- int Error;
- int ReadData(char *pPacket, DWORD length, DWORD timeout);
- struct hostent * Gethostbyname(const char *name1);
- struct servent * Getservbyname(const char *name, const char *prot);
- };
|