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

📄 comportdll.h

📁 EVC(嵌入式VC++)发的用于串口通信的程序
💻 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 COMPORTDLL_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 
// COMPORTDLL_API functions as being imported from a DLL, wheras this DLL sees symbols
// defined with this macro as being exported.
#ifdef COMPORTDLL_EXPORTS
#define COMPORTDLL_API __declspec(dllexport)
#else
#define COMPORTDLL_API __declspec(dllimport)
#endif
#include <MyCriticalSection.h>

#include "vector"   //include <vector.h>
// This class is exported from the ComPortDLL.dll
class COMPORTDLL_API CComPortDLL {
public:
	CComPortDLL(void);
	// TODO: add your methods here.
};

extern COMPORTDLL_API int nComPortDLL;

COMPORTDLL_API int fnComPortDLL(void);
////////////My Code///////////
const UINT DATABLOCK_LEN=256;
const BYTE D_FLOAT=0;
const BYTE D_LONG=1;
const BYTE D_DWORD=2;
void ModiDataBuf2(unsigned char *buf, long nLen);

//卡件
struct Mod
{
	BYTE nAddr;		 //卡件地址
	BYTE nFunction;  //功能码
	BYTE nReg;       //请求的寄存器数量
	UINT nTimeOut;    //通讯超时时间
	BOOL bComm;      //通讯是否正常
	BYTE byDataBlock[DATABLOCK_LEN]; //存储采集数据,寄存器数据(通道的数据),类似于unsigned char m_byRec[100]; 
	CMyCriticalSection csData;
	//通过其实地址和数据类型返回值
					
	
	long GetVal(BYTE nAddr,BYTE nDataType,float &fVal)//nAddr测点起始地址,nDataType:数据类型
	{//从内存中取测点数据
		unsigned char buf[8];
		csData.Lock();
		switch(nDataType)
		{
		case D_FLOAT:
			memcpy(buf,byDataBlock+nAddr,4);
			ModiDataBuf2(buf,4);
			memcpy(&fVal,buf,4);
			break;
		case D_LONG:
		case D_DWORD:
			memcpy(&fVal,byDataBlock+nAddr,sizeof(DWORD));
			break;
		default:
			
			break;
		}
		csData.Unlock();
		return 0;
		//返回状态
	}

	void SetVal(BYTE nAddr,BYTE nLen,BYTE *buf)
	{
		csData.Lock();
		if((nAddr+nLen)<DATABLOCK_LEN)
			memcpy(byDataBlock,buf,nLen);
		csData.Unlock();
	}

};

//测点
struct Tag
{
	Mod *pMod;
	BYTE nAddr; //起始地址
	BYTE nDataType;  //数据类型
};

std::vector<Mod*> m_arMod; //向量m_arMod声明 

std::vector<Tag*>m_arTag; 
//可以考虑用CArray


static UINT DrvPoll(LPVOID pParam);
static UINT MonitorCallback(unsigned char *hBuf, int nLen, LPARAM lParam);
bool OpenComm();
bool LoadModSet();

⌨️ 快捷键说明

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