public virtual float GetValueFromUser(string message) { if (LConsole.IsActive) { LConsole.Write(message); var read = LConsole.ReadLine(); if (read.ToLower() == "exit" || read.ToLower() == "quit") { LConsole.SafeExit(); throw new Exception(); } try { return(Convert.ToSingle(read)); } catch { } return(0); } else { var askF = PhysLogger.Forms.AskFloat.ShowDialog(message, 0); if (askF.dr == System.Windows.Forms.DialogResult.OK) { return(askF.Value); } else { return(0); } } }
public virtual void UpdateFirmware(PhysLogger.Forms.PhysLoggerUpdaterConsole ucf, string comPort, string forcedSource) { if (forcedSource == "" || forcedSource == null) { throw new NotImplementedException(); } RequestDisconnect(); ucf.WriteLine("PhysLogger Update Console"); string fNameSeed = ""; string verString = ""; fNameSeed = System.IO.Path.Combine("firmware", System.IO.Path.GetFileNameWithoutExtension(forcedSource)); verString = System.IO.Path.GetFileNameWithoutExtension(fNameSeed); if (fNameSeed != "") { if (System.IO.File.Exists(forcedSource)) { ucf.WriteLine(); ucf.Write("You are about to update the PhysLogger firmare to "); ucf.Write(verString); ucf.WriteLine(". This will update the firmare on the PhysLogger hardware which might raise conflicts if not done properly."); ucf.WriteLine("If you are not sure what you are doing, you might want to quit it now.\r\n"); if (System.IO.File.Exists(fNameSeed + "_preInstall.txt")) { ucf.WriteLine(); ucf.Write(System.IO.File.ReadAllText(fNameSeed + "_preInstall.txt")); ucf.WriteLine(); } ucf.Write("\r\nDo you still want to continue with the update (Y/n)? "); if (ucf.ReadLine() != "Y") { return; } string root = System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) + "\\avrdude"; ArduinoSketchUploader.UploaderMain uploader = new ArduinoSketchUploader.UploaderMain(); uploader.OnProgressUpdate += delegate(string a) { ucf.Write(a); } ; for (int i = 1; i <= 3; i++) { if (uploader.Upload(fNameSeed + ".hex", ArduinoUploader.Hardware.ArduinoModel.Mega2560, comPort)) { break; } ucf.WriteLine("Upload failed. Retrying (" + i + "/3)..."); System.Threading.Thread.Sleep(3000); } return; //p.OutputDataReceived += (s, ea) => ucf.Write(ea.Data); } } ucf.WriteLine("The firmware update process has failed."); ucf.SafeExit(); }
public override void UpdateFirmware(PhysLogger.Forms.PhysLoggerUpdaterConsole ucf, string comPort, string forcedSource) { if (forcedSource != null) { if (forcedSource != "") { base.UpdateFirmware(ucf, comPort, forcedSource); return; } } RequestDisconnect(); ucf.WriteLine("PhysLogger Update Console"); string fNameSeed = ""; string verString = ""; double maxVer = -1; foreach (var file in System.IO.Directory.GetFiles("firmware", "PhysLoggerV1*.hex")) { try { string verS = System.IO.Path.GetFileNameWithoutExtension(file); verS = verS.Substring(11); double ver = double.Parse(verS); if (ver > maxVer) { maxVer = ver; } } catch { } } if (maxVer >= 0) { fNameSeed = "firmware\\PhysLoggerV" + maxVer; verString = maxVer.ToString(); } if (fNameSeed != "") { if (System.IO.File.Exists(fNameSeed + ".hex")) { ucf.WriteLine(); ucf.Write("You are about to update the PhysLogger firmare from v" + Signature + " to v"); ucf.Write(verString); ucf.WriteLine(". This will update the firmare on the PhysLogger hardware which might raise conflicts if not done properly."); ucf.WriteLine("If you are not sure what you are doing, you might want to quit it now.\r\n"); if (System.IO.File.Exists(fNameSeed + "_preInstall.txt")) { ucf.WriteLine(); ucf.Write(System.IO.File.ReadAllText(fNameSeed + "_preInstall.txt")); ucf.WriteLine(); } ucf.Write("\r\nDo you still want to continue with the update (Y/n)? "); if (ucf.ReadLine() != "Y") { return; } string root = System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) + "\\avrdude"; ArduinoSketchUploader.UploaderMain uploader = new ArduinoSketchUploader.UploaderMain(); uploader.OnProgressUpdate += delegate(string a) { ucf.Write(a); } ; for (int i = 1; i <= 3; i++) { if (uploader.Upload(fNameSeed + ".hex", ArduinoUploader.Hardware.ArduinoModel.Mega2560, comPort)) { break; } ucf.WriteLine("Upload failed. Retrying (" + i + "/3)..."); System.Threading.Thread.Sleep(3000); } return; //p.OutputDataReceived += (s, ea) => ucf.Write(ea.Data); } } }