示例#1
0
        private void readMultiAsyncB_Click(object sender, EventArgs e)
        {
            PLC p = SelectedPLC;

            if (p == null)
            {
                return;
            }
            int rows = readMultiDGV.Rows.Count - 1;

            if (rows < 1)
            {
                MessageBox.Show("Please at least enter 1 offset");
                return;
            }
            ushort[] offsets = new ushort[rows];
            try
            {
                for (int i = 0; i < offsets.Length; i++)
                {
                    offsets[i] = UInt16.Parse((string)readMultiDGV.Rows[i].Cells[0].Value);
                }
                readMultiStatusL.Text = "Reading asynchronously...";

                BinaryReader br = p.ReadMulti(offsets);
                p.BeginReadMulti(offsets, new AsyncCallback(readMultiAsyncHandler), new object[] { p, offsets.Length });
            }
            catch (Exception exc)
            {
                readMultiStatusL.Text = exc.Message;
            }
        }