I have created an application in visual studio 2012 c++. The idea is to read the data from the serial port and to change the color for the label accordingly.I have used while loop to change the color in a continuous manner. Now, the application
is working perfectly. The problem am facing is the application not existing when i click on the exit button or 'x' button in the application.I can able to close only in task manager by clicking on end task. The following is code of my application. Please let
me know is there any way to fix this problem
while(checkBox1->Checked)
{
if(this->serialPort1->IsOpen)
{
int b[4] = {0};
int *ptr1;
ptr1 = b;
//this->serialPort1->DiscardInBuffer();
for (int i=0; i<4; i++)
{
*ptr1 = this->serialPort1->ReadChar();
ptr1++;
}
int address;
address = ((b[0]-48)*10)+(b[1]-48);
System::Windows::Forms::Label ^ ptr;
switch (address)
{
case 1: ptr = label1;
break;
case 2: ptr = label2;
break;
case 3: ptr = label3;
break;
case 4: ptr = label4;
break;
case 5: ptr = label5;
break;
case 6: ptr = label6;
break;
case 7: ptr = label7;
break;
case 8: ptr = label8;
break;
default: //MessageBox::Show("Default Case");
break;
}
if(b[2]=='o')
{
ptr->BackColor = Color::Red;
ptr->Text="R";
}
else if(b[2]=='a')
{
ptr->Text=String::Empty;
ptr->BackColor = Color::Green;
}
else if(b[2]=='i')
{
ptr->Text=String::Empty;
ptr->BackColor = Color::Blue;
}
if ((b[3]-48)<3)
{
ptr->Text=String::Empty;
ptr->BackColor = Color::SaddleBrown;
//_sleep(5000);
}
while(checkBox1->Checked)
{
if(this->serialPort1->IsOpen)
{
int b[4] = {0};
int *ptr1;
ptr1 = b;
//this->serialPort1->DiscardInBuffer();
for (int i=0; i<4; i++)
{
*ptr1 = this->serialPort1->ReadChar();
ptr1++;
}
int address;
address = ((b[0]-48)*10)+(b[1]-48);
System::Windows::Forms::Label ^ ptr;
switch (address)
{
case 1: ptr = label1;
break;
case 2: ptr = label2;
break;
case 3: ptr = label3;
break;
case 4: ptr = label4;
break;
case 5: ptr = label5;
break;
case 6: ptr = label6;
break;
case 7: ptr = label7;
break;
case 8: ptr = label8;
break;
default: //MessageBox::Show("Default Case");
break;
}
if(b[2]=='o')
{
ptr->BackColor = Color::Red;
ptr->Text="R";
}
else if(b[2]=='a')
{
ptr->Text=String::Empty;
ptr->BackColor = Color::Green;
}
else if(b[2]=='i')
{
ptr->Text=String::Empty;
ptr->BackColor = Color::Blue;
}
if ((b[3]-48)<3)
{
ptr->Text=String::Empty;
ptr->BackColor = Color::SaddleBrown;
//_sleep(5000);
}