Form objects not visibles using a delegate

6 Views Asked by At

I need to perform several actions in sync with the arrival of data, on the serial port. Then I simply need to display a message indicating that these characters have arrived correctly.

The message should be shown in a label (present in the the form), but I do not see it, however, and cannot handle.

The manage has been done with a delegate. Herew the code wrote:

------------------------------------------------------------------------------------------
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;

            }
        }
0

There are 0 best solutions below