本文整理汇总了C#中MissionPlanner.Comms.SerialPort.DiscardInBuffer方法的典型用法代码示例。如果您正苦于以下问题:C# SerialPort.DiscardInBuffer方法的具体用法?C# SerialPort.DiscardInBuffer怎么用?C# SerialPort.DiscardInBuffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MissionPlanner.Comms.SerialPort
的用法示例。
在下文中一共展示了SerialPort.DiscardInBuffer方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BUT_resettodefault_Click
private void BUT_resettodefault_Click(object sender, EventArgs e)
{
ICommsSerial comPort = new SerialPort();
try
{
comPort.PortName = MainV2.comPort.BaseStream.PortName;
comPort.BaudRate = MainV2.comPort.BaseStream.BaudRate;
comPort.ReadTimeout = 4000;
comPort.Open();
}
catch { CustomMessageBox.Show("Invalid ComPort or in use"); return; }
lbl_status.Text = "Connecting";
if (doConnect(comPort))
{
// cleanup
doCommand(comPort, "AT&T");
comPort.DiscardInBuffer();
lbl_status.Text = "Doing Command ATI & AT&F";
doCommand(comPort, "AT&F");
doCommand(comPort, "AT&W");
lbl_status.Text = "Reset";
doCommand(comPort, "ATZ");
comPort.Close();
BUT_getcurrent_Click(sender, e);
}
else
{
// off hook
doCommand(comPort, "ATO");
lbl_status.Text = "Fail";
CustomMessageBox.Show("Failed to enter command mode");
}
if (comPort.IsOpen)
comPort.Close();
}
示例2: BUT_savesettings_Click
private void BUT_savesettings_Click(object sender, EventArgs e)
{
ICommsSerial comPort = new SerialPort();
try
{
comPort.PortName = MainV2.comPort.BaseStream.PortName;
comPort.BaudRate = MainV2.comPort.BaseStream.BaudRate;
comPort.ReadTimeout = 4000;
comPort.Open();
}
catch { CustomMessageBox.Show("Invalid ComPort or in use"); return; }
lbl_status.Text = "Connecting";
if (doConnect(comPort))
{
// cleanup
doCommand(comPort, "AT&T");
comPort.DiscardInBuffer();
lbl_status.Text = "Doing Command";
if (RTI.Text != "")
{
// remote
string answer = doCommand(comPort, "RTI5");
string[] items = answer.Split('\n');
foreach (string item in items)
{
if (item.StartsWith("S"))
{
string[] values = item.Split(':', '=');
if (values.Length == 3)
{
Control[] controls = this.Controls.Find("R" + values[0].Trim(), true);
if (controls.Length > 0)
{
if (controls[0].GetType() == typeof(CheckBox))
{
string value = ((CheckBox)controls[0]).Checked ? "1" : "0";
if (value != values[2].Trim())
{
string cmdanswer = doCommand(comPort, "RT" + values[0].Trim() + "=" + value + "\r");
if (cmdanswer.Contains("OK"))
{
}
else
{
CustomMessageBox.Show("Set Command error");
}
}
}
else
{
if (controls[0] is TextBox)
{
}
else
{
if (((ComboBox)controls[0]).SelectedValue != null)
{
if (((ComboBox)controls[0]).SelectedValue.ToString() != values[2].Trim())
{
string cmdanswer = doCommand(comPort, "RT" + values[0].Trim() + "=" + ((ComboBox)controls[0]).SelectedValue + "\r");
if (cmdanswer.Contains("OK"))
{
}
else
{
CustomMessageBox.Show("Set Command error");
}
}
}
else if (controls[0].Text != values[2].Trim() && controls[0].Text != "")
{
string cmdanswer = doCommand(comPort, "RT" + values[0].Trim() + "=" + controls[0].Text + "\r");
if (cmdanswer.Contains("OK"))
{
}
else
{
CustomMessageBox.Show("Set Command error");
//.........这里部分代码省略.........
示例3: BUT_getcurrent_Click
private void BUT_getcurrent_Click(object sender, EventArgs e)
{
ICommsSerial comPort = new SerialPort();
try
{
comPort.PortName = MainV2.comPort.BaseStream.PortName;
comPort.BaudRate = MainV2.comPort.BaseStream.BaudRate;
comPort.ReadTimeout = 4000;
comPort.Open();
}
catch { CustomMessageBox.Show("Invalid ComPort or in use"); return; }
lbl_status.Text = "Connecting";
if (doConnect(comPort))
{
// cleanup
doCommand(comPort, "AT&T");
comPort.DiscardInBuffer();
lbl_status.Text = "Doing Command ATI & RTI";
ATI.Text = doCommand(comPort, "ATI");
RTI.Text = doCommand(comPort, "RTI");
uploader.Uploader.Frequency freq = (uploader.Uploader.Frequency)Enum.Parse(typeof(uploader.Uploader.Frequency), doCommand(comPort, "ATI3"));
uploader.Uploader.Board board = (uploader.Uploader.Board)Enum.Parse(typeof(uploader.Uploader.Board), doCommand(comPort, "ATI2"));
ATI3.Text = freq.ToString();
ATI2.Text = board.ToString();
try
{
RTI2.Text = ((uploader.Uploader.Board)Enum.Parse(typeof(uploader.Uploader.Board), doCommand(comPort, "RTI2"))).ToString();
}
catch { }
// 8 and 9
if (freq == uploader.Uploader.Frequency.FREQ_915)
{
S8.DataSource = Range(895000, 1000, 935000);
RS8.DataSource = Range(895000, 1000, 935000);
S9.DataSource = Range(895000, 1000, 935000);
RS9.DataSource = Range(895000, 1000, 935000);
}
else if (freq == uploader.Uploader.Frequency.FREQ_433)
{
S8.DataSource = Range(414000, 100, 454000);
RS8.DataSource = Range(414000, 100, 454000);
S9.DataSource = Range(414000, 100, 454000);
RS9.DataSource = Range(414000, 100, 454000);
}
else if (freq == uploader.Uploader.Frequency.FREQ_868)
{
S8.DataSource = Range(849000, 1000, 889000);
RS8.DataSource = Range(849000, 1000, 889000);
S9.DataSource = Range(849000, 1000, 889000);
RS9.DataSource = Range(849000, 1000, 889000);
}
if (board == uploader.Uploader.Board.DEVICE_ID_RFD900 || board == uploader.Uploader.Board.DEVICE_ID_RFD900A)
{
S4.DataSource = Range(1, 1, 30);
RS4.DataSource = Range(1, 1, 30);
}
RSSI.Text = doCommand(comPort, "ATI7").Trim();
lbl_status.Text = "Doing Command ATI5";
string answer = doCommand(comPort, "ATI5");
string[] items = answer.Split('\n');
foreach (string item in items)
{
if (item.StartsWith("S"))
{
string[] values = item.Split(':', '=');
if (values.Length == 3)
{
Control[] controls = this.Controls.Find(values[0].Trim(), true);
if (controls.Length > 0)
{
controls[0].Enabled = true;
if (controls[0] is CheckBox)
{
((CheckBox)controls[0]).Checked = values[2].Trim() == "1";
}
//.........这里部分代码省略.........
示例4: DetectBoard
//.........这里部分代码省略.........
{
return boards.b2560v2;
}
else
{
if (DialogResult.Yes == CustomMessageBox.Show("Is this a PX4/PIXHAWK?", "PX4/PIXHAWK", MessageBoxButtons.YesNo))
{
if (DialogResult.Yes == CustomMessageBox.Show("Is this a PIXHAWK?", "PIXHAWK", MessageBoxButtons.YesNo))
{
return boards.px4v2;
}
return boards.px4;
}
else
{
return boards.b2560;
}
}
}
if (serialPort.IsOpen)
serialPort.Close();
serialPort.DtrEnable = true;
serialPort.BaudRate = 57600;
serialPort.Open();
Thread.Sleep(100);
int a = 0;
while (a < 20) // 20 * 50 = 1 sec
{
//Console.WriteLine("write " + DateTime.Now.Millisecond);
serialPort.DiscardInBuffer();
serialPort.Write(new byte[] { (byte)'0', (byte)' ' }, 0, 2);
a++;
Thread.Sleep(50);
//Console.WriteLine("btr {0}", serialPort.BytesToRead);
if (serialPort.BytesToRead >= 2)
{
byte b1 = (byte)serialPort.ReadByte();
byte b2 = (byte)serialPort.ReadByte();
if (b1 == 0x14 && b2 == 0x10)
{
serialPort.Close();
log.Info("is a 1280");
return boards.b1280;
}
}
}
serialPort.Close();
log.Warn("Not a 1280");
Thread.Sleep(500);
serialPort.DtrEnable = true;
serialPort.BaudRate = 115200;
serialPort.Open();
Thread.Sleep(100);
a = 0;
while (a < 4)
示例5: BUT_getcurrent_Click
private void BUT_getcurrent_Click(object sender, EventArgs e)
{
ICommsSerial comPort = new SerialPort();
try
{
if (MainV2.comPort.BaseStream.IsOpen)
{
getTelemPortWithRadio(ref comPort);
}
else
{
comPort.PortName = MainV2.comPort.BaseStream.PortName;
comPort.BaudRate = MainV2.comPort.BaseStream.BaudRate;
}
comPort.ReadTimeout = 4000;
comPort.Open();
}
catch
{
CustomMessageBox.Show("Invalid ComPort or in use");
return;
}
lbl_status.Text = "Connecting";
try
{
if (doConnect(comPort))
{
// cleanup
doCommand(comPort, "AT&T");
comPort.DiscardInBuffer();
lbl_status.Text = "Doing Command ATI & RTI";
ATI.Text = doCommand(comPort, "ATI");
var freq =
(Uploader.Frequency)
Enum.Parse(typeof (Uploader.Frequency), doCommand(comPort, "ATI3"));
var board =
(Uploader.Board)
Enum.Parse(typeof (Uploader.Board), doCommand(comPort, "ATI2"));
ATI3.Text = freq.ToString();
ATI2.Text = board.ToString();
// 8 and 9
if (freq == Uploader.Frequency.FREQ_915)
{
MIN_FREQ.DataSource = Range(895000, 1000, 935000);
RMIN_FREQ.DataSource = Range(895000, 1000, 935000);
MAX_FREQ.DataSource = Range(895000, 1000, 935000);
RMAX_FREQ.DataSource = Range(895000, 1000, 935000);
}
else if (freq == Uploader.Frequency.FREQ_433)
{
MIN_FREQ.DataSource = Range(414000, 50, 460000);
RMIN_FREQ.DataSource = Range(414000, 50, 460000);
MAX_FREQ.DataSource = Range(414000, 50, 460000);
RMAX_FREQ.DataSource = Range(414000, 50, 460000);
}
else if (freq == Uploader.Frequency.FREQ_868)
{
MIN_FREQ.DataSource = Range(849000, 1000, 889000);
RMIN_FREQ.DataSource = Range(849000, 1000, 889000);
MAX_FREQ.DataSource = Range(849000, 1000, 889000);
RMAX_FREQ.DataSource = Range(849000, 1000, 889000);
}
if (board == Uploader.Board.DEVICE_ID_RFD900 ||
board == Uploader.Board.DEVICE_ID_RFD900A
|| board == Uploader.Board.DEVICE_ID_RFD900P ||
board == Uploader.Board.DEVICE_ID_RFD900U ||
board == Uploader.Board.DEVICE_ID_RFD900Plus)
{
TXPOWER.DataSource = Range(1, 1, 30);
RTXPOWER.DataSource = Range(1, 1, 30);
}
txt_aeskey.Text = doCommand(comPort, "AT&E?").Trim();
RSSI.Text = doCommand(comPort, "ATI7").Trim();
lbl_status.Text = "Doing Command ATI5";
var answer = doCommand(comPort, "ATI5", true);
var items = answer.Split('\n');
foreach (var item in items)
{
//.........这里部分代码省略.........
示例6: BUT_savesettings_Click
private void BUT_savesettings_Click(object sender, EventArgs e)
{
ICommsSerial comPort = new SerialPort();
try
{
if (MainV2.comPort.BaseStream.IsOpen)
{
getTelemPortWithRadio(ref comPort);
}
else
{
comPort.PortName = MainV2.comPort.BaseStream.PortName;
comPort.BaudRate = MainV2.comPort.BaseStream.BaudRate;
}
comPort.ReadTimeout = 4000;
comPort.Open();
}
catch
{
CustomMessageBox.Show("Invalid ComPort or in use");
return;
}
lbl_status.Text = "Connecting";
if (doConnect(comPort))
{
// cleanup
doCommand(comPort, "AT&T");
comPort.DiscardInBuffer();
lbl_status.Text = "Doing Command";
// set encryption keys at the same time, so if we are enabled we dont lose comms.
if (RENCRYPTION_LEVEL.Checked)
{
doCommand(comPort, "RT&E=" + txt_Raeskey.Text.PadRight(32, '0'), true);
}
if (ENCRYPTION_LEVEL.Checked)
{
doCommand(comPort, "AT&E=" + txt_aeskey.Text.PadRight(32, '0'), true);
}
if (RTI.Text != "")
{
// remote
var answer = doCommand(comPort, "RTI5", true);
var items = answer.Split(new[] {'\n'}, StringSplitOptions.RemoveEmptyEntries);
foreach (var item in items)
{
if (item.StartsWith("S"))
{
var values = item.Split(':', '=');
if (values.Length == 3)
{
values[1] = values[1].Replace("/", "_");
var controls = groupBoxRemote.Controls.Find("R" + values[1].Trim(), true);
if (controls.Length > 0)
{
if (controls[0].GetType() == typeof (CheckBox))
{
var value = ((CheckBox) controls[0]).Checked ? "1" : "0";
if (value != values[2].Trim())
{
var cmdanswer = doCommand(comPort,
"RT" + values[0].Trim() + "=" + value + "\r");
if (cmdanswer.Contains("OK"))
{
}
else
{
CustomMessageBox.Show("Set Command error");
}
}
}
else if (controls[0] is TextBox)
{
}
else if (controls[0].Name.Contains("MAVLINK")) //
{
if (((ComboBox) controls[0]).SelectedValue.ToString() != values[2].Trim())
{
var cmdanswer = doCommand(comPort,
"RT" + values[0].Trim() + "=" + ((ComboBox) controls[0]).SelectedValue +
"\r");
if (cmdanswer.Contains("OK"))
{
}
//.........这里部分代码省略.........
示例7: DetectVersion
/// <summary>
/// detects STK version 1 or 2
/// </summary>
/// <param name="port">comportname</param>
/// <returns>string either (1280/2560) or "" for none</returns>
public static string DetectVersion(string port)
{
SerialPort serialPort = new SerialPort();
serialPort.PortName = port;
if (serialPort.IsOpen)
serialPort.Close();
serialPort.DtrEnable = true;
serialPort.BaudRate = 57600;
serialPort.Open();
serialPort.toggleDTR();
Thread.Sleep(100);
int a = 0;
while (a < 20) // 20 * 50 = 1 sec
{
//Console.WriteLine("write " + DateTime.Now.Millisecond);
serialPort.DiscardInBuffer();
serialPort.Write(new byte[] { (byte)'0', (byte)' ' }, 0, 2);
a++;
Thread.Sleep(50);
//Console.WriteLine("btr {0}", serialPort.BytesToRead);
if (serialPort.BytesToRead >= 2)
{
byte b1 = (byte)serialPort.ReadByte();
byte b2 = (byte)serialPort.ReadByte();
if (b1 == 0x14 && b2 == 0x10)
{
serialPort.Close();
log.Info("is a 1280");
return "1280";
}
}
}
serialPort.Close();
log.Warn("Not a 1280");
Thread.Sleep(500);
serialPort.DtrEnable = true;
serialPort.BaudRate = 115200;
serialPort.Open();
serialPort.toggleDTR();
Thread.Sleep(100);
a = 0;
while (a < 4)
{
byte[] temp = new byte[] { 0x6, 0, 0, 0, 0 };
temp = ArduinoDetect.genstkv2packet(serialPort, temp);
a++;
Thread.Sleep(50);
try
{
if (temp[0] == 6 && temp[1] == 0 && temp.Length == 2)
{
serialPort.Close();
log.Info("is a 2560");
return "2560";
}
}
catch
{
}
}
serialPort.Close();
log.Warn("Not a 2560");
return "";
}