2017年12月22日 星期五

Connect Mitsubishi Q series PLC with Ethernet by using C#

PLC setting

1. Open GX work 2 to set the protocol type and port of PLC.
2. Write the setting to PLC

PC setting

1.Open VS IDE
2.Select C#
3.refer Socket library
using System.Net.Sockets;
4.there are two types of protocol of PLC, TCP and UDP. Here we introduce both

5. TCP connection

5.1 Create TCP object
Socket mysocket = new Socket(SocketType.Stream, ProtocolType.Tcp);

5.2 Create IP object
byte[] address = { 192, 168, 3, 39 }
IPAddress addr = new IPAddress(address);

5.3 Connect to PLC
the first parameter is IPAddress object, the rear one is port number of PLC, it can be set in GX work2.
mysocket.Connect(addr, 1001);

5.4 Checking
create a bool object to check the connection is successful or not.
bool result = mysocket.Connected;

6. UDP connection

6.1 Create UDP object
Socket mysocket = new Socket(SocketType.Dgram, ProtocolType.Udp);

6.2 Create IP object
See section 5.2

6.3 Connect to PLC
the first parameter is IPAddress object, the rear one is port number of PLC, it can be set in GX work2.
mysocket.Connect(addr, 1025);

6.4 Checking
create a bool object to check the connection is successful or not.
bool result = mysocket.Connected;



沒有留言:

張貼留言

同軸度 Coaxiality

同軸度和同心度是兩個非常容易搞混的幾何公差. 同軸度的符號如下: 跟正位度的符號是一樣的! 有這種設定,主要是它的定義和正位度的使用方法很像,反而跟同心度沒這麼相似. 首先來個範例: 由於這個不是繪圖軟體做的,只是示意用,不合工程圖規範的部分還請包涵. 這個是...