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;
namespace VM_Pro._4_Edit {
public partial class IO_UserControl : UserControl {
string[] devices = new string[3] { "焊接机器人", "理线机器人", "基恩士PLC" };
public IO_UserControl() {
InitializeComponent();
}
private void button焊头升降气缸_Click(object sender, EventArgs e) {
if (PLCComm.FindPLCByName("焊接机器人").ReadShort("555") == 0) {
if (PLCComm.FindPLCByName("焊接机器人").ReadShort("516") == 1) {
button焊头升降气缸.BackColor = Color.FromArgb(4, 120, 238);
PLCComm.FindPLCByName("焊接机器人").WriteInt("516", 0.ToString());
FuncLib.ShowMsg(string.Format(" [ {0} ] 发送指令: [ {1} ]", "焊接机器人", 0));
}
else {
button焊头升降气缸.BackColor = Color.Green;
PLCComm.FindPLCByName("焊接机器人").WriteInt("516", 1.ToString());
FuncLib.ShowMsg(string.Format(" [ {0} ] 发送指令: [ {1} ]", "焊接机器人", 1));
}
}
}
private void button顶针气缸_Click(object sender, EventArgs e) {
if (PLCComm.FindPLCByName("焊接机器人").ReadShort("555") == 0) {
if (PLCComm.FindPLCByName("焊接机器人").ReadShort("516") == 2) {
button顶针气缸.BackColor = Color.FromArgb(4, 120, 238);
PLCComm.FindPLCByName("焊接机器人").WriteInt("516", 0.ToString());
FuncLib.ShowMsg(string.Format(" [ {0} ] 发送指令: [ {1} ]", "焊接机器人", 0));
}
else {
button顶针气缸.BackColor = Color.Green;
PLCComm.FindPLCByName("焊接机器人").WriteInt("516", 2.ToString());
FuncLib.ShowMsg(string.Format(" [ {0} ] 发送指令: [ {1} ]", "焊接机器人", 2));
}
}
}
private void button焊咀吹气_Click(object sender, EventArgs e) {
if (PLCComm.FindPLCByName("焊接机器人").ReadShort("555") == 0) {
if (PLCComm.FindPLCByName("焊接机器人").ReadShort("516") == 4) {
button焊咀吹气.BackColor = Color.FromArgb(4, 120, 238);
PLCComm.FindPLCByName("焊接机器人").WriteInt("516", 0.ToString());
FuncLib.ShowMsg(string.Format(" [ {0} ] 发送指令: [ {1} ]", "焊接机器人", 0));
}
else {
button焊咀吹气.BackColor = Color.Green;
PLCComm.FindPLCByName("焊接机器人").WriteInt("516", 4.ToString());
FuncLib.ShowMsg(string.Format(" [ {0} ] 发送指令: [ {1} ]", "焊接机器人", 4));
}
}
}
private void button送丝信号_Click(object sender, EventArgs e) {
if (PLCComm.FindPLCByName("焊接机器人").ReadShort("555") == 0) {
if (PLCComm.FindPLCByName("焊接机器人").ReadShort("516") == 8) {
button送丝信号.BackColor = Color.FromArgb(4, 120, 238);
PLCComm.FindPLCByName("焊接机器人").WriteInt("516", 0.ToString());
FuncLib.ShowMsg(string.Format(" [ {0} ] 发送指令: [ {1} ]", "焊接机器人", 0));
}
else {
button送丝信号.BackColor = Color.Green;
PLCComm.FindPLCByName("焊接机器人").WriteInt("516", 8.ToString());
FuncLib.ShowMsg(string.Format(" [ {0} ] 发送指令: [ {1} ]", "焊接机器人", 8));
}
}
}
private void button送丝方向_Click(object sender, EventArgs e) {
if (PLCComm.FindPLCByName("焊接机器人").ReadShort("555") == 0) {
if (PLCComm.FindPLCByName("焊接机器人").ReadShort("516") == 16) {
button送丝方向.BackColor = Color.FromArgb(4, 120, 238);
PLCComm.FindPLCByName("焊接机器人").WriteInt("516", 0.ToString());
FuncLib.ShowMsg(string.Format(" [ {0} ] 发送指令: [ {1} ]", "焊接机器人", 0));
}
else {
button送丝方向.BackColor = Color.Green;
PLCComm.FindPLCByName("焊接机器人").WriteInt("516", 16.ToString());
FuncLib.ShowMsg(string.Format(" [ {0} ] 发送指令: [ {1} ]", "焊接机器人", 16));
}
}
}
private void button光源_Click(object sender, EventArgs e) {
if (PLCComm.FindPLCByName("焊接机器人").ReadShort("555") == 0) {
if (PLCComm.FindPLCByName("焊接机器人").ReadShort("516") == 32) {
button光源.BackColor = Color.FromArgb(4, 120, 238);
PLCComm.FindPLCByName("焊接机器人").WriteInt("516", 0.ToString());
FuncLib.ShowMsg(string.Format(" [ {0} ] 发送指令: [ {1} ]", "焊接机器人", 0));
}
else {
button光源.BackColor = Color.Green;
PLCComm.FindPLCByName("焊接机器人").WriteInt("516", 32.ToString());
FuncLib.ShowMsg(string.Format(" [ {0} ] 发送指令: [ {1} ]", "焊接机器人", 32));
}
}
}
private void button理线横移气缸_Click(object sender, EventArgs e) {
if (PLCComm.FindPLCByName("理线机器人").ReadShort("555") == 0) {
if (PLCComm.FindPLCByName("理线机器人").ReadShort("516") == 1) {
button理线横移气缸.BackColor = Color.FromArgb(4, 120, 238);
PLCComm.FindPLCByName("理线机器人").WriteInt("516", 0.ToString());
FuncLib.ShowMsg(string.Format(" [ {0} ] 发送指令: [ {1} ]", "理线机器人", 0));
}
else {
button理线横移气缸.BackColor = Color.Green;
PLCComm.FindPLCByName("理线机器人").WriteInt("516", 1.ToString());
FuncLib.ShowMsg(string.Format(" [ {0} ] 发送指令: [ {1} ]", "理线机器人", 1));
}
}
}
private void button理线竖直气缸_Click(object sender, EventArgs e) {
if (PLCComm.FindPLCByName("理线机器人").ReadShort("555") == 0) {
if (PLCComm.FindPLCByName("理线机器人").ReadShort("516") == 2) {
button理线竖直气缸.BackColor = Color.FromArgb(4, 120, 238);
PLCComm.FindPLCByName("理线机器人").WriteInt("516", 0.ToString());
FuncLib.ShowMsg(string.Format(" [ {0} ] 发送指令: [ {1} ]", "理线机器人", 0));
}
else {
button理线竖直气缸.BackColor = Color.Green;
PLCComm.FindPLCByName("理线机器人").WriteInt("516", 2.ToString());
FuncLib.ShowMsg(string.Format(" [ {0} ] 发送指令: [ {1} ]", "理线机器人", 2));
}
}
}
private void button理线夹爪气缸_Click(object sender, EventArgs e) {
if (PLCComm.FindPLCByName("理线机器人").ReadShort("555") == 0) {
if (PLCComm.FindPLCByName("理线机器人").ReadShort("516") == 4) {
button理线夹爪气缸.BackColor = Color.FromArgb(4, 120, 238);
PLCComm.FindPLCByName("理线机器人").WriteInt("516", 0.ToString());
FuncLib.ShowMsg(string.Format(" [ {0} ] 发送指令: [ {1} ]", "理线机器人", 0));
}
else {
button理线夹爪气缸.BackColor = Color.Green;
PLCComm.FindPLCByName("理线机器人").WriteInt("516", 4.ToString());
FuncLib.ShowMsg(string.Format(" [ {0} ] 发送指令: [ {1} ]", "理线机器人", 4));
}
}
}
private void button压线气缸_Click(object sender, EventArgs e) {
if (PLCComm.FindPLCByName("理线机器人").ReadShort("555") == 0) {
if (PLCComm.FindPLCByName("理线机器人").ReadShort("516") == 8) {
button压线气缸.BackColor = Color.FromArgb(4, 120, 238);
PLCComm.FindPLCByName("理线机器人").WriteInt("516", 0.ToString());
FuncLib.ShowMsg(string.Format(" [ {0} ] 发送指令: [ {1} ]", "理线机器人", 0));
}
else {
button压线气缸.BackColor = Color.Green;
PLCComm.FindPLCByName("理线机器人").WriteInt("516", 8.ToString());
FuncLib.ShowMsg(string.Format(" [ {0} ] 发送指令: [ {1} ]", "理线机器人", 8));
}
}
}
//读写
private void buttonRead_Click(object sender, EventArgs e) {
if (textBoxAddresshj.Text == null || textBoxAddresshj.Text == "") {
return;
}
//string device = devices[0];
string device = devices[comboBoxDevice.SelectedIndex];
if (radioButtonUshort.Checked) {
int value = PLCComm.FindPLCByName(device).ReadShort(textBoxAddresshj.Text);
FuncLib.ShowMsg(string.Format(" [ {0} ] 读取数据: [ {1} ]", device, textBoxValuehj.Text));
textBoxValuehj.Text = value.ToString();
}
else {
int value = PLCComm.FindPLCByName(device).ReadInt(textBoxAddresshj.Text);
FuncLib.ShowMsg(string.Format(" [ {0} ] 读取数据: [ {1} ]", device, textBoxValuehj.Text));
textBoxValuehj.Text = value.ToString();
}
}
private void buttonWrite_Click(object sender, EventArgs e) {
if (textBoxAddresshj.Text == null || textBoxAddresshj.Text == "") {
return;
}
if (textBoxValuehj.Text == null || textBoxValuehj.Text == "") {
return;
}
string device = devices[comboBoxDevice.SelectedIndex];
if (radioButtonUshort.Checked) {
PLCComm.FindPLCByName(device).WriteShort(textBoxAddresshj.Text, textBoxValuehj.Text);
FuncLib.ShowMsg(string.Format(" [ {0} ] 发送指令: [ {1} ]", "device", textBoxValuehj.Text));
}
else {
PLCComm.FindPLCByName(device).WriteInt(textBoxAddresshj.Text, textBoxValuehj.Text); ;
FuncLib.ShowMsg(string.Format(" [ {0} ] 发送指令: [ {1} ]", "device", textBoxValuehj.Text));
}
}
}
}
GUI Code
最新推荐文章于 2024-08-14 09:44:07 发布