private void btnWrite_Click(object sender, EventArgs e) { System.Diagnostics.Stopwatch sp = new System.Diagnostics.Stopwatch(); sp.Start(); string s = txtValuesW.Text.Trim(','); string[] ss = s.Split(','); short[] wt = new short[ss.Length]; for (int i = 0; i < ss.Length; i++) { wt[i] = short.Parse(ss[i]); } //short[] wt = new short[] { short.Parse(s) }; string address = txtAddressW.Text.Trim(); string count = txtCountW.Text.Trim(); short re = ENT.WriteWords(PlcMemory.DM, short.Parse(address), short.Parse(count), wt); sp.Stop(); txtUseTimeW.Text = sp.Elapsed.TotalMilliseconds.ToString() + "ms"; if (re != 0) { //写入数据出错 txtUseTimeW.Text += ",写入数据出错!"; } else { txtUseTimeW.Text += ",写入数据成功!"; } }
/// <summary> /// Fins发送数据 /// </summary> /// <param name="data"></param> /// <param name="dataLength"></param> public void FinsSendData(short[] data, short dataLength) { try { short mSendComlet = -1; mSendComlet = mOmronFins.WriteWords(PlcMemory.DM, 5001, dataLength, data); } catch (Exception) { mFinsConnStatus = false; throw; } if (mOmronFins.FinsConnected == false) { mFinsConnStatus = false; } }
public bool WriteMultiElement(PlcScanItems item, short ncount, short[] valuearray) { PlcMemory memorytype = item.AddressType; short startaddress = short.Parse(item.Address); short count = ncount; short result = 0; lock (writeLock) { result = omronethernetplc.WriteWords(memorytype, startaddress, ncount, valuearray); if (result == 0) { return(true); } else { bConnectOmronPLC = false; return(false); } } }