/// <summary> /// 写入整形 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button3_Click(object sender, EventArgs e) { if (mxComponentCla != null) { try { string[] arry = new string[1] { txtWriteAddress.Text.Trim() }; short[] arrayval = new short[1] { short.Parse(txtWriteValue.Text.Trim()) }; int x = mxComponentCla.Write(arry, arrayval); if (x == 0) { SetTextBoxInfo(string.Format("写入成功,寄存器【{0}】,值【{1}】", txtWriteAddress.Text.Trim(), txtWriteValue.Text.ToString())); } else { SetTextBoxInfo(string.Format("写入失败,寄存器【{0}】,值【{1}】", txtWriteAddress.Text.Trim(), txtWriteValue.Text.ToString())); } } catch (Exception ex) { SetTextBoxInfo(string.Format("写入错误:{0}", ex.Message)); WriteLog.WriteTextLog(ex, string.Format("寄存器【{0}】写入失败", txtWriteAddress.Text.Trim()), ""); } } }
/// <summary> /// 写入 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button5_Click(object sender, EventArgs e) { if (connectionStatus) { string arry = txtWriteAddress.Text.Trim(); short arrayval = short.Parse(txtWriteValue.Text.Trim()); int x = mxComponentCla.Write(arry, arrayval); if (x == 0) { SetTextBoxInfo(string.Format("写入成功,寄存器【{0}】,值【{1}】", arry, arrayval)); } else { SetTextBoxInfo(string.Format("写入失败,寄存器【{0}】", arry)); } } else { MessageBox.Show("PLC断线重连中,请等待PLC重连成功后再尝试", " 武汉镭立科技友情提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } }