📄 sim.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 SIM_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
// SIM_API functions as being imported from a DLL, wheras this DLL sees symbols
// defined with this macro as being exported.
#ifdef SIM_EXPORTS
#define SIM_API __declspec(dllexport)
#else
#define SIM_API __declspec(dllimport)
#endif
// This class is exported from the SIM.dll
class SIM_API CSIM
{
public:
CSIM(void);
// TODO: add your methods here.
};
extern SIM_API int nSIM;
SIM_API int fnSIM(void);
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 nType; //卡件类型
BYTE nFunction; //功能码
BYTE nReg; //请求的寄存器数量
//BYTE nDataType; //数据类型
UINT nTimeOut; //通讯超时时间
BOOL bComm; //通讯是否正常
BYTE byDataBlock[DATABLOCK_LEN]; //寄存器,类似于unsigned char m_byRec[100];
CMyCriticalSection csData;
//通过其实地址和数据类型返回值
long GetVal(BYTE nAddr,BYTE nDataType,float &fVal)
{
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;
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 + -