UdpFins.dll V1.0 Fins通信协议以太网通讯动态链接库DLL(以下简称DLL),是为满足工业通信需要,
针对工业领域要求上位机对欧姆龙系列PLC通讯实时采集与控制的组态编程而设计。
本DLL是采用Delphi语言开发的标准串口通讯库,具有以下特点:
1)、遵循欧姆龙最新Fins通信协议UDP以太网模式;
2)、支持多个网络链接并发操作,支持多线程通讯,将通讯对主程序的影响降至最低;
3)、实时性、可靠性好,通用性强;
4)、适用于多PLC(下位机)联网和上位机通信,满足多方面的需要;
5)、函数接口功能全,操作简单,支持欧姆龙PLC的绝大部分地址的读写功能函数;
6)、支持多种操作系统win2000/winXP/Win7/Win8(标准Win32 DLL);
7)、易于快速开发(VC等非RAD开发环境的开发);
8)、采用数组指针调用数据发生与接收,初学者快速入门;对于不方便使用指针的开发环境可采用DLL缓冲区传递;
9)、可在多种编程环境下使用,例如VB、VC、Delphi、PB、Labview、C#、VB.net、易语言等开发环境;
10)、扩展了函数功能读取下位机中的双字、单精度浮点等类型数据,更加符合工业自动化领域的工控软件的开发。
软件版本及相关说明:
UdpFins.dll V1.0 Fins通信协议以太网通讯链接库,实现了对欧姆龙全系列PLC的Fins协议的支持,
对于16位整数和32位整数读取写入均按有符号整数处理,小数的返回按单精度浮点型(2进制浮点)
处理读取方式。提供扩展功能函数,方便用户实现混合数据读取。能够同时开启最大256个网络链接并发
情况下的正常使用。
UdpFins.dll V1.0 分为完美版和单机版两个版本。
龙帅工作室为您提供专业串口、以太网通讯控件,也可为您订制专用通讯协议
串口、以太网控件。目前龙帅系列串口、以太网通讯协议控件包括modbus_rtu、
modbus_tcp、三菱FX PLC编程口、欧姆龙HostLink、欧姆龙Fins串口、
欧姆龙Fins UDP、西门子PPI等多个系列产品。
淘宝店:http://shop34821629.taobao.com
电 话:13912935690
腾讯QQ:157610979
邮 箱:157610979@QQ.com
在VC中使用DLL一般都是采用动态声明的方式,函数说明中给出的是Delphi的函数原型,
在VC中声明时只要注意一下类型的对应即可,Delphi中的LongInt类型对应VC中的int类型
Delphi中的Pchar对应VC中的char* ,下面给出主要函数的声明:
在使用的文件的cpp中声明一个句柄:
HINSTANCE hinstDLL;
用来标识导入的动态链接库。
1)、按下例说明声明相关各个函数:(在cpp文件的头处声明)
typedef int (_stdcall *pOpen)(int NetID, int IpPort, int RecTimeOut, int
ModeCv, char* IpAddress, char* User);
typedef int (_stdcall *pClose)(int
NetID);
typedef int (_stdcall *pTrue)(int NetID);
typedef int (_stdcall
*pWork)(int NetID);
typedef int (_stdcall *pRs)(int NetID, int nodePlc, int nodePc);
typedef
int (_stdcall *pWs)(int NetID, int nodePlc, int nodePc, int State);
typedef
int (_stdcall *pBitForced)(int NetID, int nodePlc, int nodePc, int address, int
Bit, int value, char* Area);
typedef int (_stdcall *pCancelAllF)(int NetID,
int nodePlc, int nodePc);
typedef int (_stdcall *pReadBit)(int NetID, int
nodePlc, int nodePc, int address, int Bit, int Count, char* Area, int*
RxdBuffer);
typedef int (_stdcall *pReadInt)(int NetID, int nodePlc, int
nodePc, int address, int Count, char* Area, int* RxdBuffer);
typedef int
(_stdcall *pWriteBit)(int NetID, int nodePlc, int nodePc, int address, int Bit,
int Count, char* Area, int* TxdBuffer);
typedef int (_stdcall *pWriteInt)(int
NetID, int nodePlc, int nodePc, int address, int Count, char* Area, int*
TxdBuffer);
typedef int (_stdcall *pSet)(int NetID, int nodePlc, int nodePc, int
address, int Bit, char* Area);
typedef int (_stdcall *pReSet)(int NetID, int
nodePlc, int nodePc, int address, int Bit, char* Area);
typedef int (_stdcall
*pReadDInt)(int NetID, int nodePlc, int nodePc, int address, int Count, int*
RxdBuffer);
typedef int (_stdcall *pReadFloat)(int NetID, int nodePlc, int
nodePc, int address, int Count, float* RxdBuffer);
typedef int (_stdcall
*pWriteDInt)(int NetID, int nodePlc, int nodePc, int address, int Count, int*
TxdBuffer);
typedef int (_stdcall *pWriteFloat)(int NetID, int nodePlc, int
nodePc, int address, int Count, float* TxdBuffer);
typedef int (_stdcall *pBitBin)(int value, int Bitaddress);
typedef int
(_stdcall *p32I_16h)(int value);
typedef int (_stdcall *p32I_16l)(int
value);
typedef int (_stdcall *p16I_32I)(int valueH, int valueL);
typedef
int (_stdcall *p32f_16h)(float value);
typedef int (_stdcall *p32f_16l)(float
value);
typedef float (_stdcall *p16I_32f)(int valueH, int
valueL);
typedef int (_stdcall *pInt16Unsign)(int value);
2)、建立动态链接库的新函数名:(在cpp文件的头处声明)
pOpen mOpen;
pClose mClose;
pTrue mTrue;
pWork mWork;
pRs mRs;
pWs mWs;
pBitForced mBitForced;
pCancelAllF
mCancelAllF;
pReadBit mReadBit;
pReadInt mReadInt;
pWriteBit
mWriteBit;
pWriteInt mWriteInt;
pSet mSet;
pReSet mReSet;
pReadDInt mReadDInt;
pReadFloat
mReadFloat;
pWriteDInt mWriteDInt;
pWriteFloat mWriteFloat;
pBitBin mBitBin;
p32I_16h m32I_16h;
p32I_16l m32I_16l;
p16I_32I
m16I_32I;
p32f_16h m32f_16h;
p32f_16l m32f_16l;
p16I_32f
m16I_32f;
pInt16Unsign mInt16Unsign;
3)、导入动态链接库,如例所示:(在cpp文件的OnInitDialog过程建立):
hinstDLL = LoadLibrary("UdpFins.dll");
4)、判断dll文件是否存在并声明并建立动态链接库中的函数与新函数名的对应关系,
如下:(在cpp文件的OnInitDialog过程建立):
if (hinstDLL)
{
mOpen = (pOpen)GetProcAddress
(hinstDLL,"UdpFinsOpen");
mClose = (pClose)GetProcAddress
(hinstDLL,"UdpFinsClose");
mTrue = (pTrue)GetProcAddress
(hinstDLL,"UdpTrue");
mWork = (pWork)GetProcAddress
(hinstDLL,"UdpWork");
mRs = (pRs)GetProcAddress
(hinstDLL,"UdpPlcRs");
mWs = (pWs)GetProcAddress
(hinstDLL,"UdpPlcWs");
mBitForced = (pBitForced)GetProcAddress
(hinstDLL,"UdpBitForce");
mCancelAllF = (pCancelAllF)GetProcAddress
(hinstDLL,"UdpCancelF");
mReadBit = (pReadBit)GetProcAddress
(hinstDLL,"UdpReadBit");
mReadInt = (pReadInt)GetProcAddress
(hinstDLL,"UdpReadInt");
mWriteBit = (pWriteBit)GetProcAddress
(hinstDLL,"UdpWriteBit");
mWriteInt = (pWriteInt)GetProcAddress
(hinstDLL,"UdpWriteInt");
mSet = (pSet)GetProcAddress (hinstDLL,"UdpSet");
mReSet =
(pReSet)GetProcAddress (hinstDLL,"UdpReSet");
mReadDInt =
(pReadDInt)GetProcAddress (hinstDLL,"UdpReadDInt");
mReadFloat =
(pReadFloat)GetProcAddress (hinstDLL,"UdpReadFloat");
mWriteDInt =
(pWriteDInt)GetProcAddress (hinstDLL,"UdpWriteDInt");
mWriteFloat =
(pWriteFloat)GetProcAddress (hinstDLL,"UdpWriteFloat");
mBitBin = (pBitBin)GetProcAddress (hinstDLL,"DecBitBin");
m32I_16h = (p32I_16h)GetProcAddress (hinstDLL,"Int32ToInt_16h");
m32I_16l = (p32I_16l)GetProcAddress (hinstDLL,"Int32ToInt_16l");
m16I_32I= (p16I_32I)GetProcAddress (hinstDLL,"Int16ToInt32");
m32f_16h =
(p32f_16h)GetProcAddress (hinstDLL,"Float32ToInt_16h");
m32f_16l =
(p32f_16l)GetProcAddress (hinstDLL,"Float32ToInt_16l");
m16I_32f=
(p16I_32f)GetProcAddress (hinstDLL,"Int16ToFloat32");
mInt16Unsign =
(pInt16Unsign)GetProcAddress (hinstDLL,"Int16Unsign");
AfxMessageBox("欧姆龙UdpFins.dll已成功载入!");
}
else
{
AfxMessageBox("没找到欧姆龙UdpFins.dll!");
SendMessage(WM_CLOSE);
}
注:双引号中为动态链接库中的原有函数名。
函数中用到了char*型参数,这里介绍下char*与Cstring的相互转换的函数:
(1)char*->CString
char* sz;
CString str;
str.Format("%s",sz); //可以用此函数将读取的值转成字符串
(2) CString -> char*
CString str;
char* sz = str.GetBuffer(0);//可将字符串转成char*给函数赋值
5)、当不再需要使用DLL时记得关闭串口及释放动态链接库,(在OnDestroy事件中释放)
if(hinstDLL)
{
int k = mComTrue(0);
if
(k==1)
{
mClose(0);
}
FreeLibrary(hinstDLL);
}
FINS-TCP / FINS-UDP / FINS-COM 的VB.NET和C#源代码,支持浮点数据,BCD码、16进制字符、双整形数据、二进制字符串,下载地址:
http://blog.sina.com.cn/s/blog_16d7d3ecb0102x3qi.html