buffer[4]
buffer[5]
68 07 00 81 (00) (00) 98 20
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e) { // Obtain the number of bytes waiting in the port's buffer int bytes = serialPort1.BytesToRead; // Create a byte array buffer to hold the incoming data byte[] buffer = new byte[bytes]; // Read the data from the port and store it in our buffer // if (buffer.Length == 7 ) serialPort1.Read(buffer, 0, bytes); //bytes Log(LogMsgType.Incoming, ByteArrayToHexString(buffer)); // RxString = port.ReadLine(); // ArduinoData = RxString.Split(',', '\n', '\r'); // if (ArduinoData.Count() == 7) //ensures we have all data, plus line end ("\n" or "\r") if (buffer.Count() == bytes) { if (buffer[4] == 0) // <--- Problem PitchAngle = Convert.ToDouble(buffer[5]);//<--- Problem else PitchAngle = -1.0 * Convert.ToDouble(buffer[5]);//<--- Problem // RollAngle = -1.0 * Convert.ToDouble(buffer[5]) * Math.PI / 180;//<--- Problem // YawAngle = -1.0 * Convert.ToDouble(ArduinoData[6]) * Math.PI / 180; // if (YawAngle < -Math.PI) YawAngle = YawAngle + Math.PI; Invalidate(); } }
5
if (buffer.Count() == bytes)
buffer.Count() == 4
bytes == 4
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)