SetDeviec / GetDevice 활용하기
timer를 활용하여 센서의 값을 표시한다.
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();
ActUtlTypeLib.ActUtlType ActUtlType;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
plc.ActLogicalStationNumber = 1;
int nRtn = plc.Open();
if(nRtn == 0)
{
lbConnstatus.Text = "연결성공";
timer1.Interval = 100; // 1000 = 1초
timer1.Enabled = true;
}
else
{
MessageBox.Show("연결 실패");
}
}
private void button2_Click(object sender, EventArgs e)
{
int nRtn = plc.Close();
if (nRtn == 0)
{
lbConnstatus.Text = "연결종료";
timer1.Enabled = false;
}
}
private void button3_Click(object sender, EventArgs e) // 실린더 후진
{
plc.SetDevice("y21", 0);
plc.SetDevice("y22", 1);
}
private void button4_Click(object sender, EventArgs e) // 실린더 전진
{
plc.SetDevice("y21", 1);
plc.SetDevice("y22", 2);
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void label2_Click(object sender, EventArgs e)
{
}
private void CydBackSnsr_Click(object sender, EventArgs e)
{
}
private void timer1_Tick(object sender, EventArgs e)
{
plc.GetDevice("x1", out int x01);
plc.GetDevice("x2", out int x02);
if (x01 == 1) CydBackSnsr.BackColor = System.Drawing.Color.Green;
if (x01 == 0) CydBackSnsr.BackColor = System.Drawing.Color.Gray;
if (x02 == 1) CydForSnsr.BackColor = System.Drawing.Color.Green;
if (x02 == 0) CydForSnsr.BackColor = System.Drawing.Color.Gray;
}
}
}
'PLC' 카테고리의 다른 글
[C#]PC로 미쯔비시 PLC 제어하기-디바이스값 읽기/쓰기-MX component (0) | 2022.01.26 |
---|---|
[C#]PC로 미쯔비시 PLC 제어하기-연결상태 문구표시하기-MX component (0) | 2022.01.11 |
C# Visual Studio를 활용하여 PLC 접점 ON/OFF하기 (0) | 2022.01.11 |
MX Component를 활용하여 PC와 PLC 통신하기 - CPU와 EthetNet 통신 (0) | 2022.01.10 |
MX Component를 활용하여 PC와 PLC 통신하기 - GX-Simulator2 (0) | 2021.08.13 |