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

📄 comtrans.cpp

📁 一个dll演示代码 用于串口通信的。 类似于工控的驱动
💻 CPP
字号:
// ComTrans.cpp : Defines the entry point for the DLL application.
//

#include "stdafx.h"
#include "ComTrans.h"
#include "PortTrans.h"

BOOL APIENTRY DllMain( HANDLE hModule, 
                       DWORD  ul_reason_for_call, 
                       LPVOID lpReserved
					 )
{
    switch (ul_reason_for_call)
	{
		case DLL_PROCESS_ATTACH:
		case DLL_THREAD_ATTACH:
		case DLL_THREAD_DETACH:
		case DLL_PROCESS_DETACH:
			break;
    }
    return TRUE;
}


// This is an example of an exported variable
COMTRANS_API int nComTrans=0;

// This is an example of an exported function.
COMTRANS_API int fnComTrans(void)
{
	return 42;
}

// This is the constructor of a class that has been exported.
// see ComTrans.h for the class definition
CComTrans::CComTrans()
{ 
	return; 
}
// 声明串行口操作对象
 COMTRANS_API CPortTrans *pCom =  new CPortTrans;
/*---------------------------串口操作----------------------*/
//参数初始化串口
extern "C" COMTRANS_API bool InitPortExt( int pPort, int nBaudRate, int nParity, int nByteSize, int nStopBits,int nTimeout)
{
	return pCom->InitComExt(pPort,nBaudRate,nParity,nByteSize,nStopBits, nTimeout);
}
//打开端口
extern "C" COMTRANS_API bool  OpenPort()
{
	return pCom->OpenCom();
}
//关闭端口
extern "C" COMTRANS_API bool  ClosePort()
{
	return pCom->CloseCom();
}
//设置串口
extern "C" COMTRANS_API bool  SetPort(const int Pro, int Value)
{
	 return pCom->SetCom(Pro,Value);
}
//获取串口设置
extern "C" COMTRANS_API int  GetPortSet(const int Pro)
{
 	return pCom->GetComSet(Pro);

}
//获取串口状态
extern "C" COMTRANS_API bool  GetPortState()
{
	return pCom->GetComState();
	
}
/*-------------------------设备操作--------------------*/
//发送设备命令
extern "C" COMTRANS_API bool  SendEquipmentCommand(const int EquipmentAddress,const int CommandID)
{
	return pCom->SendEquipmentCommand(EquipmentAddress,CommandID);
}
//设置设备属性
extern "C" COMTRANS_API bool SetEquipmentData(const int EquipmentAddress,const int Pro,const int Setvalue)
{
	return pCom->SetEquipmentData(EquipmentAddress,Pro,Setvalue);
}
//获取pv数据命令
extern "C" COMTRANS_API bool  SendGetPVCommand(const int EquipmentAddress)
{
	return pCom->SendGetPVCommand(EquipmentAddress);
}
//获取sv数据命令
extern "C" COMTRANS_API bool  SendGetSVCommand(const int EquipmentAddress)
{
	return pCom->SendGetSVCommand(EquipmentAddress);
}
//获取pv数据
extern "C" COMTRANS_API float   GetPVData()
{
	return pCom->GetPVData();
}
//获取sv数据
extern "C" COMTRANS_API float  GetSVData()
{
	return pCom->GetSVData();
}
//获取设备数据
extern "C" COMTRANS_API float  GetEquipmentData()
{
      return pCom->GetEquipmentData();
}
	
/*-------------------错误处理----------------*/
//获取最后一条错误文本
extern "C"  COMTRANS_API void	 GetLastErrorText(char **returnvalue)
{
   *returnvalue =  pCom->GetLastErrorText();
}
//获取最后一条错误类型编号
extern "C"  COMTRANS_API int GetLastErrorNumber()
{
	return pCom->GetLastErrorNumber();
}

⌨️ 快捷键说明

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