Read from PLC
Wrtie to 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();
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;
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 ACydBackSnsr_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) ACydBackSnsr.BackColor = System.Drawing.Color.Green;
if (x01 == 0) ACydBackSnsr.BackColor = System.Drawing.Color.Gray;
if (x02 == 1) ACydForSnsr.BackColor = System.Drawing.Color.Green;
if (x02 == 0) ACydForSnsr.BackColor = System.Drawing.Color.Gray;
}
private void label3_Click(object sender, EventArgs e)
{
}
private void BCydForSnsr_Click(object sender, EventArgs e)
{
}
private void button9_Click(object sender, EventArgs e)
{
}
private void button14_Click(object sender, EventArgs e)
{
if(txtAddressR.Text !="")
{
int Read_Result;
plc.GetDevice(txtAddressR.Text, out Read_Result);
ValueR.Text = Read_Result.ToString();
}
}
private void button15_Click(object sender, EventArgs e)
{
if(txtAddressW.Text !="")
{
plc.SetDevice(txtAddressW.Text, Convert.ToInt16(ValueW.Text));
}
}
}
}
'PLC' 카테고리의 다른 글
[C#]PC로 미쯔비시 PLC 제어하기-실린더제어-MX component (0) | 2022.01.25 |
---|---|
[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 |