public void butWrite_Click(System.Object sender, System.EventArgs e) { short i = 0; short re = 0; string[] temp = null; object[] WD = null; if (!EntLink) { MessageBox.Show("还未与PLC建立联接!"); return; } WD = new object[Convert.ToUInt16(txtWriteCnt.Text)]; temp = txtWrite.Text.Split('\n'); for (i = 0; i < WD.Length; i++) { if (i >= temp.Length) { WD[i] = 0; } else { WD[i] = temp[i].Trim(); } } int var1 = cmbWriteMry.SelectedIndex + 1; FinsCom.PlcCom.PlcMemory mry = (FinsCom.PlcCom.PlcMemory)var1; var1 = cmbWriteType.SelectedIndex + 1; FinsCom.PlcCom.DataType typ = (FinsCom.PlcCom.DataType)var1; re = PLC.CmdWrite(Convert.ToUInt16(txtStation.Text), mry, typ, Convert.ToUInt16(txtWriteAdd.Text), Convert.ToUInt16(txtWriteCnt.Text), ref WD); txtReWrite.Text = re.ToString(); }
public void butRead_Click(System.Object sender, System.EventArgs e) { short i = 0; short re = 0; object[] RD = null; RD = new object[Convert.ToUInt16(txtReadCnt.Text)]; if (!EntLink) { MessageBox.Show("还未与PLC建立联接!"); return; } int var1 = cmbReadMry.SelectedIndex + 1; FinsCom.PlcCom.PlcMemory mry = (FinsCom.PlcCom.PlcMemory)var1; var1 = cmbReadType.SelectedIndex + 1; FinsCom.PlcCom.DataType typ = (FinsCom.PlcCom.DataType)var1; re = PLC.CmdRead(Convert.ToUInt16(txtStation.Text), mry, typ, Convert.ToUInt16(txtReadAdd.Text), Convert.ToUInt16(txtReadCnt.Text), ref RD); txtReRead.Text = re.ToString(); lstRead.Items.Clear(); for (i = 0; i < RD.Length; i++) { if (!ReferenceEquals(RD[i], null)) { lstRead.Items.Add(RD[i]); } else { lstRead.Items.Add("0"); } } }