본문 바로가기

PLC

C# Visual Studio를 활용하여 PLC 접점 ON/OFF하기

 

 

Visual Studio를 실행하여 아래와 같이 실행창을 구성한다.

 

 

사용한 도구상자

Button

Label

GroupBox

 

 

실행창에서 M0 On/Off 버튼을 눌렀을 때 PLC의 M0가 On/Off 되는 것을 볼 수 있다.

 

 

 

 

솔루션 탐색기 - 참조추가

MITSUBISHI ActUtlType Controls Ver1.0

안뜨면 MX component 최신버전으로 다시 설치.

 

 

프로그램

노란색 음영 : 추가작성한 부분

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;

using ActUtlTypeLib;

namespace WindowsFormsApp2

{

public partial class Form1 : Form

{

public ActUtlType plc = new ActUtlType(); // PLC 개체 생성

public Form1()

{

InitializeComponent();

}

private void plc_conn_bt_Click(object sender, EventArgs e)

{

plc.ActLogicalStationNumber = 1; // 통신국번

plc.Open(); // 통신포트 오픈

}

private void plc_disconn_bt_Click(object sender, EventArgs e)

{

plc.Close(); // 통신포트 클로즈

}

private void m0_on_bt_Click(object sender, EventArgs e)

{

plc.SetDevice("M0", 1);

}

private void m0_off_bt_Click(object sender, EventArgs e)

{

plc.SetDevice("M0", 0);

}

}

}

 

WindowsFormsApp2 (1).zip
0.04MB