My code is working perfectly fine except I don't believe it is optimal and is going work reliably for fast response or handle significan delays.
Is there a better way of doing this? I would like it to just only wait for the arrival of the first 8 byte data on the buffer and read and continue on to the next task?
Sleep (2000); serialPort1->;DiscardInBuffer(); serialPort1->;DiscardOutBuffer();
auto Power = gcnew array<System::Byte> {0x52, 0x0C, 0x01, 0x00, 0x00};
serialPort1->Write(Power, 0, Power->Length);
Sleep(500);
auto Power1 = gcnew array<System::Byte> {0x00, 0x00, 0x00, 0x00, 0x00};
serialPort1->Read(Power1, 0, Power1->;Length);
String^ str2 = String::Format("{0:X2} {1:X2} {2:X2} {3:X2} {4:X2}", Power1[0], Power1[1], Power1[2], Power1[3], Power1[4]);
String^ str3 = String::Format("{2:N0}", Power1[0], Power1[1]);
richTextBox1->Text += "Power Level -> ";
richTextBox1->Text += str3 + "Watts" "\r\n";