使用委托不可见的表单对象

Form objects not visibles using a delegate

提问人:Attilio 提问时间:11/9/2023 更新时间:11/9/2023 访问量:4

问:

我需要在串行端口上执行与数据到达同步的几项操作。然后,我只需要显示一条消息,指示这些字符已正确到达。

该消息应该显示在标签中(存在于表单中),但是我没有看到它,也无法处理。

管理已通过委托完成。代码在这里写道:

------------------------------------------------------------------------------------------
Code where I can get the serial port data and the call to the delegate

 public delegate void DelegateProcessIncomingData(byte[] data);

        static public void com_Data_RX(object sender, SerialDataReceivedEventArgs e)
        {          
            SerialPort sp = (SerialPort)sender;

            if ((GblFunctions.GetEndOfFrameFlagStatus() == false))
            {           
                int expected_bytes = sp.BytesToRead;
                byte[] buffer      = new byte[expected_bytes];
                sp.Read(buffer, 0, expected_bytes);

                DelegateProcessIncomingData Proc = new DelegateProcessIncomingData(Form_UpdateFW.ProcessIncomingData);
                Proc.Invoke(buffer);
            }
            else
            {
                sp.DiscardInBuffer();
            }
        }


------------------------------------------------------------------------------------------

Code where I can manage the arrived data. The instruction to manage the label LBL_ActualOperation and the button BTN_DownLoad gives error

The show errors are:

You need an object reference for the non-static property, method or field 'Form_UpdateFW.LBL_ActualOperation

An object reference is needed for the non-static property, method or field 'Form_UpdateFW.BTN_DownLoad' 



       public static void ProcessIncomingData(byte[] data)
        {
            switch (DownLoadPhaser)
            {
                case (ushort)DOWNLOAD.PHASE_0_WAITING_CONNECTION:
                    if (AnalyzeIncomingData(data, (ushort)EXPECTED_MESSAGE.LCX_SIMPLE_PING) == true)
                    {
                        Form_SerialPort.com_Data_TX(ref MSG_OUTPUT_LCX_SIMPLE_PING, MSG_OUTPUT_LCX_SIMPLE_PING.Length);
                        
                        LBL_ActualOperation.Text = "String processed !";    // ERROR
                        BTN_DownLoad.Enabled     = true;                    // ERROR

                        DownLoadPhaser  = (ushort)DOWNLOAD.PHASE_1_CONNECTION_CARRIED_OUT;                                               
                    }
                    GblFunctions.ClearEndOfFrameFlagStatus();
                    break;

                case (ushort)DOWNLOAD.PHASE_1_CONNECTION_CARRIED_OUT:
                    // continue phases
                    break;

            }
        }
对象 静态 委托

评论


答: 暂无答案