//除尘机风扇启动停止 private void Chb_Fans_CheckedChanged(object sender, EventArgs e) { UInt32 FansSet = 0; if (Chb_Fans.Checked == true) { FansSet = 1; Chb_Fans.BackColor = Color.LightGreen; Chb_Fans.Text = "启动"; } else { FansSet = 0; Chb_Fans.BackColor = Color.Red; Chb_Fans.Text = "停止"; } int resno = CS7TCP.WriteWord(Z通讯设置.plcHandle, 0x84, device.address, 6, FansSet); }
//除尘机毛刷反转 private void Chb_Brush_R_CheckedChanged(object sender, EventArgs e) { UInt32 BrushsSet = 0; if (Chb_Brush_R.Checked == true) { Chb_Brush.Checked = false; Chb_Brush.BackColor = Color.Red; BrushsSet = 2; Chb_Brush_R.BackColor = Color.LightGreen; Chb_Brush_R.Text = "反转"; } else { BrushsSet = 0; Chb_Brush_R.BackColor = Color.Red; //Chb_Brush.Text = "反转"; } int resno = CS7TCP.WriteWord(Z通讯设置.plcHandle, 0x84, device.address, 8, BrushsSet); }
//判定离开后开始执行写入指令 //配方参数输入,,,,,,对话框中参数输入 public void handleInputComplete(object sender) { System.Windows.Forms.TextBox _textbox = (System.Windows.Forms.TextBox)sender; switch (_textbox.Name) { //主输送线速度写入 case "txb_Control_Conveyor_Main": UInt32 Write_Conveyor_Main = 0; //定义读取变量 if (txb_Control_Conveyor_Main.Text.Trim() == "") { UInt32 ReadBack_Write_Conveyor_Main = 0; CS7TCP.ReadWord(Z通讯设置.plcHandle, 0x84, device.address, 0, ref ReadBack_Write_Conveyor_Main); txb_Control_Conveyor_Main.Text = Convert.ToString(Convert.ToDecimal(ReadBack_Write_Conveyor_Main) / 10); MessageBox.Show("参数区间在1-20之间,请输入适当的参数"); } else { Write_Conveyor_Main = Convert.ToUInt32(Convert.ToDecimal(txb_Control_Conveyor_Main.Text.ToString()) * 10); //转换成String格式然后显示在textbox里面 if (Convert.ToUInt32(Convert.ToDecimal(txb_Control_Conveyor_Main.Text) * 10) <= 200 && Convert.ToUInt32(Convert.ToDecimal(txb_Control_Conveyor_Main.Text) * 10) >= 0) { int resno = CS7TCP.WriteWord(Z通讯设置.plcHandle, 0x84, device.address, 0, Write_Conveyor_Main); //写入配方编号 if (resno == 0) { A0开机画面 parent = (A0开机画面)Parent.FindForm(); parent.showLog(" 输送线速度写入成功!"); } else { MessageBox.Show("输送线速度写入失败,请重新输入"); } } else { UInt32 ReadBack_Write_Conveyor_Main = 0; CS7TCP.ReadWord(Z通讯设置.plcHandle, 0x84, device.address, 0, ref ReadBack_Write_Conveyor_Main); txb_Control_Conveyor_Main.Text = Convert.ToString(Convert.ToDecimal(ReadBack_Write_Conveyor_Main) / 10); MessageBox.Show("参数区间在1-20之间,请输入适当的参数"); } } break; //第一组高度设定写入 case "txb_Control_Brush_Height": UInt32 Write_App1_Height = 0; //定义读取变量 if (txb_Control_Brush_Height.Text.Trim() == "") { UInt32 ReadBack_Write_App1_Height = 0; CS7TCP.ReadWord(Z通讯设置.plcHandle, 0x84, device.address, 2, ref ReadBack_Write_App1_Height); txb_Control_Brush_Height.Text = Convert.ToString(Convert.ToDecimal(ReadBack_Write_App1_Height) / 100); MessageBox.Show("参数区间在1-200之间,请输入适当的参数"); } else { Write_App1_Height = Convert.ToUInt32(Convert.ToDecimal(txb_Control_Brush_Height.Text.ToString()) * 100); //转换成String格式然后显示在textbox里面 if (Convert.ToUInt32(Convert.ToDecimal(txb_Control_Brush_Height.Text) * 100) <= 20000 && Convert.ToUInt32(Convert.ToDecimal(txb_Control_Brush_Height.Text) * 100) > 0) { int resno = CS7TCP.WriteWord(Z通讯设置.plcHandle, 0x84, device.address, 2, Write_App1_Height); //写入配方编号 if (resno == 0) { A0开机画面 parent = (A0开机画面)Parent.FindForm(); parent.showLog(" 第一组高度参数写入成功!"); } else { MessageBox.Show("第一组高度参数写入失败,请重新输入"); } } else { UInt32 ReadBack_Write_App1_Height = 0; CS7TCP.ReadWord(Z通讯设置.plcHandle, 0x84, device.address, 2, ref ReadBack_Write_App1_Height); txb_Control_Brush_Height.Text = Convert.ToString(Convert.ToDecimal(ReadBack_Write_App1_Height) / 100); MessageBox.Show("参数区间在1-200之间,请输入适当的参数"); } } break; //第一组高度误差补偿设定写入 case "txb_Control_Brush_buchang": UInt32 Write_App1_buchang = 0; //定义读取变量 if (txb_Control_Brush_buchang.Text.Trim() == "") { UInt32 ReadBack_Write_App1_buchang = 0; CS7TCP.ReadWord(Z通讯设置.plcHandle, 0x84, device.address, 4, ref ReadBack_Write_App1_buchang); txb_Control_Brush_buchang.Text = Convert.ToString(Convert.ToDecimal(ReadBack_Write_App1_buchang) / 100); MessageBox.Show("参数区间在1-20之间,请输入适当的参数"); } else { Write_App1_buchang = Convert.ToUInt32(Convert.ToDecimal(txb_Control_Brush_buchang.Text.ToString()) * 100); //转换成String格式然后显示在textbox里面 if (Convert.ToUInt32(Convert.ToDecimal(txb_Control_Brush_buchang.Text) * 100) <= 10000 && Convert.ToUInt32(Convert.ToDecimal(txb_Control_Brush_buchang.Text) * 100) >= 0) { int resno = CS7TCP.WriteWord(Z通讯设置.plcHandle, 0x84, device.address, 4, Write_App1_buchang); //写入配方编号 if (resno == 0) { A0开机画面 parent = (A0开机画面)Parent.FindForm(); parent.showLog(" 第一组高度误差补偿参数写入成功!"); } else { MessageBox.Show("第一组高度误差补偿写入失败,请重新输入"); } } else { UInt32 ReadBack_Write_App1_buchang = 0; CS7TCP.ReadWord(Z通讯设置.plcHandle, 0x84, device.address, 4, ref ReadBack_Write_App1_buchang); txb_Control_Brush_buchang.Text = Convert.ToString(Convert.ToDecimal(ReadBack_Write_App1_buchang) / 100); MessageBox.Show("参数区间在1-20之间,请输入适当的参数"); } } break; //配方编号写入 case "txb_Recipe_NO": UInt32 Write_Recipe_NO = 0; //定义读取变量 if (txb_Recipe_NO.Text.Trim() == "") { UInt32 ReadBack = 0; CS7TCP.ReadWord(Z通讯设置.plcHandle, 0x84, device.address, 52, ref ReadBack); txb_Recipe_NO.Text = Convert.ToString(ReadBack); MessageBox.Show("输入无效,配方区间在1-20之间,请输入适当的配方编号"); } else { Write_Recipe_NO = Convert.ToUInt32(txb_Recipe_NO.Text.ToString()); //转换成String格式然后显示在textbox里面 if (Convert.ToUInt32(txb_Recipe_NO.Text) <= 20 && Convert.ToUInt32(txb_Recipe_NO.Text) >= 0) { int resno = CS7TCP.WriteWord(Z通讯设置.plcHandle, 0x84, device.address, 52, Write_Recipe_NO); //写入配方编号 if (resno == 0) { A0开机画面 parent = (A0开机画面)Parent.FindForm(); parent.showLog(" 配方编号写入成功!"); } else { MessageBox.Show("配方编号写入失败,请重新输入"); } } else { UInt32 ReadBack = 0; CS7TCP.ReadWord(Z通讯设置.plcHandle, 0x84, device.address, 52, ref ReadBack); txb_Recipe_NO.Text = Convert.ToString(ReadBack); MessageBox.Show("输入无效,配方区间在1-20之间,请输入适当的配方编号"); } } break; } }