using Bro.Common.Helper; using Bro.UI.Model.Winform; 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 Windows.UI.Composition.Interactions; namespace Bro.M141.Process.UI { [MenuNode("ProductStatus", "PLC状态显示界面", 1, EnumHelper.TopMenu.SystemInfo, MenuNodeType.Form)] //public partial class PLCstate : UserControl public partial class PLCstate : MenuFormBase { public PLCstate() { InitializeComponent(); } M141Process M141Process => Process as M141Process; public override void OnProcessUpdated() { base.OnProcessUpdated(); M141Process.RefreshUIplc -= RefreshUI; M141Process.RefreshUIplc += RefreshUI; //lab11 皮带速度 //lab12 单位mm/s } Dictionary address = new Dictionary(); private void button1_Click(object sender, EventArgs e) { M141Process.PlcWrite(3021, State_now[1] == 1 ? 0 : 1); } private void button3_Click(object sender, EventArgs e) { M141Process.PlcWrite(3023, State_now[3] == 1 ? 0 : 1); } private void button2_Click(object sender, EventArgs e) { M141Process.PlcWrite(3022, State_now[2] == 1 ? 0 : 1); } private void button4_Click(object sender, EventArgs e) { M141Process.PlcWrite(3020, State_now[0] == 1 ? 0 : 1); } private void button5_Click(object sender, EventArgs e) { M141Process.PlcWrite(3024, State_now[7] == 1 ? 0 : 1); } List State_now = new List() { }; public void RefreshUI(List Intstate) { this.Invoke(new Action(() => { if (Intstate.Count == 17) { State_now = Intstate; label4.Text = "阻挡气缸当前状态: " + (Intstate[0] == 1 ? "伸出" : "缩回"); button4.Text = "阻挡气缸" + (Intstate[0] == 0 ? "伸出" : "缩回"); label1.Text = "收料气缸1当前状态: " + (Intstate[1] == 0 ? "伸出" : "缩回"); button1.Text = "收料气缸1" + (Intstate[1] == 1 ? "伸出" : "缩回"); label2.Text = "收料气缸2当前状态: " + (Intstate[2] == 0 ? "伸出" : "缩回"); button2.Text = "收料气缸2" + (Intstate[2] == 1 ? "伸出" : "缩回"); label3.Text = "收料气缸3当前状态: " + (Intstate[3] == 0 ? "伸出" : "缩回"); button3.Text = "收料气缸3" + (Intstate[3] == 1 ? "伸出" : "缩回"); label10.Text = "皮带当前状态: " + (Intstate[7] == 0 ? "停止" : "旋转"); button5.Text = "皮带" + (Intstate[7] == 1 ? "停止" : "旋转"); label5.Text = "通道1有无料: " + (Intstate[4] == 0 ? "无料" : "有料"); label6.Text = "通道2有无料: " + (Intstate[5] == 0 ? "无料" : "有料"); label7.Text = "通道3有无料: " + (Intstate[6] == 0 ? "无料" : "有料"); string Alarmstr = ""; for (int i = 10; i <= 16; i++) { if (Intstate[i] == 1) { Alarmstr += address[i] + "\r\n"; } } if (string.IsNullOrEmpty(Alarmstr)) { label9.Text = "无"; label9.BackColor = Color.Transparent; } else { label9.Text = Alarmstr; LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"PLC报警信息: {Alarmstr}"); label9.BackColor = Color.Red; } } else if (Intstate.Count == 8) { label18.Text = Intstate[0].ToString(); label19.Text = Intstate[4].ToString(); label17.Text = Intstate[6].ToString(); } })); } private void PLCstate_Load(object sender, EventArgs e) { address[0] = "阻挡气缸"; address[1] = "收缩气缸1"; address[2] = "收缩气缸2"; address[3] = "收缩气缸3"; address[4] = "通道1有无料"; address[5] = "通道2有无料"; address[6] = "通道3有无料"; address[10] = "阻挡气缸原点报警"; address[11] = "收料气缸1动点报警"; address[12] = "收料气缸2动点报警"; address[13] = "收料气缸3动点报警"; address[14] = "急停报警"; address[15] = "皮带轴报警"; address[16] = "上位机通讯报警"; } private void button6_Click(object sender, EventArgs e) { int speed = 0; try { speed = Convert.ToInt32(textBox1.Text); M141Process.PlcWrite(3010, speed); } catch { MessageBox.Show("请输入有效数字"); return; } } private void button7_Click(object sender, EventArgs e) { int speed = 0; try { speed = Convert.ToInt32(textBox2.Text); //M141Process.PlcWrite(3012, speed / 100); M141Process.PlcWrite(3014, speed); } catch { MessageBox.Show("请输入有效数字"); return; } } private void label9_Click(object sender, EventArgs e) { } private void label8_Click(object sender, EventArgs e) { } private void button8_Click(object sender, EventArgs e) { int speed = 0; try { speed = Convert.ToInt32(textBox3.Text); //M141Process.PlcWrite(3012, speed / 100); M141Process.PlcWrite(3016, speed); } catch { MessageBox.Show("请输入有效数字"); return; } } int linestate = 1; private void button9_Click(object sender, EventArgs e) { M141Process.PlcWrite(3026, linestate); linestate = linestate == 1 ? 0 : 1; } private void button10_Click(object sender, EventArgs e) { M141Process.PlcWrite(3025, 1); } } }