close

事前準備:

  • 安裝 GX Work2 (Ver 1.521T)
  • 安裝 MX Component (Ver 4.17T)
  • 安裝 GX Configurator-DP (Ver 7.13P)
  • PLC(Q03UDVCPU) + 電源模組(Q61P) + Profibus Master通訊模組(QJ71PB92V)
  • 量測主機(Marposs P7ME) + 測頭
  • Profibus 通訊線
  • USB (A-Type 轉 mini)
  • 網路線(RJ45)


 

開啟GX Work2

 

新增專案

 

將PLC 與 PC 用USB線連接起來,安裝驅動程式

 

建立連線

 

到專案頁,PLC參數上,雙擊滑鼠左鍵

設定IP, (為了PC 與 PLC透過網路連線用)

 

將參數寫入到PLC,寫入完成須斷電重開,該IP才會生效

 

本機PC 須設定成相同網域,至控制台

網路和共用中心

變更介面卡設定

區域連線的內容

IPV4

設定IP

 

MX Component 設定

開啟Communication Setup Utility,

 

到這邊為止都是在建立PC 與 PLC的通訊,目標是透過MX Component的函式庫連線。

我上面舉例的是用Ethernet,也可以用USB

建立站號後,可以用PLC Monitor Utility 的程式測試,這也是MX Component的軟體

 

C#部分

在工具箱中,選擇項目

 

補充一點 請將專案設定成 Framework4.5(含) 之後的版本,否則執行的時候會出現錯誤訊息,

不接受事後改回Framework4.5之後的版本,所以請勿降版,否則會很難處理。

元件砍掉重拉也無效。

 

將元件拉到畫面

設定站號

 

程式碼:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int ret=axActUtlType1.Open();
            if(ret == 0)
            {
                timer1.Enabled = true;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            axActUtlType1.Close();
            timer1.Enabled = false;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            short[] buf = new short[1];
            int ret = axActUtlType1.ReadDeviceBlock2("D4000", 1, out buf[0]);
            if (ret == 0)
            {
                label1.Text = buf[0].ToString();
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            short data = Int16.Parse(textBox1.Text); 
            axActUtlType1.WriteDeviceBlock2("D4000", 1, ref data);
        }

    }
}
 

 

接下來是Profibus的部份

新增智能模組

 

參數(Parameter)上,雙擊滑鼠左鍵

新增量測設備的GSD檔

 

拖曳量測設備到Profubus Network,建立主從關係

設定Profibus從站的站號:1

依照Marposs P7ME手冊,拉取設備Profibus的I/O Mapping的資料格式,

這邊需要盡可能的一樣,否則只是Byte數對,還是會通不起來,會診斷出:

The I/O byte size parameter received from the master dose not match that of the slave。

 

輸出設定映像檔

將智能模組的設定寫入PLC

arrow
arrow
    文章標籤
    PLC Profibus C# Marposs
    全站熱搜

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