PLC

[C#]PC로 미쯔비시 PLC 제어하기-연결상태 문구표시하기-MX component

슝슝쑝쑝 2022. 1. 11. 14:31

 

C#으로 MX component를 활용한 PLC 제어하기 

 

연결상태를 문구로 표시하기

 

 

 

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 WindowsFormsApp3
{
    public partial class Form1 : Form
    {
        public ActUtlType plc = new ActUtlType();
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            plc.ActLogicalStationNumber = 1;
            int nRtn = plc.Open();
            if(nRtn == 0)
            {
                lbConnstatus.Text = "연결성공";
            }
            else 
            {
                MessageBox.Show("연결 실패");
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
         
            int nRtn = plc.Close();
            if (nRtn == 0)
            {
                lbConnstatus.Text = "연결종료";
            }
        
        }

        private void button3_Click(object sender, EventArgs e)
        {
            plc.SetDevice("M0", 1);
        }

        private void button4_Click(object sender, EventArgs e)
        {
            plc.SetDevice("M0", 0);

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}

 

WindowsFormsApp3.zip
0.05MB