wjun7610
級別: 略有小成
|
圖片:
Omron_HostLink.dll V3.2 HostLink通信協(xié)議串口通訊動態(tài)鏈接庫DLL(以下簡稱DLL),是為滿足工業(yè)通信需要, 針對工業(yè)領(lǐng)域要求上位機(jī)對歐姆龍系列PLC通訊實(shí)時(shí)采集與控制的組態(tài)編程而設(shè)計(jì)。 本DLL是采用Delphi語言開發(fā)的標(biāo)準(zhǔn)串口通訊庫,具有以下特點(diǎn): 1)、遵循歐姆龍HostLink通信協(xié)議; 2)、支持多串口并發(fā)操作,支持多線程串口通訊,將串口通訊對主程序的影響降至最低; 3)、實(shí)時(shí)性、可靠性好,通用性強(qiáng); 4)、適用于多PLC(下位機(jī))聯(lián)網(wǎng)和上位機(jī)通信,滿足多方面的需要; 5)、函數(shù)接口功能全,操作簡單,支持歐姆龍PLC的絕大部分地址的讀寫功能函數(shù); 6)、支持USB、PC擴(kuò)展卡等擴(kuò)展串口號; 7)、支持多種操作系統(tǒng)win9x/win2000/winXP(標(biāo)準(zhǔn)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)、擴(kuò)展了函數(shù)功能讀取下位機(jī)中的雙字、單精度浮點(diǎn)等類型數(shù)據(jù),更加符合工業(yè)自動化領(lǐng)域的工控軟件的開發(fā)。 軟件版本更新及相關(guān)說明: Omron_HostLink.dll V3.2 HostLink通信協(xié)議串口通訊鏈接庫,實(shí)現(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ù)的返回按單精度浮點(diǎn)型(2進(jìn)制浮點(diǎn))處理讀取方式。提供擴(kuò)展功能函數(shù),方便用戶實(shí)現(xiàn)混合數(shù)據(jù)讀取。 能夠同時(shí)滿足32個(gè)串口并發(fā)情況下的正常使用。 Omron_HostLink.dll V3.2 分為完美版和單機(jī)版兩個(gè)版本,本DLL于2010年最新規(guī)整優(yōu)化了部分源碼, 通過DLL發(fā)送緩存區(qū)與接收緩存區(qū)數(shù)據(jù)傳遞的功能擴(kuò)展,使多語言環(huán)境的使用更加便利。 全新的串口通信DLL控件,完美的VB、VC、delphi例程及工件手冊是,廣大立志利用各類高級語言進(jìn)行上位機(jī)軟件開發(fā)的首先工具。 淘寶店:http://shop34821629.taobao.com 電 話:13912935690 025-84359545 騰訊QQ:157610979 郵 箱:157610979@QQ.com wjun7610@yahoo.com.cn chinawanglong@163.com |
---|---|
|
wjun7610
級別: 略有小成
|
在VC中使用DLL一般都是采用動態(tài)聲明的方式,函數(shù)說明中給出的是Delphi的函數(shù)原型, 在VC中聲明時(shí)只要注意一下類型的對應(yīng)即可,Delphi中的longint類型對應(yīng)VC中的int類型 Delphi中的Pchar對應(yīng)VC中的char* ,下面給出主要函數(shù)的聲明: 在使用的文件的cpp中聲明一個(gè)句柄: HINSTANCE hinstDLL; 用來標(biāo)識導(dǎo)入的動態(tài)鏈接庫。 1)、按下例說明聲明相關(guān)各個(gè)函數(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)、當(dāng)不再需要使用DLL時(shí)記得關(guān)閉串口及釋放動態(tài)鏈接庫,(在OnDestroy事件中釋放) if(hinstDLL) { int k = mComTrue(mnport); if (k==1) { mClose(mnport); } FreeLibrary(hinstDLL); } |
---|---|
|
wjun7610
級別: 略有小成
|
上面的DLL使用要點(diǎn)也適用于其他各種windows標(biāo)準(zhǔn)DLL的VC調(diào)用。 |
---|---|
|
wjun7610
級別: 略有小成
|
呵呵,謝謝你的指教,不錯(cuò)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)硬件測試成功再吧。 我的目的是提高一些工控人員進(jìn)行開發(fā)上位機(jī)軟件的速度,提供完整的函數(shù)接口,比開發(fā)人員自行使用協(xié)議開發(fā)要快速,特別是對于新手來說完善的使用例程更加方便了他們的使用。多語言的支持比目前很多只支持VB或VC的一些網(wǎng)絡(luò)流行源代碼來說適用性更好,無論使用VC、VB、delphi、CB、PB、易語言、Labview等等都可以得到完美的解決方案。不使用其他控件,完全可以制作綠色版上位機(jī)軟件,至于收費(fèi)嘛,我用了時(shí)間做這個(gè)軟件自然希望得到認(rèn)可,愿意不愿意用全憑各位自己,我僅提供一種便捷的方法而已。 |
---|---|
|