wjun7610
级别: 略有小成
精华主题: 0
发帖数量: 127 个
工控威望: 249 点
下载积分: 708 分
在线时间: 31(小时)
注册时间: 2007-09-16
最后登录: 2024-11-08
查看wjun7610的 主题 / 回贴
楼主  发表于: 2011-04-05 15:29
图片:
Omron_HostLink.dll V3.2 HostLink通信协议串口通讯动态链接库DLL(以下简称DLL),是为满足工业通信需要,

针对工业领域要求上位机对欧姆龙系列PLC通讯实时采集与控制的组态编程而设计。

本DLL是采用Delphi语言开发的标准串口通讯库,具有以下特点:

1)、遵循欧姆龙HostLink通信协议;

2)、支持多串口并发操作,支持多线程串口通讯,将串口通讯对主程序的影响降至最低;

3)、实时性、可靠性好,通用性强;

4)、适用于多PLC(下位机)联网和上位机通信,满足多方面的需要;

5)、函数接口功能全,操作简单,支持欧姆龙PLC的绝大部分地址的读写功能函数;

6)、支持USB、PC扩展卡等扩展串口号;

7)、支持多种操作系统win9x/win2000/winXP(标准Win32 DLL);

8)、易于快速开发(VC等非RAD开发环境的开发);

9)、更新原有函数调用方式采用数组调用数据发生与接收,初学者快速入门;

10)、可在多种编程环境下使用,例如VB、VC、Delphi、PB、Labview、易语言等开发环境;

11)、扩展了函数功能读取下位机中的双字、单精度浮点等类型数据,更加符合工业自动化领域的工控软件的开发。

软件版本更新及相关说明:

Omron_HostLink.dll V3.2 HostLink通信协议串口通讯链接库,实现了对欧姆 龙全系列PLC的HostLink协议的支持,

(删减了一些特权指令)wangjun于2010年在原有omron.dll V2.0版基础上的更新版,重写了函数结构,采用数据接收

和发送缓冲区(数组)方式传递,读出和写入单元数据使用更方便。对于16位整数和32位整数读取写入均按有符号整数

处理,小数的返回按单精度浮点型(2进制浮点)处理读取方式。提供扩展功能函数,方便用户实现混合数据读取。

能够同时满足32个串口并发情况下的正常使用。

Omron_HostLink.dll V3.2 分为完美版和单机版两个版本,本DLL于2010年最新规整优化了部分源码,

通过DLL发送缓存区与接收缓存区数据传递的功能扩展,使多语言环境的使用更加便利。

全新的串口通信DLL控件,完美的VB、VC、delphi例程及工件手册是,广大立志利用各类高级语言进行上位机软件开发的首先工具。

淘宝店:http://shop34821629.taobao.com

电 话:13912935690 025-84359545

腾讯QQ:157610979

邮 箱:157610979@QQ.com

wjun7610@yahoo.com.cn

chinawanglong@163.com
wjun7610
级别: 略有小成
精华主题: 0
发帖数量: 127 个
工控威望: 249 点
下载积分: 708 分
在线时间: 31(小时)
注册时间: 2007-09-16
最后登录: 2024-11-08
查看wjun7610的 主题 / 回贴
1楼  发表于: 2011-04-05 15:32
在VC中使用DLL一般都是采用动态声明的方式,函数说明中给出的是Delphi的函数原型,

在VC中声明时只要注意一下类型的对应即可,Delphi中的longint类型对应VC中的int类型

Delphi中的Pchar对应VC中的char* ,下面给出主要函数的声明:

在使用的文件的cpp中声明一个句柄:

HINSTANCE hinstDLL;

用来标识导入的动态链接库。

1)、按下例说明声明相关各个函数:(在cpp文件的头处声明)

typedef int (_stdcall *pOpen)(int nport, int BaudRate, int DataBits, char* Parity, int StopBits, char* User);
typedef int (_stdcall *pClose)(int nport);
typedef int (_stdcall *pSetDelay)(int nport);
typedef int (_stdcall *pComTrue)(int nport);
typedef int (_stdcall *pComWork)(int nport);

typedef int (_stdcall *pMS)(int nport, int node);
typedef int (_stdcall *pSC)(int nport, int node, int State);
typedef int (_stdcall *pMM)(int nport, int node);
typedef int (_stdcall *pTS)(int nport, int node);
typedef int (_stdcall *pReadInt)(int nport, int node, int address, int Count, char* Order, int* RxdBuffer);
typedef int (_stdcall *pReadTc)(int nport, int node, int address, int Count, int* RxdBuffer);
typedef int (_stdcall *pWriteInt)(int nport, int node, int address, int Count, char* Order, int* TxdBuffer);

typedef int (_stdcall *pSetF)(int nport, int node, int address, int Bit, char* Order);
typedef int (_stdcall *pReSetF)(int nport, int node, int address, int Bit, char* Order);
typedef int (_stdcall *pCancelF)(int nport, int node, int address, int Bit, char* Order);
typedef int (_stdcall *pCancelAllF)(int nport, int node);

typedef int (_stdcall *pSet)(int nport, int node, int address, int Bit, char* Order);
typedef int (_stdcall *pReSet)(int nport, int node, int address, int Bit, char* Order);
typedef int (_stdcall *pReadBit)(int nport, int node, int address, int Bit, int Count, char* Order, int* RxdBuffer);
typedef int (_stdcall *pReadDInt)(int nport, int node, int address, int Count,int* RxdBuffer);
typedef int (_stdcall *pReadFloat)(int nport, int node, int address, int Count, float* RxdBuffer);
typedef int (_stdcall *pWriteDInt)(int nport, int node, int address, int Count, int* TxdBuffer);
typedef int (_stdcall *pWriteFloat)(int nport, int node, 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);

2)、建立动态链接库的新函数名:(在cpp文件的头处声明)

pOpen mOpen;
pClose mClose;
pSetDelay mSetDelay;
pComTrue mComTrue;
pComWork mComWork;

pMS mMS;
pSC mSC;
pMM mMM;
pTS mTS;
pReadInt mReadInt;
pReadTc mReadTc;
pWriteInt mWriteInt;

pSetF mSetF;
pReSetF mReSetF;
pCancelF mCancelF;
pCancelAllF mCancelAllF;

pSet mSet;
pReSet mReSet;
pReadBit mReadBit;
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;

3)、导入动态链接库,如例所示:(在cpp文件的OnInitDialog过程建立):

hinstDLL = LoadLibrary("Omron_HostLink.dll");

4)、判断dll文件是否存在并声明并建立动态链接库中的函数与新函数名的对应关系,

如下:(在cpp文件的OnInitDialog过程建立):

if (hinstDLL)
{
mOpen = (pOpen)GetProcAddress (hinstDLL,"OmronComOpen");
mClose = (pClose)GetProcAddress (hinstDLL,"OmronComClose");
mSetDelay = (pSetDelay)GetProcAddress (hinstDLL,"OmronSetDelay");
mComTrue = (pComTrue)GetProcAddress (hinstDLL,"OmronComTrue");
mComWork = (pComWork)GetProcAddress (hinstDLL,"OmronComWork");

mMS = (pMS)GetProcAddress (hinstDLL,"OmronMS");
mSC = (pSC)GetProcAddress (hinstDLL,"OmronSC");
mMM = (pMM)GetProcAddress (hinstDLL,"OmronMM");
mTS= (pTS)GetProcAddress (hinstDLL,"OmronTS");
mReadInt = (pReadInt)GetProcAddress (hinstDLL,"OmronReadInt");
mReadTc = (pReadTc)GetProcAddress (hinstDLL,"OmronReadTc");
mWriteInt = (pWriteInt)GetProcAddress (hinstDLL,"OmronWriteInt");

mSetF = (pSetF)GetProcAddress (hinstDLL,"OmronSetF");
mReSetF = (pReSetF)GetProcAddress (hinstDLL,"OmronReSetF");
mCancelF = (pCancelF)GetProcAddress (hinstDLL,"OmronCancelF");
mCancelAllF = (pCancelAllF)GetProcAddress (hinstDLL,"OmronCancelAllF");

mSet = (pSet)GetProcAddress (hinstDLL,"OmronSet");
mReSet = (pReSet)GetProcAddress (hinstDLL,"OmronReSet");
mReadBit = (pReadBit)GetProcAddress (hinstDLL,"OmronReadBit");
mReadDInt = (pReadDInt)GetProcAddress (hinstDLL,"OmronReadDInt");
mReadFloat = (pReadFloat)GetProcAddress (hinstDLL,"OmronReadFloat");
mWriteDInt = (pWriteDInt)GetProcAddress (hinstDLL,"OmronWriteDInt");
mWriteFloat = (pWriteFloat)GetProcAddress (hinstDLL,"OmronWriteFloat");

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");

AfxMessageBox("Omron_HostLink.dll已成功载入!");
}
else
{
AfxMessageBox("没找到Omron_HostLink.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(mnport);
if (k==1)
{
mClose(mnport);
}
FreeLibrary(hinstDLL);
}
wjun7610
级别: 略有小成
精华主题: 0
发帖数量: 127 个
工控威望: 249 点
下载积分: 708 分
在线时间: 31(小时)
注册时间: 2007-09-16
最后登录: 2024-11-08
查看wjun7610的 主题 / 回贴
2楼  发表于: 2011-04-05 15:35
上面的DLL使用要点也适用于其他各种windows标准DLL的VC调用。
yamqq
雅马哈,爱普生,电装机器人。
级别: 网络英雄

精华主题: 0
发帖数量: 1717 个
工控威望: 5539 点
下载积分: 24618 分
在线时间: 300(小时)
注册时间: 2008-05-05
最后登录: 2024-12-24
查看yamqq的 主题 / 回贴
3楼  发表于: 2011-04-06 16:31
楼主,你out了,现在是基于fins的了!本来想把源码贴出来,想想还是不要断了你的财路,只把通讯协议贴一些出来吧
SUDT ACCESSPORT LOG FILE - Monitor mode

监控: COM8
创建时间: 2011-03-19, 14:35:30
计算机名: J2
系统版本: Microsoft Windows XP Professional Service Pack 3 (Build 2600)

#       Time        Function                        Data ( Hex )    

1       [00000000]  IRP_MJ_CREATE                   Port Opened - vb6.exe
2       [00000001]  IOCTL_SERIAL_SET_BAUD_RATE      Baud Rate: 9600
3       [00000001]  IOCTL_SERIAL_SET_LINE_CONTROL   StopBits: 1, Parity: No, DataBits: 8
4       [00000010]  IRP_MJ_CLOSE                    Port Closed
5       [00000000]  IRP_MJ_CREATE                   Port Opened - vb6.exe
6       [00000000]  IOCTL_SERIAL_SET_BAUD_RATE      Baud Rate: 9600
7       [00000001]  IOCTL_SERIAL_SET_LINE_CONTROL   StopBits: 1, Parity: No, DataBits: 8
8       [00000001]  IOCTL_SERIAL_SET_BAUD_RATE      Baud Rate: 9600
9       [00000002]  IOCTL_SERIAL_SET_LINE_CONTROL   StopBits: 2, Parity: Even, DataBits: 7
10      [00000088]  IRP_MJ_WRITE                    Length: 0017, Data: 40 30 30 52 44 30 30 30 31 30 30 30 31 35 36 2A 0D
11      [00002270]  IRP_MJ_CLOSE                    Port Closed
12      [00000000]  IRP_MJ_CREATE                   Port Opened - AccessPort.exe
13      [00000001]  IOCTL_SERIAL_SET_BAUD_RATE      Baud Rate: 9600
14      [00000001]  IOCTL_SERIAL_SET_LINE_CONTROL   StopBits: 2, Parity: Even, DataBits: 7
15      [00000002]  IOCTL_SERIAL_SET_BAUD_RATE      Baud Rate: 9600
16      [00000003]  IOCTL_SERIAL_SET_LINE_CONTROL   StopBits: 2, Parity: Even, DataBits: 7
17      [00000940]  IRP_MJ_CLOSE                    Port Closed
18      [00000000]  IRP_MJ_CREATE                   Port Opened - vb6.exe
19      [00000000]  IOCTL_SERIAL_SET_BAUD_RATE      Baud Rate: 9600
20      [00000001]  IOCTL_SERIAL_SET_LINE_CONTROL   StopBits: 1, Parity: No, DataBits: 8
21      [00000010]  IRP_MJ_CLOSE                    Port Closed
22      [00000000]  IRP_MJ_CREATE                   Port Opened - vb6.exe
23      [00000001]  IOCTL_SERIAL_SET_BAUD_RATE      Baud Rate: 9600
24      [00000002]  IOCTL_SERIAL_SET_LINE_CONTROL   StopBits: 1, Parity: No, DataBits: 8
25      [00000002]  IOCTL_SERIAL_SET_BAUD_RATE      Baud Rate: 9600
26      [00000003]  IOCTL_SERIAL_SET_LINE_CONTROL   StopBits: 2, Parity: Even, DataBits: 7
27      [00000941]  IRP_MJ_WRITE                    Length: 0017, Data: 40 30 30 52 44 30 30 30 31 30 30 30 31 35 36 2A 0D
28      [00001933]  IRP_MJ_WRITE                    Length: 0017, Data: 40 30 30 57 44 30 30 30 31 30 30 30 32 35 30 2A 0D
29      [00002507]  IRP_MJ_CLOSE                    Port Closed
30      [00000000]  IRP_MJ_CREATE                   Port Opened - AccessPort.exe
31      [00000000]  IOCTL_SERIAL_SET_BAUD_RATE      Baud Rate: 9600
32      [00000001]  IOCTL_SERIAL_SET_LINE_CONTROL   StopBits: 2, Parity: Even, DataBits: 7
33      [00000002]  IOCTL_SERIAL_SET_BAUD_RATE      Baud Rate: 9600
34      [00000003]  IOCTL_SERIAL_SET_LINE_CONTROL   StopBits: 2, Parity: Even, DataBits: 7
35      [00000804]  IRP_MJ_CLOSE                    Port Closed
36      [00000000]  IRP_MJ_CREATE                   Port Opened - vb6.exe
37      [00000001]  IOCTL_SERIAL_SET_BAUD_RATE      Baud Rate: 9600
38      [00000002]  IOCTL_SERIAL_SET_LINE_CONTROL   StopBits: 1, Parity: No, DataBits: 8
39      [00000009]  IRP_MJ_CLOSE                    Port Closed
40      [00000000]  IRP_MJ_CREATE                   Port Opened - vb6.exe
41      [00000001]  IOCTL_SERIAL_SET_BAUD_RATE      Baud Rate: 9600
42      [00000001]  IOCTL_SERIAL_SET_LINE_CONTROL   StopBits: 1, Parity: No, DataBits: 8
43      [00000002]  IOCTL_SERIAL_SET_BAUD_RATE      Baud Rate: 9600
44      [00000002]  IOCTL_SERIAL_SET_LINE_CONTROL   StopBits: 2, Parity: Even, DataBits: 7
45      [00000093]  IRP_MJ_WRITE                    Length: 0017, Data: 40 30 30 52 44 30 30 30 31 30 30 30 31 35 36 2A 0D
46      [00000177]  IRP_MJ_WRITE                    Length: 0017, Data: 40 30 30 52 44 30 30 30 31 30 30 30 31 35 36 2A 0D
47      [00000190]  IRP_MJ_WRITE                    Length: 0017, Data: 40 30 30 52 44 30 30 30 31 30 30 30 31 35 36 2A 0D
48      [00000293]  IRP_MJ_CLOSE                    Port Closed

@00FA00000000001018200000000017C*//d0读
@00FA00000000001018200010000017D*  D1读   @00FA00000000001018200020000017E*  D2读
@00FA00000000001018200020000027D*  D2D3 读
@00FA00000000001018200020000027D*  D2D3 可写

@00FA0000000000101B2000000000106*  H0 读
@00FA0000000000101B2000000000106*  H0 可写
@00FA0000000000101B2000100000107*  H1 读
@00FA0000000000101B2000100000107*  H1 可写
@00FA0000000000101B2000200000104*  H2 读
@00FA0000000000101B2000200000104*  H2 可写
@00FA0000000000101B2000300000105*  H3 读
@00FA0000000000101B2000300000105*  H3 可写
@00FA0000000000101B2000300000206*  H3H4读
@00FA0000000000101B2000300000206*  H3H4可写

@00FA00000000001023100010100010176* 设置W1.1位置
@00FA00000000001023000640000010175* 写100.00
@00FA000000000010130006400000177*  100.00 读
@00FA000000000010130006401000176*  100.01 读
@00FA000000000010130006402000175*  100.02 读
@00FA000000000010130006500000176*  101.00 读
@00FA000000000010130006501000177*  101.01 读
@00FA000000000010130006502000174*  101.02 读


@00FA000000000010130000000000175*  0.00 读
@00FA000000000010130000001000174*  0.01 读
@00FA000000000010130000002000177*  0.02 读
@00FA000000000010130000100000174*  01.00读
@00FA000000000010130000200000177*  02.00读
@00FA000000000010131000000000174*  W0.00 读
@00FA000000000010131000001000175*  W0.01 读
@00FA000000000010131000002000176*  W0.02 读
@00FA000000000010131000002000176*   W0.02 读
@00FA000000000010131000100000175*  W1.00读
@00FA000000000010131000200000176*  W2.00读

@00FA000000000010189000000000177*  T0读
@00FA000000000010189000000000177*  T0读写
@00FA000000000010189000100000176*  T1读
@00FA000000000010189000100000176*  T1读写
@00FA000000000010189000200000175*  T2读
@00FA000000000010189000200000175*  T2读写

@00FA000000000010189000000000177*  C0读
@00FA000000000010189000000000177*  C0读写
@00FA000000000010189000100000176*  C1读
@00FA000000000010189000100000176*  C1读写
@00FA000000000010189000100000176*  C1读写并写了上下限100-10

@00FA000000000010189000200000175*  C2读
@00FA000000000010189000200000175*  C2读写
@00FA00000000001018900FA00000170*  C250读写
@00FA00000000001018909C400000109*  C2500读写
@00FA00000000001018909C40000020A*  C2500 C2501读写
这个人很懒,什么也没有留下!
wyk335858575
级别: *
精华主题: * 篇
发帖数量: * 个
工控威望: * 点
下载积分: * 分
在线时间: (小时)
注册时间: *
最后登录: *
查看wyk335858575的 主题 / 回贴
4楼  发表于: 2011-04-06 16:35
不错,看看先
wyk335858575
级别: *
精华主题: * 篇
发帖数量: * 个
工控威望: * 点
下载积分: * 分
在线时间: (小时)
注册时间: *
最后登录: *
查看wyk335858575的 主题 / 回贴
5楼  发表于: 2011-04-06 16:37
wjun7610
级别: 略有小成
精华主题: 0
发帖数量: 127 个
工控威望: 249 点
下载积分: 708 分
在线时间: 31(小时)
注册时间: 2007-09-16
最后登录: 2024-11-08
查看wjun7610的 主题 / 回贴
6楼  发表于: 2011-05-24 20:29
呵呵,谢谢你的指教,不错Fins协议是欧姆龙新版的协议对于新版的支持更好,而且支持串口、以太网等,特别是他支持CP1H、CP1L、CP1E等新出型号的W区的读写。数据的读取数量也更大,本人正在仿现在的hostlink串口动态库开发相关串口库,以太网的等我购买了欧姆龙以太网硬件测试成功再吧。
我的目的是提高一些工控人员进行开发上位机软件的速度,提供完整的函数接口,比开发人员自行使用协议开发要快速,特别是对于新手来说完善的使用例程更加方便了他们的使用。多语言的支持比目前很多只支持VB或VC的一些网络流行源代码来说适用性更好,无论使用VC、VB、delphi、CB、PB、易语言、Labview等等都可以得到完美的解决方案。不使用其他控件,完全可以制作绿色版上位机软件,至于收费嘛,我用了时间做这个软件自然希望得到认可,愿意不愿意用全凭各位自己,我仅提供一种便捷的方法而已。