本文整理汇总了C#中MissionPlanner.Arduino.ArduinoSTK.Close方法的典型用法代码示例。如果您正苦于以下问题:C# ArduinoSTK.Close方法的具体用法?C# ArduinoSTK.Close怎么用?C# ArduinoSTK.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MissionPlanner.Arduino.ArduinoSTK
的用法示例。
在下文中一共展示了ArduinoSTK.Close方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BUT_copyto1280_Click
private void BUT_copyto1280_Click(object sender, EventArgs e)
{
IArduinoComms port = new ArduinoSTK();
port.BaudRate = 57600;
port.DataBits = 8;
port.StopBits = StopBits.One;
port.Parity = Parity.None;
port.DtrEnable = true;
StreamReader sr = new StreamReader(Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + @"EEPROM1280.bin");
BinaryReader br = new BinaryReader(sr.BaseStream);
byte[] EEPROM = br.ReadBytes(1024 * 4);
br.Close();
sr.Close();
sr = new StreamReader(Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + @"FLASH1280.bin");
br = new BinaryReader(sr.BaseStream);
byte[] FLASH = br.ReadBytes(1024 * 128);
br.Close();
sr.Close();
try
{
port.PortName = MissionPlanner.MainV2.comPortName;
port.Open();
if (port.connectAP())
{
log.Info("starting");
port.uploadflash(FLASH, 0, FLASH.Length, 0);
port.upload(EEPROM, 0, (short)EEPROM.Length, 0);
log.Info("Uploaded");
}
else
{
CustomMessageBox.Show("Communication Error - no connection");
}
port.Close();
}
catch (Exception ex) { CustomMessageBox.Show("Check port settings or Port in use? " + ex.ToString()); port.Close(); }
}
示例2: UploadFW
private void UploadFW(bool custom = false)
{
ArduinoSTK comPort = new ArduinoSTK();
uploader.Uploader uploader = new uploader.Uploader();
try
{
comPort.PortName = MainV2.comPort.BaseStream.PortName;
comPort.BaudRate = 115200;
comPort.Open();
}
catch { CustomMessageBox.Show("Invalid ComPort or in use"); return; }
bool bootloadermode = false;
// attempt bootloader mode
try
{
uploader_ProgressEvent(0);
uploader_LogEvent("Trying Bootloader Mode");
uploader.port = comPort;
uploader.connect_and_sync();
uploader.ProgressEvent += new ProgressEventHandler(uploader_ProgressEvent);
uploader.LogEvent += new LogEventHandler(uploader_LogEvent);
uploader_LogEvent("In Bootloader Mode");
bootloadermode = true;
}
catch
{
// cleanup bootloader mode fail, and try firmware mode
comPort.Close();
comPort.BaudRate = MainV2.comPort.BaseStream.BaudRate;
try
{
comPort.Open();
}
catch { CustomMessageBox.Show("Error opening port", "error"); return; }
uploader.ProgressEvent += new ProgressEventHandler(uploader_ProgressEvent);
uploader.LogEvent += new LogEventHandler(uploader_LogEvent);
uploader_LogEvent("Trying Firmware Mode");
bootloadermode = false;
}
// check for either already bootloadermode, or if we can do a ATI to ID the firmware
if (bootloadermode || doConnect(comPort))
{
uploader.IHex iHex = new uploader.IHex();
iHex.LogEvent += new LogEventHandler(iHex_LogEvent);
iHex.ProgressEvent += new ProgressEventHandler(iHex_ProgressEvent);
// put into bootloader mode/udpate mode
if (!bootloadermode)
{
try
{
comPort.Write("AT&UPDATE\r\n");
string left = comPort.ReadExisting();
log.Info(left);
Sleep(700);
comPort.BaudRate = 115200;
}
catch { }
}
global::uploader.Uploader.Board device = global::uploader.Uploader.Board.FAILED;
global::uploader.Uploader.Frequency freq = global::uploader.Uploader.Frequency.FAILED;
// get the device type and frequency in the bootloader
uploader.getDevice(ref device, ref freq);
// get firmware for this device
if (getFirmware(device, custom))
{
// load the hex
try
{
iHex.load(firmwarefile);
}
catch { CustomMessageBox.Show("Bad Firmware File"); goto exit; }
// upload the hex and verify
try
{
uploader.upload(comPort, iHex);
}
catch (Exception ex) { CustomMessageBox.Show("Upload Failed " + ex.Message); }
}
else
{
//.........这里部分代码省略.........
示例3: BUT_copy1280_Click
private void BUT_copy1280_Click(object sender, EventArgs e)
{
ArduinoSTK port = new ArduinoSTK();
port.BaudRate = 57600;
port.DataBits = 8;
port.StopBits = StopBits.One;
port.Parity = Parity.None;
port.DtrEnable = true;
try
{
port.PortName = MissionPlanner.MainV2.comPortName;
log.Info("Open Port");
port.Open();
log.Info("Connect AP");
if (port.connectAP())
{
log.Info("Download AP");
byte[] EEPROM = new byte[1024 * 4];
for (int a = 0; a < 4 * 1024; a += 0x100)
{
port.setaddress(a);
port.download(0x100).CopyTo(EEPROM, a);
}
log.Info("Verify State");
if (port.keepalive())
{
StreamWriter sw = new StreamWriter(Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + @"EEPROM1280.bin");
BinaryWriter bw = new BinaryWriter(sw.BaseStream);
bw.Write(EEPROM, 0, EEPROM.Length);
bw.Close();
log.Info("Download AP");
byte[] FLASH = new byte[1024 * 128];
for (int a = 0; a < FLASH.Length; a += 0x100)
{
port.setaddress(a);
port.downloadflash(0x100).CopyTo(FLASH, a);
}
sw = new StreamWriter(Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + @"FLASH1280.bin");
bw = new BinaryWriter(sw.BaseStream);
bw.Write(FLASH, 0, FLASH.Length);
bw.Close();
}
else
{
CustomMessageBox.Show("Communication Error - Bad data");
}
}
else
{
CustomMessageBox.Show("Communication Error - no connection");
}
port.Close();
}
catch (Exception ex) { CustomMessageBox.Show("Port Error? " + ex.ToString()); if (port != null && port.IsOpen) { port.Close(); } }
}