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

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

可以適用于常用的各種開發(fā)環(huán)境如:Vb6、Vb.net、Delphi、C#、VC++、powerbuilder、易語言、labviEW等進行上位機軟件開發(fā)。

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

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

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

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

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

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

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

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

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

9)、采用數(shù)組指針調(diào)用數(shù)據(jù)發(fā)生與接收,初學者快速入門;對于不方便使用指針的開發(fā)環(huán)境可采用DLL緩沖區(qū)傳遞;

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

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

軟件版本及相關說明:

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

wangjun于2013年在原有Omron_HostLink.dll V3.2版基礎上基于Finsi協(xié)議重寫通訊底層協(xié)議結(jié)構(gòu)。

對于16位整數(shù)和32位整數(shù)讀取寫入均按有符號整數(shù)處理,小數(shù)的返回按單精度浮點型(2進制浮點)

處理讀取方式。提供擴展功能函數(shù),方便用戶實現(xiàn)混合數(shù)據(jù)讀取。能夠同時滿足32個串口并發(fā)

情況下的正常使用。

Omron_Fins.dll V1.0 分為完美版和單機版兩個版本。

注意:實例在使用時不能超出試用版的地址限制,否則無法正確通訊。


龍帥工作室為您提供專業(yè)串口通訊控件,也可為您訂制

專用通訊協(xié)議串口控件。目前龍帥系列串口通訊協(xié)議

控件包括modbus_rtu、modbus_tcp、三菱FX PLC編程口、

歐姆龍HostLink、西門子PPI等多個系列產(chǎn)品。

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

電 話:13912935690

騰訊QQ:157610979

阿里旺旺: wj_longshuai

郵 箱:[url=mailto:157610979@QQ.com]157610979@QQ.com[/url] ;   [url=mailto:chinawanglong@163.com]chinawanglong@163.com[/url]
[ 此帖被wjun7610在2016-11-24 14:06重新編輯 ]
附件: 歐姆龍fins協(xié)議動態(tài)庫.rar (1353 K) 下載次數(shù):659
網(wǎng)站提示: 請不要用迅雷下載附件,容易出錯
wjun7610
級別: 略有小成
精華主題: 0
發(fā)帖數(shù)量: 127 個
工控威望: 249 點
下載積分: 708 分
在線時間: 31(小時)
注冊時間: 2007-09-16
最后登錄: 2024-10-02
查看wjun7610的 主題 / 回貼
1樓  發(fā)表于: 2013-06-22 19:52
DLL串口操作函數(shù)包括:

  1)、finsComOpen打開串口;

     finsCvComOpen打開串口; //CV模式通訊串口打開

  2)、finsComClose關閉串口;
      
  3)、finsSetDelay串口通訊延時設定;
                    
  4)、finsComTrue判斷串口是否打開成功;
            
  5)、finsComWork判斷串口是否正在工作中;

Fins協(xié)議基本功能函數(shù)包括:

  1)、finsPlcRs  讀取PLC運行狀態(tài);

  2)、finsPlcWs 更改PLC運行狀態(tài);  

  3)、finsBitForced  PLC位元件強制;

  4)、finsCancelAllF 取消全部PLC強制;

  5)、finsReadBit 讀PLC位元件值;

  6)、finsReadInt 讀PLC字元件值;

  7)、finsWriteBit 寫PLC位元件值;  

  8)、finsWriteInt 寫PLC字元件值;

Fins協(xié)議擴展功能函數(shù)包括:

  1)、finsSet PLC的位元件置位;

  2)、finsReSet PLC的位元件復位;  

  3)、finsReadDInt 讀PLC的雙字整數(shù)值;

  4)、finsReadFloat 讀PLC的浮點數(shù)據(jù)值;

  5)、finsWriteDInt 寫PLC的雙字整數(shù)值;

  6)、finsWriteFloat 寫PLC的浮點數(shù)據(jù)值;

Fins協(xié)議DLL緩沖區(qū)傳遞功能函數(shù)包括

  1)、finsClearBuf  清除復位DLL緩存區(qū);

  2)、finsReadBitBuf 讀PLC的位元件值  

  3)、finsReadIntBuf 讀PLC的字元件值;

  4)、finsReadDIntBuf 讀PLC雙字整數(shù)值;

  5)、finsIntDllBufRead 讀DLL整數(shù)緩存區(qū)值;

  6)、finsReadFloatBuf 讀PLC浮點數(shù)據(jù)值;  

  7)、finsFloatDllBufRead 讀DLL浮點緩存區(qū)值;

  8)、finsWriteIntDllBuf  寫DLL整數(shù)緩存區(qū)值;

  9)、finsBitBufWrite  寫PLC的位元件值;

  10)、finsIntBufWrite 寫PLC的字元件值;  

  11)、finsDIntBufWrite 寫PLC雙字整數(shù)值;

  12)、finsWriteFloatDllBuf 寫DLL浮點緩存區(qū)值;  

  13)、finsFloatBufWrite 寫PLC浮點數(shù)據(jù)值;
當需要進行16位整數(shù)、32位整數(shù)、32位浮點數(shù)值進行混合讀寫時,所需拓展函數(shù)包括:

  1)、DecBitBin  字整數(shù)的位抽取;

  2)、Int32ToInt_16h  雙字到字轉(zhuǎn)換高位字;  

  3)、Int32ToInt_16l  雙字到字轉(zhuǎn)換低位字;

  4)、Int16ToInt32  字到雙字的轉(zhuǎn)換;

  5)、Float32ToInt_16h 浮點到字轉(zhuǎn)換高位字;

  6)、Float32ToInt_16l 浮點到字轉(zhuǎn)換低位字;

  7)、Int16ToFloat32  字到浮點的轉(zhuǎn)換;

  8)、Int16Unsign   16位有符號整數(shù)轉(zhuǎn)無符號整數(shù)  
wjun7610
級別: 略有小成
精華主題: 0
發(fā)帖數(shù)量: 127 個
工控威望: 249 點
下載積分: 708 分
在線時間: 31(小時)
注冊時間: 2007-09-16
最后登錄: 2024-10-02
查看wjun7610的 主題 / 回貼
2樓  發(fā)表于: 2013-06-22 19:52
在VC中使用DLL一般都是采用動態(tài)聲明的方式,函數(shù)說明中給出的是Delphi的函數(shù)原型,

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

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

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

HINSTANCE hinstDLL;

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

1)、按下例說明聲明相關各個函數(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 value);
typedef int (_stdcall *pComTrue)(int nport);
typedef int (_stdcall *pComWork)(int nport);

typedef int (_stdcall *pRs)(int nport, int node);
typedef int (_stdcall *pWs)(int nport, int node, int State);
typedef int (_stdcall *pBitForced)(int nport, int node, int address, int Bit, int value, char* Area);
typedef int (_stdcall *pCancelAllF)(int nport, int node);
typedef int (_stdcall *pReadBit)(int nport, int node, int address, int Bit, int Count, char* Area, int* RxdBuffer);
typedef int (_stdcall *pReadInt)(int nport, int node, int address, int Count, char* Area, int* RxdBuffer);
typedef int (_stdcall *pWriteBit)(int nport, int node, int address, int Bit, int Count, char* Area, int* TxdBuffer);
typedef int (_stdcall *pWriteInt)(int nport, int node, int address, int Count, char* Area, int* TxdBuffer);

typedef int (_stdcall *pSet)(int nport, int node, int address, int Bit, char* Area);
typedef int (_stdcall *pReSet)(int nport, int node, int address, int Bit, char* Area);
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);
typedef int (_stdcall *pInt16Unsign)(int value);

2)、建立動態(tài)鏈接庫的新函數(shù)名:(在cpp文件的頭處聲明)

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

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)、導入動態(tài)鏈接庫,如例所示:(在cpp文件的OnInitDialog過程建立):

hinstDLL = LoadLibrary("Omron_fins.dll");

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

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

   if (hinstDLL)
   {
      mOpen = (pOpen)GetProcAddress (hinstDLL,"finsComOpen");
      //mOpen = (pOpen)GetProcAddress (hinstDLL,"finsCvComOpen");  CV模式plc使用這個打開串口
      mClose = (pClose)GetProcAddress (hinstDLL,"finsComClose");
      mSetDelay = (pSetDelay)GetProcAddress (hinstDLL,"finsSetDelay");
      mComTrue = (pComTrue)GetProcAddress (hinstDLL,"finsComTrue");
      mComWork = (pComWork)GetProcAddress (hinstDLL,"finsComWork");
    
      mRs = (pRs)GetProcAddress (hinstDLL,"finsPlcRs");
      mWs = (pWs)GetProcAddress (hinstDLL,"finsPlcWs");
      mBitForced = (pBitForced)GetProcAddress (hinstDLL,"finsBitForced");
      mCancelAllF = (pCancelAllF)GetProcAddress (hinstDLL,"finsCancelAllF");
      mReadBit = (pReadBit)GetProcAddress (hinstDLL,"finsReadBit");
      mReadInt = (pReadInt)GetProcAddress (hinstDLL,"finsReadInt");
      mWriteBit = (pWriteBit)GetProcAddress (hinstDLL,"finsWriteBit");
      mWriteInt = (pWriteInt)GetProcAddress (hinstDLL,"finsWriteInt");

      mSet = (pSet)GetProcAddress (hinstDLL,"finsSet");
      mReSet = (pReSet)GetProcAddress (hinstDLL,"finsReSet");
      mReadDInt = (pReadDInt)GetProcAddress (hinstDLL,"finsReadDInt");
      mReadFloat = (pReadFloat)GetProcAddress (hinstDLL,"finsReadFloat");
      mWriteDInt = (pWriteDInt)GetProcAddress (hinstDLL,"finsWriteDInt");
      mWriteFloat = (pWriteFloat)GetProcAddress (hinstDLL,"finsWriteFloat");


     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("Omron_fins.dll已成功載入!");
  }
  else
{
    AfxMessageBox("沒找到Omron_fins.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時記得關閉串口及釋放動態(tài)鏈接庫,(在OnDestroy事件中釋放)

if(hinstDLL)
{
   int k = mComTrue(mnport);
   if (k==1)
   {
      mClose(mnport);
   }    
   FreeLibrary(hinstDLL);
}