When a byte from the serial port is received, it enters this handler correctly, but my label on the GUI does not change. Edit: Yes, it is in the same class as the GUI
Edit 2 The function declaration does not need to be ‘static’…I merely copy-pasted an example from msdn
edit 3 It works after getting rid of the static decleration and using something like this.
Thanks for your help
private static void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
{
Form1 gui = new Form1(); //main GUI
try
{
SerialPort sp = (SerialPort)sender;
string indata = sp.ReadExisting();
//gui.rxLabel.Text = indata;
gui.txLabel.Text = "testttingg";
}
.......
Why are you declaring a new instance of your form? Just use your form’s
txLabelIn c#:
this.txLabel.Text = "testing";In vb.net:
Me.txLabel.Text = "testing"In the sample code you posted you are creating a new instance / reference to your actual form. Use the existing instance, in addition, use
thisrather then a new instance.I had to edit my question as I noticed you were using a static method.
Try this:
Of course I am just calling
DataReceivedHandler()from a button event, you can call it from your own event. Point being is you need to pass the current instance,thisto the function. Once inside the function do not create a new instance of the form, just set a reference to the current form and use that reference to apply the settings to the property (txtBox or Label or whatever).