Fanuc Focas1/2 in BCB

Update : 2018.07.21

1.開新專案

 

2.拉元件

 

3.設定屬性

 

4.Fwlib32.lib複製到專案的資料夾中

 

5.Fwlib32.lib加入專案中

如果編譯沒意外的話應該會發生錯誤。

這個時後就要用coff2omf.exe了,程式就在BCB的安裝路徑Bin當中。

先將它複製到程式路徑中

cmd底下使用

還好成功了,不然就要用其他辦法了。

然後我們把舊的移掉。

新的加進來

6.編譯/執行

成功了,可以安心的打程式了。

 

7.將標頭檔放到程式路徑下

我是用0i系列的控制器,因此我就從0i的資料夾複製過來。

 

8.開始打程式吧

函式介紹:

連線(使用光纖),甚麼都不用設定,直接連線。

FWLIBAPI short WINAPI cnc_allclibhndl(unsigned short *FlibHndl);

連線(使用網路線),輸入IP與Port。

FWLIBAPI short WINAPI cnc_allclibhndl3(const char *ipaddr, unsigned short port, long timeout, unsigned short *FlibHndl);

連線成功時,會回傳EW_OK。

 

 

====Unit1.cpp====

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"

TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
    short ret;
    //Ethernet
    if(RadioButton1->Checked) ret=cnc_allclibhndl3(Edit1->Text.c_str(), (WORD)StrToInt(Edit2->Text), 1, &FFlibHndl);
    //HSSB
    else ret=cnc_allclibhndl(&FFlibHndl);

    if(ret==EW_OK) ShowMessage("Connect OK");
    else ShowMessage("Connect Fail.");

}
//---------------------------------------------------------------------------

 

====Unit1.h====

//---------------------------------------------------------------------------

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include "Fwlib32.h"
//---------------------------------------------------------------------------

class TForm1 : public TForm
{
__published:    
// IDE-managed Components
    TLabel *Label1;
    TLabel *Label2;
    TEdit *Edit1;
    TEdit *Edit2;
    TButton *Button1;
    TGroupBox *GroupBox1;
    TRadioButton *RadioButton1;
    TRadioButton *RadioButton2;
    void __fastcall Button1Click(TObject *Sender);
private:    
// User declarations
    WORD FFlibHndl;

public:        // User declarations
    __fastcall TForm1(TComponent* Owner);

};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif

 

到我的 GitHub 下載範例

 

 

文章標籤
全站熱搜
創作者介紹
創作者 史克威爾凱特 的頭像
史克威爾凱特

史克威爾凱特的部落格

史克威爾凱特 發表在 痞客邦 留言(1) 人氣(700)