private void writeAsyncB_Click(object sender, EventArgs e) { PLC p = SelectedPLC; if (p == null) { return; } DynamicByteProvider dbp = (DynamicByteProvider)rwHB.ByteProvider; byte[] data = dbp.Bytes.ToArray(); int offset = (int)rwOffsetNUD.Value; rwStatusL.Text = "Writing asynchronously..."; p.BeginWriteRaw(offset, data, new AsyncCallback(writeAsyncHandler), p); }
private void massWriteB_Click(object sender, EventArgs e) { Object o = plcLB.SelectedItem; if (o == null) { return; } PLC plc = (PLC)o; MemoryStream ms = new MemoryStream(); BinaryWriter bw = new BinaryWriter(ms); for (int i = 0; i < 100; i++) { bw.Write(i * 2); } plc.BeginWriteRaw(0, ms.GetBuffer(), new AsyncCallback(WriteRawAsyncHandler), plc); }
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()); } }