• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 479
  • Last Modified:

serial port Invoke call

hi -
I'm using VS2010 and .net4.0 with a windows form applications.  
I have successfully used the following code to handle the return data from a serial device to pass the received data to the original thread:

void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
int numBytesRead = port.Read(receiveBuffer, 0, 200);
                    UpdateDisplay ud = new UpdateDisplay(UpdateDisplayMethod);

                    if (numBytesRead != 0)
                        Invoke(ud, new object[] { receiveBuffer, numBytesRead });


I have a slightly different flavor of an application where I create a class which the above code is embedded in. when I try to paste in the invoke code, VS2010 flags it with this error:
Error      29 Cannot access a non-static member of outer type 'System.Windows.Forms.Control' via nested type 'Control_Editor.CT_UI_Control.MatrixDisplay'

 the windows form code creates the class with this code:
MatrixModule = new MatrixDisplay(portNameitem);
I don't understand why i'm getting the error, and more importantly, I don't know what to do about it.
1 Solution
Miguel OzSoftware EngineerCommented:
A bit hard to say without looking at your class declaration and method signature.
Please post these details tog et the whole picture.

As an educated guess I will say that your class is defining a nested inner class and trying to access the container(outer) class as shown here (Answer from Stanley).
jdcoburnAuthor Commented:
yes - you were correct. it was a typo that I didn't catch until after I had posted this.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now