Click here to Skip to main content
15,304,433 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm writing a programm using serial port to receive data from serial port, then based on it to add some buttons. I've already shown all the received datas in a textbox,and all I want to do now is : If in the received string contains "0x0000", it will hide a button and a textbox, here's what i 've tried so far:

C#

C#
if (myString.Contains("0x0000"))
{
    newtemperature.Visible = false;
    neue_temperatur.Visible = false;
}



It works only, when the string "0x0000" was the last string received. Then i tried the Enabled property, it works perfectly! But I still want to hide those buttons.How could i do this? Any help is appreciated!
Posted

C#

public delegate void AddDataDelegate(String myString);
public AddDataDelegate myDelegate;

void scanOnOff()
{
serialPort1.DataReceived += new SerialDataReceivedEventHandler(serialPort1_DataReceived);
myDelegate = AddDataMethod;
}

void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
SerialPort port = (SerialPort)sender;
string indata = port.ReadLine();
Console.WriteLine(indata);
richTextBox1.Invoke(myDelegate, new Object[] { indata });
}

public void AddDataMethod(String myString)
{
if (myString.Contains("0x0000"))
{
newtemperature.Visible = false;
neue_temperatur.Visible = false;
}
}
   
Can you please Post the complete code?
I do not see anything wrong in your code as its very straight forward that if mySring contains 0x0000, then hide some controls.

Also you mentioned that it works only if the last received string is 0x0000. Can you please check, to concatenate all the string which you are receiving in a single variable and then apply that check on that single variable?
   
Comments
Deepu S Nair 20-Apr-15 4:19am
   
Don't post your comment as solution.Use 'Have a Question or Comment?' link.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900