示例#1
0
        void WriteRawAsyncHandler(IAsyncResult ar)
        {
            AsyncResult a = (AsyncResult)ar;
            PLC         p = (PLC)a.AsyncState;

            p.EndWrite(ar);
        }
示例#2
0
        private void writeAsyncHandler(IAsyncResult ar)
        {
            if (InvokeRequired)
            {
                // We'll update GUI, so we need to pass the async call back processing
                // to the GUI thread.
                BeginInvoke(new AsyncCallback(writeAsyncHandler), new object[] { ar });
                return;
            }
            PLC p = (PLC)ar.AsyncState;

            try
            {
                p.EndWrite(ar);
                rwStatusL.Text = "Done";
            }
            catch (IndexOutOfRangeException exc)
            {
                rwStatusL.Text = "Out of range or max request capacity";
            }
            catch (Exception exc)
            {
                rwStatusL.Text = "Unexpected error: " + exc.Message;
            }
        }
示例#3
0
        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());
            }
        }