private void cmd_Down_Click(object sender, System.Windows.RoutedEventArgs e) { using (var device = new SerialDevice(COMPortName.Text, 115200, System.IO.Ports.Parity.None, 8, System.IO.Ports.StopBits.One)) { var toSet = Math.Ceiling((double)((inputMovementVal.Value * 0.0000000001 / alpha()) * 1000.0 * 1526.0 * 3000.0 / 0.5)).ToString(NumberFormatInfo.InvariantInfo); device.SendCommandRequest("en"); device.SendCommandRequest(string.Format("lr-{0}", toSet)); device.SendCommandRequest("np"); device.SendCommandRequest("m"); while (!device.ReceiveDeviceAnswer().Contains('p')) { ; } //Thread.Sleep((int)(500.0 * inputMovementVal.Value)); device.SendCommandRequest("di"); } }