First of all, I'm pretty new to C++.
I'm writing a program to communicate with a device via the serial port.
Radio buttons are used to toggle the mode and the program is supposed to execute a loop until a radio button is changed. As soon as the button is pressed to toggle onto Pmode, the program crashes and nothing can be pressed.
I've been looking online and people with similar problems have suggested using Invoking but I don't really understand how to use this?
Here's the relevant bit of code: thanks for any advice
private: System::Void rbCMode_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
{
if(rbCMode->Checked)
{
String^ message = "Set_Mode_C";
mySerialPort->WriteLine(String::Format("{0}", message));
OKCheck();
}
else
{
String^ message = "Set_Mode_P";
mySerialPort->WriteLine(String::Format("{0}", message));
OKCheck();
}
while(rbPMode->Checked == true)
{
ReadAngles(xangle, yangle, x_angle_text, y_angle_text);
txtXDisplay->Text=x_angle_text;
txtYDisplay->Text=y_angle_text;
}
}
static void ReadAngles(double^ %xangle, double^ %yangle, String^ %x_angle_text, String^ %y_angle_text)
{
int databytes = mySerialPort->BytesToRead;
while (databytes < 19)
{
databytes = mySerialPort->BytesToRead;
}
String^ buffer = mySerialPort->ReadLine();
while (buffer->Length <= 5)
{
buffer = mySerialPort->ReadLine();
}
x_angle_text = buffer->Substring(2,6);
y_angle_text = buffer->Substring(11,6);
xangle = System::Convert::ToDouble(x_angle_text);
yangle = System::Convert::ToDouble(y_angle_text);
return;
}