private void VerifyACK() { if (this.InvokeRequired) { SetTextCallback d = new SetTextCallback(VerifyACK); this.Invoke(d, new object[] { }); } else { SerialPortTerminal.AppendText(BitConverter.ToString(receiveBuffer) + "\n"); if ((receiveBuffer[0] == stx) & (receiveBuffer[1] == ack[1]) & (receiveBuffer[2] == etx)) { timer1.Enabled = false; } else { serialPort.DiscardInBuffer(); } } }
private void ProcessData() { if (this.InvokeRequired) { SetTextCallback d = new SetTextCallback(ProcessData); this.Invoke(d, new object[] { }); } else { SerialPortTerminal.AppendText(BitConverter.ToString(receiveBuffer) + "\n"); time += 0.025; if (VerifyFrame(receiveBuffer)) { currentPosition = BitConverter.ToDouble(receiveBuffer, 1); currentSpeed = BitConverter.ToDouble(receiveBuffer, 9); positionGraphControl.UpdateGraph(PositionGraph, 1, time, currentPosition, graphMode); speedGraphControl.UpdateGraph(SpeedGraph, 1, time, currentSpeed, graphMode); if (PositionRadioButton.Checked) { dataTable.Rows.Add(time, "Position", positionSetpoint, currentPosition, currentSpeed); positionGraphControl.UpdateGraph(PositionGraph, 0, time, positionSetpoint, graphMode); } if (SpeedRadioButton.Checked) { dataTable.Rows.Add(time, "Speed", speedSetpoint, currentPosition, currentSpeed); speedGraphControl.UpdateGraph(SpeedGraph, 0, time, speedSetpoint, graphMode); } PowerTextBox.Text = Convert.ToString(Math.Round(BitConverter.ToDouble(receiveBuffer, 17), 2)) + "%"; CurrentPositionTextBox.Text = Convert.ToString(currentPosition); CurrentSpeedTextBox.Text = Convert.ToString(currentSpeed); //serialPort.Write(ack, 0, 3); //SerialPortTerminal.AppendText(BitConverter.ToString(ack) + "\n"); } else { serialPort.DiscardInBuffer(); } } }