wjun7610
級別: 略有小成
精華主題: 0
發(fā)帖數(shù)量: 127 個
工控威望: 249 點
下載積分: 708 分
在線時間: 31(小時)
注冊時間: 2007-09-16
最后登錄: 2024-10-02
查看wjun7610的 主題 / 回貼
樓主  發(fā)表于: 2011-04-05 15:29
圖片:
Omron_HostLink.dll V3.2 HostLink通信協(xié)議串口通訊動態(tài)鏈接庫DLL(以下簡稱DLL),是為滿足工業(yè)通信需要,

針對工業(yè)領(lǐng)域要求上位機對歐姆龍系列PLC通訊實時采集與控制的組態(tài)編程而設(shè)計。

本DLL是采用Delphi語言開發(fā)的標準串口通訊庫,具有以下特點:

1)、遵循歐姆龍HostLink通信協(xié)議;

2)、支持多串口并發(fā)操作,支持多線程串口通訊,將串口通訊對主程序的影響降至最低;

3)、實時性、可靠性好,通用性強;

4)、適用于多PLC(下位機)聯(lián)網(wǎng)和上位機通信,滿足多方面的需要;

5)、函數(shù)接口功能全,操作簡單,支持歐姆龍PLC的絕大部分地址的讀寫功能函數(shù);

6)、支持USB、PC擴展卡等擴展串口號;

7)、支持多種操作系統(tǒng)win9x/win2000/winXP(標準Win32 DLL);

8)、易于快速開發(fā)(VC等非RAD開發(fā)環(huán)境的開發(fā));

9)、更新原有函數(shù)調(diào)用方式采用數(shù)組調(diào)用數(shù)據(jù)發(fā)生與接收,初學(xué)者快速入門;

10)、可在多種編程環(huán)境下使用,例如VB、VC、Delphi、PB、Labview、易語言等開發(fā)環(huán)境;

11)、擴展了函數(shù)功能讀取下位機中的雙字、單精度浮點等類型數(shù)據(jù),更加符合工業(yè)自動化領(lǐng)域的工控軟件的開發(fā)。

軟件版本更新及相關(guān)說明:

Omron_HostLink.dll V3.2 HostLink通信協(xié)議串口通訊鏈接庫,實現(xiàn)了對歐姆 龍全系列PLC的HostLink協(xié)議的支持,

(刪減了一些特權(quán)指令)wangjun于2010年在原有omron.dll V2.0版基礎(chǔ)上的更新版,重寫了函數(shù)結(jié)構(gòu),采用數(shù)據(jù)接收

和發(fā)送緩沖區(qū)(數(shù)組)方式傳遞,讀出和寫入單元數(shù)據(jù)使用更方便。對于16位整數(shù)和32位整數(shù)讀取寫入均按有符號整數(shù)

處理,小數(shù)的返回按單精度浮點型(2進制浮點)處理讀取方式。提供擴展功能函數(shù),方便用戶實現(xiàn)混合數(shù)據(jù)讀取。

能夠同時滿足32個串口并發(fā)情況下的正常使用。

Omron_HostLink.dll V3.2 分為完美版和單機版兩個版本,本DLL于2010年最新規(guī)整優(yōu)化了部分源碼,

通過DLL發(fā)送緩存區(qū)與接收緩存區(qū)數(shù)據(jù)傳遞的功能擴展,使多語言環(huán)境的使用更加便利。

全新的串口通信DLL控件,完美的VB、VC、delphi例程及工件手冊是,廣大立志利用各類高級語言進行上位機軟件開發(fā)的首先工具。

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

電 話:13912935690 025-84359545

騰訊QQ:157610979

郵 箱:157610979@QQ.com

wjun7610@yahoo.com.cn

chinawanglong@163.com
wjun7610
級別: 略有小成
精華主題: 0
發(fā)帖數(shù)量: 127 個
工控威望: 249 點
下載積分: 708 分
在線時間: 31(小時)
注冊時間: 2007-09-16
最后登錄: 2024-10-02
查看wjun7610的 主題 / 回貼
1樓  發(fā)表于: 2011-04-05 15:32
在VC中使用DLL一般都是采用動態(tài)聲明的方式,函數(shù)說明中給出的是Delphi的函數(shù)原型,

在VC中聲明時只要注意一下類型的對應(yīng)即可,Delphi中的longint類型對應(yīng)VC中的int類型

Delphi中的Pchar對應(yīng)VC中的char* ,下面給出主要函數(shù)的聲明:

在使用的文件的cpp中聲明一個句柄:

HINSTANCE hinstDLL;

用來標識導(dǎo)入的動態(tài)鏈接庫。

1)、按下例說明聲明相關(guān)各個函數(shù):(在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)、建立動態(tài)鏈接庫的新函數(shù)名:(在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)、導(dǎo)入動態(tài)鏈接庫,如例所示:(在cpp文件的OnInitDialog過程建立):

hinstDLL = LoadLibrary("Omron_HostLink.dll");

4)、判斷dll文件是否存在并聲明并建立動態(tài)鏈接庫中的函數(shù)與新函數(shù)名的對應(yīng)關(guān)系,

如下:(在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);
}

注:雙引號中為動態(tài)鏈接庫中的原有函數(shù)名。


函數(shù)中用到了char*型參數(shù),這里介紹下char*與Cstring的相互轉(zhuǎn)換的函數(shù):

(1)char*->CString

char* sz;
CString str;
str.Format("%s",sz); //可以用此函數(shù)將讀取的值轉(zhuǎn)成字符串

(2) CString -> char*

CString str;
char* sz = str.GetBuffer(0);//可將字符串轉(zhuǎn)成char*給函數(shù)賦值


5)、當不再需要使用DLL時記得關(guān)閉串口及釋放動態(tài)鏈接庫,(在OnDestroy事件中釋放)

if(hinstDLL)
{
int k = mComTrue(mnport);
if (k==1)
{
mClose(mnport);
}
FreeLibrary(hinstDLL);
}
wjun7610
級別: 略有小成
精華主題: 0
發(fā)帖數(shù)量: 127 個
工控威望: 249 點
下載積分: 708 分
在線時間: 31(小時)
注冊時間: 2007-09-16
最后登錄: 2024-10-02
查看wjun7610的 主題 / 回貼
2樓  發(fā)表于: 2011-04-05 15:35
上面的DLL使用要點也適用于其他各種windows標準DLL的VC調(diào)用。
yamqq
雅馬哈,愛普生,電裝機器人。
級別: 網(wǎng)絡(luò)英雄

精華主題: 0
發(fā)帖數(shù)量: 1717 個
工控威望: 5539 點
下載積分: 24588 分
在線時間: 299(小時)
注冊時間: 2008-05-05
最后登錄: 2024-08-25
查看yamqq的 主題 / 回貼
3樓  發(fā)表于: 2011-04-06 16:31
樓主,你out了,現(xiàn)在是基于fins的了!本來想把源碼貼出來,想想還是不要斷了你的財路,只把通訊協(xié)議貼一些出來吧
SUDT ACCESSPORT LOG FILE - Monitor mode

監(jiān)控: COM8
創(chuàng)建時間: 2011-03-19, 14:35:30
計算機名: J2
系統(tǒng)版本: 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* 設(shè)置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
級別: *
精華主題: * 篇
發(fā)帖數(shù)量: * 個
工控威望: * 點
下載積分: * 分
在線時間: (小時)
注冊時間: *
最后登錄: *
查看wyk335858575的 主題 / 回貼
4樓  發(fā)表于: 2011-04-06 16:35
不錯,看看先
wyk335858575
級別: *
精華主題: * 篇
發(fā)帖數(shù)量: * 個
工控威望: * 點
下載積分: * 分
在線時間: (小時)
注冊時間: *
最后登錄: *
查看wyk335858575的 主題 / 回貼
5樓  發(fā)表于: 2011-04-06 16:37
wjun7610
級別: 略有小成
精華主題: 0
發(fā)帖數(shù)量: 127 個
工控威望: 249 點
下載積分: 708 分
在線時間: 31(小時)
注冊時間: 2007-09-16
最后登錄: 2024-10-02
查看wjun7610的 主題 / 回貼
6樓  發(fā)表于: 2011-05-24 20:29
呵呵,謝謝你的指教,不錯Fins協(xié)議是歐姆龍新版的協(xié)議對于新版的支持更好,而且支持串口、以太網(wǎng)等,特別是他支持CP1H、CP1L、CP1E等新出型號的W區(qū)的讀寫。數(shù)據(jù)的讀取數(shù)量也更大,本人正在仿現(xiàn)在的hostlink串口動態(tài)庫開發(fā)相關(guān)串口庫,以太網(wǎng)的等我購買了歐姆龍以太網(wǎng)硬件測試成功再吧。
我的目的是提高一些工控人員進行開發(fā)上位機軟件的速度,提供完整的函數(shù)接口,比開發(fā)人員自行使用協(xié)議開發(fā)要快速,特別是對于新手來說完善的使用例程更加方便了他們的使用。多語言的支持比目前很多只支持VB或VC的一些網(wǎng)絡(luò)流行源代碼來說適用性更好,無論使用VC、VB、delphi、CB、PB、易語言、Labview等等都可以得到完美的解決方案。不使用其他控件,完全可以制作綠色版上位機軟件,至于收費嘛,我用了時間做這個軟件自然希望得到認可,愿意不愿意用全憑各位自己,我僅提供一種便捷的方法而已。