Example #1
0
        public void AutoRefresh(object source, ElapsedEventArgs e)
        {
            try
            {
                var    length = Bytes.Length;
                byte[] result;
#pragma warning disable CS8602 // Dereference of a possibly null reference.
                if (psb.com is not ICommunicatorNX cnx)
                {
                    result = psb.com.ReadBytes(address, length);
                }
                else
                {
                    if (method == RWMethod.Main)
                    {
                        result = cnx.ReadBytesMain(address, length);
                    }
                    else if (method == RWMethod.Absolute)
                    {
                        result = cnx.ReadBytesAbsolute(address, length);
                    }
                    else
                    {
                        result = psb.com.ReadBytes(address, length);
                    }
                }
#pragma warning restore CS8602 // Dereference of a possibly null reference.
                RTB_RAM.Invoke((MethodInvoker) delegate { RTB_RAM.Text = string.Join(" ", result.Select(z => $"{z:X2}")); });
                refresh.Start();
            }
        public void AutoRefresh(object source, ElapsedEventArgs e)
        {
            if (!CB_AutoRefresh.Checked)
            {
                // prevent race condition between the uncheck event and auto refresh
                refresh.Stop();
                return;
            }
            try
            {
                var    length = Bytes.Length;
                byte[] result;
#pragma warning disable CS8602 // Dereference of a possibly null reference.
                if (psb.com is not ICommunicatorNX cnx)
                {
                    result = psb.com.ReadBytes(address, length);
                }
                else
                {
                    if (method == RWMethod.Main)
                    {
                        result = cnx.ReadBytesMain(address, length);
                    }
                    else if (method == RWMethod.Absolute)
                    {
                        result = cnx.ReadBytesAbsolute(address, length);
                    }
                    else
                    {
                        result = psb.com.ReadBytes(address, length);
                    }
                }
#pragma warning restore CS8602 // Dereference of a possibly null reference.
                var r_text = string.Join(" ", result.Select(z => $"{z:X2}"));
                RTB_RAM.Invoke((MethodInvoker) delegate {
                    if (RTB_RAM.Text != r_text) // Prevent text updates if there is no update since they hinder copying
                    {
                        RTB_RAM.Text = r_text;
                    }
                });
                if (RT_Timer.Enabled)
                {
                    RT_Timer.Invoke((MethodInvoker) delegate { refresh.Interval = (double)RT_Timer.Value; });
                }
                refresh.Start();
            }