private void readAsyncB_Click(object sender, EventArgs e) { PLC p = SelectedPLC; if (p == null) { return; } int offset = (int)rwOffsetNUD.Value; int len = (int)rwLenNUD.Value; p.BeginRead(offset, len, new AsyncCallback(readAsyncHandler), p); }
public void ReadWriteRawAsyncTest() { const int INT_COUNT = 200; MemoryStream ms = new MemoryStream(INT_COUNT * 4); BinaryWriter bw = new BinaryWriter(ms); for (int i = 0; i < INT_COUNT; i++) { bw.Write(i * 2); } IAsyncResult ar = plc.BeginWriteRaw(0, ms.GetBuffer(), null, null); ar.AsyncWaitHandle.WaitOne(); plc.EndWrite(ar); ar = plc.BeginRead(0, INT_COUNT * 4, null, null); ar.AsyncWaitHandle.WaitOne(); BinaryReader br = plc.EndRead(ar); for (int i = 0; i < INT_COUNT; i++) { Assert.AreEqual(i * 2, br.ReadInt32()); } }