⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mbtcp_arm.h

📁 wince环境下的一个EVC的modbus协议通讯的例子程序
💻 H
字号:

// The following ifdef block is the standard way of creating macros which make exporting 
// from a DLL simpler. All files within this DLL are compiled with the MBTCP_ARM_EXPORTS
// symbol defined on the command line. this symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see 
// MBTCP_ARM_API functions as being imported from a DLL, wheras this DLL sees symbols
// defined with this macro as being exported.
#ifdef MBTCP_ARM_EXPORTS
#define MBTCP_ARM_API __declspec(dllexport)
#else
#define MBTCP_ARM_API __declspec(dllimport)
#endif

enum COMM_STATUS { EMPTY, COMM_NO_ERROR, TIMEOUT, BAD_MESSAGE, COMMAND_FAILURE };
//**************************************************************************
// This class is exported from the MBTCP_ARM.dll
//class MBTCP_ARM_API CMBTCP_ARM {
//public:
//	CMBTCP_ARM(void);
	// TODO: add your methods here.
//};

class OMessage
{
enum { BUFFER_SIZE = 500 };
public:
   OMessage();
   ~OMessage();
   void Clear();
   virtual COMM_STATUS IsOk()=0;
   virtual BYTE GetAddress()=0;
   virtual BYTE GetFunction()=0;
   virtual BOOL GetBit( int offset )=0;    // offset of bit from start of group
   virtual WORD GetWord( int offset )=0;   // word offset in group

   virtual void Add( BYTE byte )=0;
   virtual void Finish()=0;
   virtual BOOL MsgDone()=0;

   BYTE     buffer[BUFFER_SIZE];
   BYTE*    data;
   WORD     dataLength;
   WORD     length;
   FILETIME timestamp;
   COMM_STATUS  ok;
};

//**************************************************************************
/* Added by Wilson 2003/6/27 */
class OTcpMessage : public OMessage
{
public:
   OTcpMessage();
   ~OTcpMessage();
   virtual COMM_STATUS IsOk();
   BYTE           GetAddress();
   BYTE           GetFunction();
   BOOL           GetBit( int offset );    // offset of bit from start of group
   WORD           GetWord( int offset );   // word offset in group

   void           Add( BYTE byte );
   void           Finish();
   BOOL           MsgDone();
   void           ConvertData();
};

//**************************************************************************
class ORtuMessage : public OMessage
{
public:
   ORtuMessage();
   ~ORtuMessage();
   virtual COMM_STATUS IsOk();
   BYTE           GetAddress();
   BYTE           GetFunction();
   BOOL           GetBit( int offset );    // offset of bit from start of group
   WORD           GetWord( int offset );   // word offset in group

   void           Add( BYTE byte );
   void           Finish();
   BOOL           MsgDone();
   void           ConvertData();
};

//Modbus TCP functions
MBTCP_ARM_API int MBTCPInit(int iSocketNumber, char *tcpipaddr, int tcpipport); // Return 1==>True 0==>False

extern MBTCP_ARM_API OMessage* MessageTcp(int iSocketNumber, OMessage* msg, DWORD timeout, CAsyncSocket* ModbusSocket);

MBTCP_ARM_API int MBTCP_R_Coils(int iSocketNumber,int iSlaveNumber, int iStartAddress, int iCount, int *iRecv, int iFuncNumber /*1/2 up to the modbus device*/);	//Function 1/2 Return 1==>True 0==>False

MBTCP_ARM_API int MBTCP_W_Coil(int iSocketNumber, int iSlaveNumber, int iCoilAddress, int iCoilStatus);	//Function 15 Return 1==>True 0==>False

MBTCP_ARM_API int MBTCP_R_Registries(int iSocketNumber, int iSlaveNumber, int iStartAddress, int iCount, short *iRecv, int iFuncNumber /*3/4 up to the modbus device*/);	//Function 3/4 Return 1==>True 0==>False

MBTCP_ARM_API int MBTCP_W_Registry(int iSocketNumber, int iSlaveNumber, int iRegAddress, short iRegStatus);	//Function 16 iRegStatus==>-32768~32767 Return 1==>True 0==>False 

MBTCP_ARM_API void MBTCPClose(int iSocketNumber);	//Return 1==>True 0==>False

//Modbus RTU functions
extern MBTCP_ARM_API OMessage* Message(int iPortNumber, OMessage* msg, DWORD timeout);

MBTCP_ARM_API int MBRTUInit(int iPortNumber, int iBaudrate,int iParity, int iDataBit, int iStopBit, int iTimeOut); // Return 1==>True 0==>False

MBTCP_ARM_API int MBRTU_R_Coils(int iPortNumber, int iSlaveNumber, int iStartAddress, int iCount, unsigned char *iRecv, int iFuncNumber /*1/2 up to the modbus device*/);	//Function 1/2 Return 1==>True 0==>False

MBTCP_ARM_API int MBRTU_W_Coil(int iPortNumber, int iSlaveNumber, int iCoilAddress, int iCoilStatus);	//Function 15 Return 1==>True 0==>False

MBTCP_ARM_API int MBRTU_R_Registries(int iPortNumber, int iSlaveNumber, int iStartAddress, int iCount, short *iRecv, int iFuncNumber /*3/4 up to the modbus device*/);	//Function 3/4 Return 1==>True 0==>False

MBTCP_ARM_API int MBRTU_W_Registry(int iPortNumber, int iSlaveNumber, int iRegAddress, short iRegStatus);	//Function 16 iRegStatus==>-32768~32767 Return 1==>True 0==>False 

MBTCP_ARM_API void MBRTUClose(int iPortNumber);	//Return 1==>True 0==>False

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -