using EasyModbus; using Sunny.UI; using System; using System.Drawing; using System.Linq; using System.Web.Services.Description; using System.Windows.Forms; namespace SLC1_N { public partial class Electricity : Form { public Electricity() { InitializeComponent(); } public delegate void MySignalHandler(int msg, bool mode); // 声明信号 public event MySignalHandler Signal_PLC_WriteCoil; private void Electricity_Load(object sender, EventArgs e) { label90.Visible = false; tb_RelieveDelay.Visible = false; label104.Visible = false; // 读取一次本地参数 cb_MachineNum.SelectedIndex = 0; cb_ParaNum.SelectedIndex = 0; if (Form1.f1.User == "操作员") { chk_ChkBee.Enabled = false; bt_BtnKeep.Enabled = false; tb_FullTime.Enabled = false; tb_BalanTime.Enabled = false; tb_TestTime1.Enabled = false; tb_ExhaustTime.Enabled = false; tb_DelayTime1.Enabled = false; tb_DelayTime2.Enabled = false; tb_RelieveDelay.Enabled = false; tb_Evolume.Enabled = false; tb_FPtoplimit.Enabled = false; tb_FPlowlimit.Enabled = false; tb_BalanPreMax.Enabled = false; tb_BalanPreMin.Enabled = false; tb_Leaktoplimit.Enabled = false; tb_Leaklowlimit.Enabled = false; cb_PUnit.Enabled = false; cb_LUnit.Enabled = false; } if (Form1.f1.User == "工程师") { cb_PUnit.Enabled = false; cb_LUnit.Enabled = false; tb_FullTime.Enabled = false; tb_BalanTime.Enabled=false; tb_TestTime1.Enabled = false; tb_ExhaustTime.Enabled=false; tb_FPlowlimit.Enabled=false; tb_FPtoplimit.Enabled=false; tb_Leaktoplimit.Enabled=false; tb_Leaklowlimit.Enabled=false; } if (Form1.f1.User != "厂商") { //消失 label111.Visible = false; label112.Visible = false; label117.Visible = false; tb_BalanPreMax.Visible = false; tb_BalanPreMin.Visible = false; label116.Visible = false; } //PressMax.Text = Form1.f1.PressMax.ToString(); //PressMin.Text = Form1.f1.PressMin.ToString(); //PressingTimeMax.Text = Form1.f1.PressingTimeMax.ToString(); //PressingTimeMin.Text = Form1.f1.PressingTimeMin.ToString(); //ReadParameters(MachineNum.SelectedIndex + 1, ParaNum.SelectedIndex + 1); // Json记录读取 var config = new JsonConfig("config.json"); // 条码长度 tb_code1len.Text = config.GetValue("CodeLength1", "9"); tb_code2len.Text = config.GetValue("CodeLength2", "9"); tb_code3len.Text = config.GetValue("CodeLength3", "9"); tb_code4len.Text = config.GetValue("CodeLength4", "9"); // 是否扫码 if (Form1.f1.HCPLC_client?.Connected == true) { chk_ch1saoma.Checked = Form1.f1.coilSaoma[0]; chk_ch2saoma.Checked = Form1.f1.coilSaoma[1]; chk_ch3saoma.Checked = Form1.f1.coilSaoma[2]; chk_ch4saoma.Checked = Form1.f1.coilSaoma[3]; } else { lb_PLCsaomamsg.Text = "PLC未连接"; lb_PLCsaomamsg.ForeColor = Color.Red; } //chk_ch1saoma.Checked = config.GetValue("chk_ch1saoma", true); //chk_ch2saoma.Checked = config.GetValue("chk_ch2saoma", true); //chk_ch3saoma.Checked = config.GetValue("chk_ch3saoma", true); //chk_ch4saoma.Checked = config.GetValue("chk_ch4saoma", true); // 正负压 rbt_PpressureMode.Checked = config.GetValue("rbt_PpressureMode", true); rbt_NpressureMode.Checked = config.GetValue("rbt_NpressureMode", true); string PorN = "P"; if (rbt_PpressureMode.Checked) PorN = "P"; else if (rbt_NpressureMode.Checked) PorN = "N"; ReadParametersJson("1", "1", PorN); // 连续测试/次数 chk_ContinueTest.Checked = config.GetValue("chk_ContinueTest", true); tb_ContinueTestCount.Enabled = chk_ContinueTest.Checked; tb_ContinueTestCount.Text = config.GetValue("tb_ContinueTestCount", 1).ToString(); } //上传参数 private void BtnUpload_Click(object sender, EventArgs e) { try { bt_BtnUpload.Enabled = false; tb_RelieveDelay.Text = "0"; if (tb_FullTime.Text == "" || tb_BalanTime.Text == "" || tb_TestTime1.Text == "" || tb_ExhaustTime.Text == "" || tb_DelayTime1.Text == "" || tb_DelayTime2.Text == "" || tb_RelieveDelay.Text == "" || tb_Evolume.Text == "" || cb_LUnit.Text == "" || cb_PUnit.Text == "" || tb_FPtoplimit.Text == "" || tb_FPlowlimit.Text == "" || tb_BalanPreMax.Text == "" || tb_BalanPreMin.Text == "" || tb_Leaktoplimit.Text == "" || tb_Leaklowlimit.Text == "") { MessageBox.Show("输入参数格式不对"); } else { // 拆分 float int[] FPtoplimit = Fun_SplitBytes(float.Parse(tb_FPtoplimit.Text)); // [low, high] int[] FPlowlimit = Fun_SplitBytes(float.Parse(tb_FPlowlimit.Text)); int[] BalanPreMax = Fun_SplitBytes(float.Parse(tb_BalanPreMax.Text)); int[] BalanPreMin = Fun_SplitBytes(float.Parse(tb_BalanPreMin.Text)); int[] Leaktoplimit = Fun_SplitBytes(float.Parse(tb_Leaktoplimit.Text)); int[] Leaklowlimit = Fun_SplitBytes(float.Parse(tb_Leaklowlimit.Text)); int[] Evolume = Fun_SplitBytes(float.Parse(tb_Evolume.Text)); // 合并数据(float + int) int[] values = new int[] { Convert.ToInt32(tb_FullTime.Text) * 10, // 充气时间 Convert.ToInt32(tb_BalanTime.Text) * 10, // 平衡时间 Convert.ToInt32(tb_TestTime1.Text) * 10, // 检测时间 Convert.ToInt32(tb_ExhaustTime.Text) * 10, // 排气时间 Convert.ToInt32(tb_RelieveDelay.Text),// 解除2延时 Convert.ToInt32(tb_DelayTime1.Text), // 延时1 Convert.ToInt32(tb_DelayTime2.Text), // 延时2 FPtoplimit[0], FPtoplimit[1], // 充气上限 FPlowlimit[0], FPlowlimit[1], // 充气下限 BalanPreMax[0], BalanPreMax[1], // 平衡上限 BalanPreMin[0], BalanPreMin[1], // 平衡下限 Leaktoplimit[0], Leaktoplimit[1],// 泄漏量上限 Leaklowlimit[0], Leaklowlimit[1],// 泄漏量下限 Evolume[0], Evolume[1], // 等效容积 cb_PUnit.SelectedIndex, // 压力单位 cb_LUnit.SelectedIndex, // 泄漏量单位 }; // [low, high, 1] switch (cb_MachineNum.SelectedIndex) { case 0: Form1.f1.LL28CH1client.writeRegisters(1006, values); // 通道1 从1006 开始写入 Signal_PLC_WriteCoil?.Invoke(1008, rbt_NpressureMode.Checked); break; case 1: Form1.f1.LL28CH2client.writeRegisters(1006, values); // 通道2 从1006 开始写入 Signal_PLC_WriteCoil?.Invoke(1009, rbt_NpressureMode.Checked); break; case 2: Form1.f1.LL28CH3client.writeRegisters(1006, values); // 通道3 从1006 开始写入 Signal_PLC_WriteCoil?.Invoke(1010, rbt_NpressureMode.Checked); break; case 3: Form1.f1.LL28CH4client.writeRegisters(1006, values); // 通道4 从1006 开始写入 Signal_PLC_WriteCoil?.Invoke(1011, rbt_NpressureMode.Checked); break; } } bt_BtnUpload.Enabled = true; } catch (Exception ex) { MessageBox.Show(ex.Message); mxlLog.Instance.Error($"参数界面上传异常,行号{ex.StackTrace} ", ex); } } // 将 float 拆分为两个(低字在前,高字在后) public int[] Fun_SplitBytes(float value) { byte[] bytes = BitConverter.GetBytes(value); ushort lowWord = BitConverter.ToUInt16(bytes, 0); // 低位(地址1015) ushort highWord = BitConverter.ToUInt16(bytes, 2); // 高位(地址1016) return new int[] { lowWord, highWord }; // 返回 [low, high] } //修改蜂鸣器设定,写入0是打开蜂鸣器,写入1是关闭蜂鸣器 // 读取参数 按钮 private void BtnRead_Click(object sender, EventArgs e) { try { // 通道1 if(cb_MachineNum.Text == "1") { tb_FullTime.Text = (Form1.f1.LL28CH1client.ArrRegister[6] / 10.0).ToString(); tb_BalanTime.Text = (Form1.f1.LL28CH1client.ArrRegister[7] / 10.0).ToString(); tb_TestTime1.Text = (Form1.f1.LL28CH1client.ArrRegister[8] / 10.0).ToString(); tb_ExhaustTime.Text = (Form1.f1.LL28CH1client.ArrRegister[9] / 10.0).ToString(); tb_DelayTime1.Text = Form1.f1.LL28CH1client.ArrRegister[11].ToString(); tb_DelayTime2.Text = Form1.f1.LL28CH1client.ArrRegister[12].ToString(); tb_Evolume.Text = Form1.f1.LL28CH1client.readFloat(25); tb_FPtoplimit.Text = Form1.f1.LL28CH1client.readFloat(13); tb_FPlowlimit.Text = Form1.f1.LL28CH1client.readFloat(15); cb_PUnit.SelectedIndex = Convert.ToInt32(Form1.f1.LL28CH1client.ArrRegister[27]); cb_LUnit.SelectedIndex = Convert.ToInt32(Form1.f1.LL28CH1client.ArrRegister[28]); tb_BalanPreMax.Text = Form1.f1.LL28CH1client.readFloat(17); tb_BalanPreMin.Text = Form1.f1.LL28CH1client.readFloat(19); tb_Leaktoplimit.Text = Form1.f1.LL28CH1client.readFloat(21); tb_Leaklowlimit.Text = Form1.f1.LL28CH1client.readFloat(23); chk_ChkBee.Checked = Form1.f1.LL28CH1client.ArrCoil[4]; } // 通道2 if (cb_MachineNum.Text == "2") { tb_FullTime.Text = (Form1.f1.LL28CH2client.ArrRegister[6] / 10.0).ToString(); tb_BalanTime.Text = (Form1.f1.LL28CH2client.ArrRegister[7] / 10.0).ToString(); tb_TestTime1.Text = (Form1.f1.LL28CH2client.ArrRegister[8] / 10.0).ToString(); tb_ExhaustTime.Text = (Form1.f1.LL28CH2client.ArrRegister[9] / 10.0).ToString(); tb_DelayTime1.Text = Form1.f1.LL28CH2client.ArrRegister[11].ToString(); tb_DelayTime2.Text = Form1.f1.LL28CH2client.ArrRegister[12].ToString(); tb_Evolume.Text = Form1.f1.LL28CH2client.readFloat(25); tb_FPtoplimit.Text = Form1.f1.LL28CH2client.readFloat(13); tb_FPlowlimit.Text = Form1.f1.LL28CH2client.readFloat(15); cb_PUnit.SelectedIndex = Convert.ToInt32(Form1.f1.LL28CH2client.ArrRegister[27]); cb_LUnit.SelectedIndex = Convert.ToInt32(Form1.f1.LL28CH2client.ArrRegister[28]); tb_BalanPreMax.Text = Form1.f1.LL28CH2client.readFloat(17); tb_BalanPreMin.Text = Form1.f1.LL28CH2client.readFloat(19); tb_Leaktoplimit.Text = Form1.f1.LL28CH2client.readFloat(21); tb_Leaklowlimit.Text = Form1.f1.LL28CH2client.readFloat(23); chk_ChkBee.Checked = Form1.f1.LL28CH2client.ArrCoil[4]; } // 通道3 if (cb_MachineNum.Text == "3") { tb_FullTime.Text = (Form1.f1.LL28CH3client.ArrRegister[6] / 10.0).ToString(); tb_BalanTime.Text = (Form1.f1.LL28CH3client.ArrRegister[7] / 10.0).ToString(); tb_TestTime1.Text = (Form1.f1.LL28CH3client.ArrRegister[8] / 10.0).ToString(); tb_ExhaustTime.Text = (Form1.f1.LL28CH3client.ArrRegister[9] / 10.0).ToString(); tb_DelayTime1.Text = Form1.f1.LL28CH3client.ArrRegister[11].ToString(); tb_DelayTime2.Text = Form1.f1.LL28CH3client.ArrRegister[12].ToString(); tb_Evolume.Text = Form1.f1.LL28CH3client.readFloat(25); tb_FPtoplimit.Text = Form1.f1.LL28CH3client.readFloat(13); tb_FPlowlimit.Text = Form1.f1.LL28CH3client.readFloat(15); cb_PUnit.SelectedIndex = Convert.ToInt32(Form1.f1.LL28CH3client.ArrRegister[27]); cb_LUnit.SelectedIndex = Convert.ToInt32(Form1.f1.LL28CH3client.ArrRegister[28]); tb_BalanPreMax.Text = Form1.f1.LL28CH3client.readFloat(17); tb_BalanPreMin.Text = Form1.f1.LL28CH3client.readFloat(19); tb_Leaktoplimit.Text = Form1.f1.LL28CH3client.readFloat(21); tb_Leaklowlimit.Text = Form1.f1.LL28CH3client.readFloat(23); chk_ChkBee.Checked = Form1.f1.LL28CH3client.ArrCoil[4]; } // 通道4 if (cb_MachineNum.Text == "4") { tb_FullTime.Text = (Form1.f1.LL28CH4client.ArrRegister[6] / 10.0).ToString(); tb_BalanTime.Text = (Form1.f1.LL28CH4client.ArrRegister[7] / 10.0).ToString(); tb_TestTime1.Text = (Form1.f1.LL28CH4client.ArrRegister[8] / 10.0).ToString(); tb_ExhaustTime.Text = (Form1.f1.LL28CH4client.ArrRegister[9] / 10.0).ToString(); tb_DelayTime1.Text = Form1.f1.LL28CH4client.ArrRegister[11].ToString(); tb_DelayTime2.Text = Form1.f1.LL28CH4client.ArrRegister[12].ToString(); tb_Evolume.Text = Form1.f1.LL28CH4client.readFloat(25); tb_FPtoplimit.Text = Form1.f1.LL28CH4client.readFloat(13); tb_FPlowlimit.Text = Form1.f1.LL28CH4client.readFloat(15); cb_PUnit.SelectedIndex = Convert.ToInt32(Form1.f1.LL28CH4client.ArrRegister[27]); cb_LUnit.SelectedIndex = Convert.ToInt32(Form1.f1.LL28CH4client.ArrRegister[28]); tb_BalanPreMax.Text = Form1.f1.LL28CH4client.readFloat(17); tb_BalanPreMin.Text = Form1.f1.LL28CH4client.readFloat(19); tb_Leaktoplimit.Text = Form1.f1.LL28CH4client.readFloat(21); tb_Leaklowlimit.Text = Form1.f1.LL28CH4client.readFloat(23); chk_ChkBee.Checked = Form1.f1.LL28CH4client.ArrCoil[4]; } } catch (Exception ex) { MessageBox.Show(ex.Message); mxlLog.Instance.Error($"参数界面读取异常,行号{ex.StackTrace} ", ex); } } // 保存参数 按钮 private void BtnKeep_Click(object sender, EventArgs e) { string PorN = "P"; if(rbt_PpressureMode.Checked) PorN = "P"; else if (rbt_NpressureMode.Checked) PorN = "N"; SetParametersJson(Convert.ToInt32(cb_MachineNum.Text), cb_ParaNum.Text, PorN); // 通道-编号 } // 写入参数 通道-编号 private void SetParametersJson(int CH, string i, string PorN) { // 保存到本地文件 var config = new JsonConfig("config.json"); config.SetValue($"{CH}" + PorN + "params_number" + i, cb_ParaNum.Text); config.SetValue($"{CH}" + PorN + "paraname" + i, tb_ParaName.Text); config.SetValue($"{CH}" + PorN + "fulltime" + i, tb_FullTime.Text); config.SetValue($"{CH}" + PorN + "balantime" + i, tb_BalanTime.Text); config.SetValue($"{CH}" + PorN + "testtime1" + i, tb_TestTime1.Text); config.SetValue($"{CH}" + PorN + "exhausttime" + i, tb_ExhaustTime.Text); config.SetValue($"{CH}" + PorN + "delaytime1" + i, tb_DelayTime1.Text); config.SetValue($"{CH}" + PorN + "delaytime2" + i, tb_DelayTime2.Text); config.SetValue($"{CH}" + PorN + "relievedelay" + i, tb_RelieveDelay.Text); config.SetValue($"{CH}" + PorN + "evolume" + i, tb_Evolume.Text); config.SetValue($"{CH}" + PorN + "fptoplimit" + i, tb_FPtoplimit.Text); config.SetValue($"{CH}" + PorN + "fplowlimit" + i, tb_FPlowlimit.Text); config.SetValue($"{CH}" + PorN + "balanpremax" + i, tb_BalanPreMax.Text); config.SetValue($"{CH}" + PorN + "balanpremin" + i, tb_BalanPreMin.Text); config.SetValue($"{CH}" + PorN + "leaktoplimit" + i, tb_Leaktoplimit.Text); config.SetValue($"{CH}" + PorN + "leaklowlimit" + i, tb_Leaklowlimit.Text); config.SetValue($"{CH}" + PorN + "punit" + i, cb_PUnit.SelectedIndex); config.SetValue($"{CH}" + PorN + "lunit" + i, cb_LUnit.SelectedIndex); config.SetValue($"{CH}" + PorN + "bee" + i, chk_ChkBee.Checked); // 保存开口、容积 if(rbt_OpeningMode.Checked) { config.SetValue($"{CH}" + PorN + "opmode" + i, false); } else if (rbt_VolumeMode.Checked) { config.SetValue($"{CH}" + PorN + "opmode" + i, true); } // 保存到主界面变量 Form1.f1.GetYiqiParam(CH, PorN).fulltime = Convert.ToInt32(tb_FullTime.Text); Form1.f1.GetYiqiParam(CH, PorN).balantime = Convert.ToInt32(tb_BalanTime.Text); Form1.f1.GetYiqiParam(CH, PorN).testtime1 = Convert.ToInt32(tb_TestTime1.Text); Form1.f1.GetYiqiParam(CH, PorN).exhausttime = Convert.ToInt32(tb_ExhaustTime.Text); Form1.f1.GetYiqiParam(CH, PorN).delaytime1 = Convert.ToInt32(tb_DelayTime1.Text); Form1.f1.GetYiqiParam(CH, PorN).delaytime2 = Convert.ToInt32(tb_DelayTime2.Text); Form1.f1.GetYiqiParam(CH, PorN).relievedelay = Convert.ToInt32(tb_RelieveDelay.Text); Form1.f1.GetYiqiParam(CH, PorN).evolume = StringToFloat(tb_Evolume.Text); Form1.f1.GetYiqiParam(CH, PorN).fptoplimit = StringToFloat(tb_FPtoplimit.Text); Form1.f1.GetYiqiParam(CH, PorN).fplowlimit = StringToFloat(tb_FPlowlimit.Text); Form1.f1.GetYiqiParam(CH, PorN).balanpremax = StringToFloat(tb_BalanPreMax.Text); Form1.f1.GetYiqiParam(CH, PorN).balanpremin = StringToFloat(tb_BalanPreMin.Text); Form1.f1.GetYiqiParam(CH, PorN).leaktoplimit = StringToFloat(tb_Leaktoplimit.Text); Form1.f1.GetYiqiParam(CH, PorN).leaklowlimit = StringToFloat(tb_Leaklowlimit.Text); Form1.f1.GetYiqiParam(CH, PorN).punit = cb_PUnit.SelectedIndex; Form1.f1.GetYiqiParam(CH, PorN).lunit = cb_LUnit.SelectedIndex; Form1.f1.GetYiqiParam(CH, PorN).opmode = rbt_VolumeMode.Checked; //mesconfig.IniWriteValue("Parameters", CH + "unit", CHKUnit.Checked.ToString()); //mesconfig.IniWriteValue("Parameters", CH + "presscompensation", PressCompensation.Text); //MessageBox.Show("仪器编号:" + CH + "保存" + i + "组参数成功!"); } private float StringToFloat(string value, float defaultValue = 0f) { return float.TryParse(value, out float result) ? result : defaultValue; } // 读取本地参数记录 private void ReadParametersJson(string CH, string i, string PorN) { var config = new JsonConfig("config.json"); //ParaNum.Text = config.GetValue($"{CH}" + "params_number" + i, ""); tb_ParaName.Text = config.GetValue($"{CH}" + PorN + "paraname" + i, "0"); tb_FullTime.Text = config.GetValue($"{CH}" + PorN + "fulltime" + i, "0"); tb_BalanTime.Text = config.GetValue($"{CH}" + PorN + "balantime" + i, "0"); tb_TestTime1.Text = config.GetValue($"{CH}" + PorN + "testtime1" + i, "0"); tb_ExhaustTime.Text = config.GetValue($"{CH}" + PorN + "exhausttime" + i, "0"); tb_DelayTime1.Text = config.GetValue($"{CH}" + PorN + "delaytime1" + i, "0"); tb_DelayTime2.Text = config.GetValue($"{CH}" + PorN + "delaytime2" + i, "0"); tb_RelieveDelay.Text = config.GetValue($"{CH}" + PorN + "relievedelay" + i, "0"); tb_Evolume.Text = config.GetValue($"{CH}" + PorN + "evolume" + i, "0"); tb_FPtoplimit.Text = config.GetValue($"{CH}" + PorN + "fptoplimit" + i, "0"); tb_FPlowlimit.Text = config.GetValue($"{CH}" + PorN + "fplowlimit" + i, "0"); tb_BalanPreMax.Text = config.GetValue($"{CH}" + PorN + "balanpremax" + i, "0"); tb_BalanPreMin.Text = config.GetValue($"{CH}" + PorN + "balanpremin" + i, "0"); tb_Leaktoplimit.Text = config.GetValue($"{CH}" + PorN + "leaktoplimit" + i, "0"); tb_Leaklowlimit.Text = config.GetValue($"{CH}" + PorN + "leaklowlimit" + i, "0"); cb_PUnit.SelectedIndex = config.GetValue($"{CH}" + PorN + "punit" + i, 1); cb_LUnit.SelectedIndex = config.GetValue($"{CH}" + PorN + "lunit" + i, 1); chk_ChkBee.Checked = config.GetValue($"{CH}" + PorN + "bee" + i, false); // 容积/开口 bool kk = config.GetValue($"{CH}" + PorN + "opmode" + i, false); if (kk == false) { rbt_OpeningMode.Checked = true; } else if (kk == true) { rbt_VolumeMode.Checked = true; } } private void MachineNum_KeyPress(object sender, KeyPressEventArgs e) { e.Handled = true; // 通道下拉框禁止所有输入 } // 通道下拉框变化 private void MachineNum_SelectedIndexChanged(object sender, EventArgs e) { string PorN = "P"; if (rbt_PpressureMode.Checked) PorN = "P"; else if (rbt_NpressureMode.Checked) PorN = "N"; ReadParametersJson(cb_MachineNum.Text, cb_ParaNum.Text, PorN); } // 编号下拉框变化 private void ParaNum_SelectedIndexChanged(object sender, EventArgs e) { string PorN = "P"; if (rbt_PpressureMode.Checked) PorN = "P"; else if (rbt_NpressureMode.Checked) PorN = "N"; ReadParametersJson(cb_MachineNum.Text, cb_ParaNum.Text, PorN); } // 不知道干嘛的,隐藏在下面 private void SaveConfig_Click(object sender, EventArgs e) { try { //Form1.f1.PressMax = Convert.ToDouble(PressMax.Text); //Form1.f1.PressMin = Convert.ToDouble(PressMin.Text); //Form1.f1.PressingTimeMax = Convert.ToDouble(PressingTimeMax.Text); //Form1.f1.PressingTimeMin = Convert.ToDouble(PressingTimeMin.Text); //string dialog = Form1.f1.machine; //ConfigINI mesconfig = new ConfigINI("Model", dialog); //mesconfig.IniWriteValue("Press", "PressMax", PressMax.Text); //mesconfig.IniWriteValue("Press", "PressMin", PressMin.Text); //mesconfig.IniWriteValue("Press", "PressingTimeMax", PressingTimeMax.Text); //mesconfig.IniWriteValue("Press", "PressingTimeMin", PressingTimeMin.Text); } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void Electricity_FormClosed(object sender, FormClosedEventArgs e) { Signal_PLC_WriteCoil = null; } // 条码长度保存按钮 private void uiSymbolButton1_Click(object sender, EventArgs e) { Form1.f1.tb_CH1codeLeng.Text = tb_code1len.Text; Form1.f1.tb_CH2codeLeng.Text = tb_code2len.Text; Form1.f1.tb_CH3codeLeng.Text = tb_code3len.Text; Form1.f1.tb_CH4codeLeng.Text = tb_code4len.Text; if (Form1.f1.saomaClient1 != null) Form1.f1.saomaClient1.codeLength = Convert.ToInt32(tb_code1len.Text); if (Form1.f1.saomaClient2 != null) Form1.f1.saomaClient2.codeLength = Convert.ToInt32(tb_code2len.Text); //if (Form1.f1.saomaClient3 != null) // Form1.f1.saomaClient3.codeLength = Convert.ToInt32(tb_code1len.Text); //if (Form1.f1.saomaClient4 != null) // Form1.f1.saomaClient5.codeLength = Convert.ToInt32(tb_code2len.Text); // Json记录 var config = new JsonConfig("config.json"); config.SetValue("CodeLength1", tb_code1len.Text); config.SetValue("CodeLength2", tb_code2len.Text); config.SetValue("CodeLength3", tb_code3len.Text); config.SetValue("CodeLength4", tb_code4len.Text); //MessageBox.Show("设置成功"); } // 通道1扫码 private void checkBox1_CheckedChanged(object sender, EventArgs e) { if (chk_ch1saoma.Checked) { Signal_PLC_WriteCoil?.Invoke(1012, true); } else { Signal_PLC_WriteCoil?.Invoke(1012, false); } var config = new JsonConfig("config.json"); config.SetValue("chk_ch1saoma", chk_ch1saoma.Checked); } // 通道2扫码 private void checkBox2_CheckedChanged(object sender, EventArgs e) { if (chk_ch2saoma.Checked) { Signal_PLC_WriteCoil?.Invoke(1013, true); } else { Signal_PLC_WriteCoil?.Invoke(1013, false); } var config = new JsonConfig("config.json"); config.SetValue("chk_ch2saoma", chk_ch2saoma.Checked); } // 通道3扫码 private void chk_ch3saoma_CheckedChanged(object sender, EventArgs e) { if (chk_ch3saoma.Checked) { Signal_PLC_WriteCoil?.Invoke(1014, true); } else { Signal_PLC_WriteCoil?.Invoke(1014, false); } var config = new JsonConfig("config.json"); config.SetValue("chk_ch3saoma", chk_ch3saoma.Checked); } // 通道4扫码 private void chk_ch4saoma_CheckedChanged(object sender, EventArgs e) { if (chk_ch4saoma.Checked) { Signal_PLC_WriteCoil?.Invoke(1015, true); } else { Signal_PLC_WriteCoil?.Invoke(1015, false); } var config = new JsonConfig("config.json"); config.SetValue("chk_ch4saoma", chk_ch4saoma.Checked); } // 单位下拉框 private void PUnit_TextChanged(object sender, EventArgs e) { lb_PUnit1.Text = cb_PUnit.Text; lb_PUnit2.Text = cb_PUnit.Text; } private void LUnit_TextChanged(object sender, EventArgs e) { lb_LUnit1.Text = cb_LUnit.Text; lb_LUnit2.Text = cb_LUnit.Text; } // 蜂鸣器 private void chk_ChkBee_CheckedChanged(object sender, EventArgs e) { switch (cb_MachineNum.SelectedIndex) { case 0: Form1.f1.LL28CH1client.writeCoil("4", chk_ChkBee.Checked); break; case 1: Form1.f1.LL28CH2client.writeCoil("4", chk_ChkBee.Checked); break; case 2: Form1.f1.LL28CH3client.writeCoil("4", chk_ChkBee.Checked); break; case 3: Form1.f1.LL28CH4client.writeCoil("4", chk_ChkBee.Checked); break; } } //// 容积模式/开口模式 //private void rbt_VolumeModeOrOpeningMode_Click(object sender, EventArgs e) //{ // if(rbt_VolumeMode.Checked) // { // Signal_PLC_WriteCoil?.Invoke(1000, true); // Signal_PLC_WriteCoil?.Invoke(1001, true); // Signal_PLC_WriteCoil?.Invoke(1002, true); // Signal_PLC_WriteCoil?.Invoke(1003, true); // } // else if(rbt_OpeningMode.Checked) // { // Signal_PLC_WriteCoil?.Invoke(1000, false); // Signal_PLC_WriteCoil?.Invoke(1001, false); // Signal_PLC_WriteCoil?.Invoke(1002, false); // Signal_PLC_WriteCoil?.Invoke(1003, false); // } // var config = new JsonConfig("config.json"); // config.SetValue("rbt_VolumeMode", rbt_VolumeMode.Checked); // config.SetValue("rbt_OpeningMode", rbt_OpeningMode.Checked); //} // 正负压 private void rbt_PpressureModeOr_NpressureMode_Click(object sender, EventArgs e) { if (rbt_PpressureMode.Checked) { string PorN = "P"; if (rbt_PpressureMode.Checked) PorN = "P"; else if (rbt_NpressureMode.Checked) PorN = "N"; ReadParametersJson(cb_MachineNum.Text, cb_ParaNum.Text, PorN); //Signal_PLC_WriteCoil?.Invoke(1008, false); //Signal_PLC_WriteCoil?.Invoke(1009, false); //Signal_PLC_WriteCoil?.Invoke(1010, false); //Signal_PLC_WriteCoil?.Invoke(1011, false); } else if (rbt_NpressureMode.Checked) { string PorN = "P"; if (rbt_PpressureMode.Checked) PorN = "P"; else if (rbt_NpressureMode.Checked) PorN = "N"; ReadParametersJson(cb_MachineNum.Text, cb_ParaNum.Text, PorN); //Signal_PLC_WriteCoil?.Invoke(1008, true); //Signal_PLC_WriteCoil?.Invoke(1009, true); //Signal_PLC_WriteCoil?.Invoke(1010, true); //Signal_PLC_WriteCoil?.Invoke(1011, true); } var config = new JsonConfig("config.json"); config.SetValue("rbt_PpressureMode", rbt_PpressureMode.Checked); config.SetValue("rbt_NpressureMode", rbt_NpressureMode.Checked); } // 是否连续测试 private void chk_ContinueTest_CheckedChanged(object sender, EventArgs e) { Form1.f1.m_ContinueTest = chk_ContinueTest.Checked; tb_ContinueTestCount.Enabled = chk_ContinueTest.Checked; var config = new JsonConfig("config.json"); config.SetValue("chk_ContinueTest", chk_ContinueTest.Checked); } // 连续次数 private void tb_ContinueTestCount_TextChanged(object sender, EventArgs e) { if(string.IsNullOrEmpty(tb_ContinueTestCount.Text)) return; Form1.f1.m_ContinueTestCount = Convert.ToInt32(tb_ContinueTestCount.Text); var config = new JsonConfig("config.json"); config.SetValue("tb_ContinueTestCount", Convert.ToInt32(tb_ContinueTestCount.Text)); } } }