恭喜,你发布的帖子
发布于 2020-07-10 11:17:59
3楼
先Ping PLC的IP地址!
先定义全局对象,再创建对象!
Plc plc;
private void btnTest_Click(object sender, EventArgs e)
{
plc = new Plc (CpuType.S71200, txtIP.Text, 0, 1);
if (plc.Open() == ErrorCode.NoError)
{
MessageBox.Show("Connect Sucessfully!", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Information);
plc.Close();
timer1.Enabled = true;
}
else
MessageBox.Show("Cannot connect to PLC!", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
private void timer1_Tick(object sender, EventArgs e)
{
if (plc.Open() == ErrorCode.NoError)
{
dataNhan = plc.ReadBytes(DataType.Input, 0, 0, 1);
if (dataNhan[0].SelectBit(0) == true)
Lamp.BackColor = Color.Green;
else
Lamp.BackColor = Color.Gray;
plc.Close();
}
else
MessageBox.Show("Cannot connect to PLC!", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
请填写推广理由:
分享
只看
楼主