本文整理汇总了C#中MissionPlanner.Comms.SerialPort.toggleDTR方法的典型用法代码示例。如果您正苦于以下问题:C# SerialPort.toggleDTR方法的具体用法?C# SerialPort.toggleDTR怎么用?C# SerialPort.toggleDTR使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MissionPlanner.Comms.SerialPort
的用法示例。
在下文中一共展示了SerialPort.toggleDTR方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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 "";
}