Example #1
0
        private bool Connect()
        {
            if (!_arduinoComm.Init(_selectedComPort.ComPort, ArduinoCommunication.DEFAULT_BAUDRATE, ArduinoCommunication.DEFAULT_TIMEOUT, true))
            {
                _logging.Error(MODUL_NAME, "ConnectBtn_Click", $"error connecting to Arduino");
                Helper.ControlInvokeRequired(FlasherVersionTb, () =>
                {
                    FlasherVersionTb.Text = "Error connecting to arduino";
                });
                return(false);
            }

            int majorVersion = 0;
            int minorVersion = 0;
            int apiVersion   = 0;

            SketchVersion.ArduinoType arduinoType;
            _currentSketchVersion = null;

            Debug.WriteLine("GetArduinoSketchVersion");
            if (!_arduinoComm.GetArduinoSketchVersion(out majorVersion, out minorVersion, out apiVersion, out arduinoType))
            {
                _logging.Error(MODUL_NAME, "ConnectBtn_Click", $"error reading Arduino sketch version");
                Helper.ControlInvokeRequired(FlasherVersionTb, () =>
                {
                    FlasherVersionTb.Text = "Error reading Arduino sketch version";
                });
                return(false);
            }

            _currentSketchVersion = new SketchVersion(majorVersion, minorVersion, apiVersion, arduinoType);

            Helper.ControlInvokeRequired(FlasherVersionTb, () =>
            {
                FlasherVersionTb.Text =
                    $"Arduino: Version={majorVersion}.{minorVersion}, " +
                    $"API-Version={apiVersion}, " +
                    $"Type={SketchVersion.ArduinoTypeToName(arduinoType)}";
            });

            Debug.WriteLine("GetTapecartInfo");
            _tapecartInfo = _arduinoComm.GetTapecartInfo();
            if (_tapecartInfo == null)
            {
                _logging.Error(MODUL_NAME, "ConnectBtn_Click", $"error reading tapecart info");
                Helper.ControlInvokeRequired(TapecartVersionTb, () =>
                {
                    TapecartVersionTb.Text = "Error reading Tapecart info";
                });
                return(true);
            }

            Helper.ControlInvokeRequired(TapecartVersionTb, () =>
            {
                TapecartVersionTb.Text =
                    $"Name={_tapecartInfo.TCrtName}, TotalSize={_tapecartInfo.TotalSize:X6}h, " +
                    $"PageSize={_tapecartInfo.PageSize:X}h, ErasePages={_tapecartInfo.ErasePages:X}h";
            });
            return(true);
        }
Example #2
0
        private async void ConnectBtn_Click(object sender, EventArgs e)
        {
            if (_selectedComPort == null)
            {
                return;
            }

            _logging.Info(MODUL_NAME, "ConnectBtn_Click", $"Connecting to {_arduinoComm.CurrentParameter}");

            FlasherVersionTb.Text  = "";
            TapecartVersionTb.Text = "";

            if (_arduinoComm.Connected)
            {
                _arduinoComm.DeInit();
                ConnectBtn.Text      = "Connect";
                ConnectBtn.ForeColor = Color.Black;
                SetButtonStatus();
                DetectBtn.Enabled  = true;
                ConnectBtn.Enabled = true;
                return;
            }

            DetectBtn.Enabled  = false;
            ConnectBtn.Enabled = false;

            string btnText = ConnectBtn.Text;

            ConnectBtn.Text      = "Connecting...";
            ConnectStateLbl.Text = "";
            ConnectBtn.Refresh();

            bool success = false;
            await Task.Run(() => {
                success = Connect();
            });

            if (success)
            {
                _logging.Info(MODUL_NAME, "ConnectBtn_Click", $"Connected");
            }
            else
            {
                _arduinoComm.DeInit();
            }

            SetButtonStatus();

            SketchVersion latest = _sketchList.GetLatestVersion(_currentSketchVersion);

            if (latest != null)
            {
                AskForSketchUpdate(latest);
            }
        }
Example #3
0
        public void ReadSketchList()
        {
            string exePath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

            //string exePath = Application.StartupPath;

            SketchVersions = new List <SketchVersion>();

            DirectoryInfo dirInfo = new DirectoryInfo(exePath);

            FileInfo[] files = dirInfo.GetFiles("TapecartFlasher*.hex");

            foreach (FileInfo file in files)
            {
                string[] list = Path.GetFileNameWithoutExtension(file.Name).Split('_');
                if (list.Length != 5)
                {
                    continue;
                }

                SketchVersion.ArduinoType arduinoType = SketchVersion.ArduinoNameToType(list[1]);
                if (arduinoType == SketchVersion.ArduinoType.None)
                {
                    continue;                     // invalid arduino type
                }
                int majorVersion;
                if (!int.TryParse(list[2], out majorVersion))
                {
                    continue;                     // invalid major version
                }
                int minorVersion;
                if (!int.TryParse(list[3], out minorVersion))
                {
                    continue;                     // invalid major version
                }
                int apiVersion;
                if (!int.TryParse(list[4], out apiVersion))
                {
                    continue;                     // invalid major version
                }
                SketchVersion version = new SketchVersion(majorVersion, minorVersion, apiVersion, arduinoType);
                version.Filename = file.Name;

                SketchVersions.Add(version);

                SketchVersions.Sort(delegate(SketchVersion x, SketchVersion y)
                {
                    return(x.SortCompareTo(y));
                });
            }
        }
Example #4
0
        public UpdateView(Rectangle position, string msg, string comPortName, SketchVersion oldVersion)
        {
            _parentWindowsPosition = position;

            InitializeComponent();

            _sketchList.ReadSketchList();
            _latestVersion = _sketchList.GetLatestVersion(oldVersion);

            MessageLbl.Text = "";

            if (oldVersion != null)
            {
                OldVersion.Text = $"{oldVersion.DisplayName} Tapecart Flasher v{oldVersion.VerStr}";
            }
            else
            {
                OldVersion.Text = "---";
            }

            if (_latestVersion != null)
            {
                NewVersion.Text = $"{_latestVersion.DisplayName} Tapecart Flasher v{_latestVersion.VerStr}";
            }
            else
            {
                NewVersion.Text = "---";
                _latestVersion  = _sketchList.GetLatestVersion(oldVersion, true);
            }

            UpdateProgress(0.0);

            // die Zuweisung an DataSource löst SelectedIndexChanged aus und überschreibt _latestVersion
            // work around:
            BoardTypeCb.Items.Clear();
            foreach (SketchVersion f in _sketchList.SketchVersions)
            {
                BoardTypeCb.Items.Add(f);
            }

            BoardTypeCb.SelectedItem  = _latestVersion;
            BoardTypeCb.DisplayMember = "DisplayName";
            if (oldVersion != null)
            {
                BoardTypeCb.Enabled = false;
            }

            _comPortName = comPortName;
        }
Example #5
0
        private void AskForSketchUpdate(SketchVersion latest)
        {
            _logging.Info(MODUL_NAME, "AskForSketchUpdate", $"current={_currentSketchVersion} latest={latest}");

            DialogResult terms = MessageBox.Show(
                "The Arduiono Tapecart Flasher Version does not match the current Version.\r\n" +
                $"Do you want to update from version {_currentSketchVersion.VerStr} to {latest.VerStr}?",
                "Arduino Flasher Update?",
                MessageBoxButtons.YesNo,
                MessageBoxIcon.Warning,
                MessageBoxDefaultButton.Button2);

            if (terms == DialogResult.Yes)
            {
                UpdateSketch();
            }
        }
Example #6
0
        public int SortCompareTo(SketchVersion version)
        {
            // 1. board type
            if (Type != version.Type)
            {
                return(((int)Type).CompareTo((int)version.Type));
            }

            // 2. major version
            if (Major != version.Major)
            {
                return(Major.CompareTo(version.Major));
            }

            // 3. minor version
            return(Minor.CompareTo(version.Minor));
        }
Example #7
0
        public SketchVersion GetLatestVersion(SketchVersion version, bool noVersionCheck = false)
        {
            if (version == null)
            {
                return(null);
            }

            // get the version for the same arduino type
            SketchVersion latest = (from f in SketchVersions where f.Type == version.Type select f).FirstOrDefault();

            if (latest == null)
            {
                return(null);
            }
            if (noVersionCheck || latest.IsHigherAs(version))
            {
                return(latest);
            }
            return(null);
        }
Example #8
0
        public bool IsHigherAs(SketchVersion version)
        {
            if (version.Type != Type)
            {
                return(false);                // different type, can not be compared
            }
            if (Major > version.Major)
            {
                return(true);
            }
            if (Api > version.Api)
            {
                return(true);
            }
            if (Major == version.Major && Minor > version.Minor)
            {
                return(true);
            }

            return(false);
        }
Example #9
0
 public bool Equals(SketchVersion version)
 {
     return(Major == version.Major && Minor == version.Minor && Api == version.Api);
 }
Example #10
0
        private void UploadSketch()
        {
            ArduinoProgress progress = new ArduinoProgress(UpdateProgress);

            ArduinoModel?model = SketchVersion.ArduinoTypeToModel(_latestVersion.Type);

            if (model == null)
            {
                _logging.Error(MODUL_NAME, "UploadSketch", $"invalid arduino type {_latestVersion.Type}");
                return;
            }

            var uploader = new ArduinoSketchUploader(
                new ArduinoSketchUploaderOptions()
            {
                FileName     = _latestVersion.Filename,
                PortName     = _comPortName,
                ArduinoModel = model.Value,
            },
                new ArduinoLogger(),
                progress
                );

            /*
             * string hexStr = Helper.GetEmbeddedTextRessource(LatestSketchName);
             * if (string.IsNullOrEmpty(hexStr))
             * {
             *      _logging.Error(MODUL_NAME, "UploadSketch", $"Error reading embedded resource '{LatestSketchName}'");
             *      return;
             * }
             * string[] hexLines = hexStr.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
             */

            Helper.ControlInvokeRequired(StatusLbl, () => {
                StatusLbl.Text = "Uploading Sketch";
            });

            Helper.ControlInvokeRequired(UploadPb, () => {
                UploadPb.Minimum = 0;
                UploadPb.Maximum = 100;
                UploadPb.Step    = 1;
                UploadPb.Value   = 0;
            });

            try {
                //uploader.UploadSketch(hexLines);
                uploader.UploadSketch();
            }
            catch (Exception ex) {
                _logging.Error(MODUL_NAME, "UploadSketch", $"UploadSketch error ex={ex}");
                Helper.ControlInvokeRequired(StatusLbl, () => {
                    StatusLbl.Text = "Sketch upload error";
                });
                return;
            }

            UpdateProgress(1.0);
            Helper.ControlInvokeRequired(StatusLbl, () => {
                StatusLbl.Text = "Sketch upload completed";
            });
        }
Example #11
0
 private void BoardTypeCb_SelectedIndexChanged(object sender, EventArgs e)
 {
     _latestVersion  = (SketchVersion)BoardTypeCb.SelectedItem;
     NewVersion.Text = $"{_latestVersion.DisplayName} Tapecart Flasher v{_latestVersion.VerStr}";
 }