protected USB2LCD.VersionInfo GetCOMVersion(string port)
 {
     COM c = null;
     USB2LCD.VersionInfo v = new USB2LCD.VersionInfo();
     try
     {
         c = new COM(port, 9600);
         v.version = c.ReadByte(USB2LCD.Command.ReadVersion);
         v.module = c.ReadByte(USB2LCD.Command.ReadModuleType);
         v.serialnumber = c.ReadShort(USB2LCD.Command.ReadSerialNum);;
         c.Close();
     }
     catch (COMException ex)
     {
         ex.Show(this);
     }
     catch (Exception ex)
     {
         MessageBox.Show(this, "The COM port caused an error:\n"+ex.Message, "COM Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     finally
     {
         if (c != null) c.Close();
     }
     return v;
 }
Exemple #2
0
 protected USB2LCD.VersionInfo GetVersion()
 {
     COM c = null;
     USB2LCD.VersionInfo v = new USB2LCD.VersionInfo();
     try
     {
         c = new COM(port, Baud);
         v.version      = c.ReadByte(USB2LCD.Command.ReadVersion);
         v.module       = c.ReadByte(USB2LCD.Command.ReadModuleType);
         v.serialnumber = c.ReadShort(USB2LCD.Command.ReadSerialNum);
         c.Close();
     }
     catch (COMException ex)
     {
         ex.Show(this);
     }
     catch (Exception ex)
     {
         ShowErrorMessage("The COM port caused an error:\n"+ex.Message, "COM Error");
     }
     finally
     {
         if (c != null) { c.Close(); }
     }
     return v;
 }
Exemple #3
0
        private void UpdateFirmware()
        {
            int retval;

            // get the HEX file to use
            if (ShowFileDialog() == DialogResult.OK)
            {
                retval = USB2LCD.CheckHEXfile(openFileDialog.FileName);
                if (retval < 0)
                {
                    ShowErrorMessage("The selected file could not be read / parsed: "+retval, "File Error");
                    EnableForm(true);
                    return;
                }
            }
            else
            {
                EnableForm(true);
                return;
            }

            this.BeginInvoke(new Func<DialogResult, IWin32Window, string, string>(ProgressDialog.ShowModal), this, "Firmware Update", "Please wait while the device resets...");

            int[] ids = USB2LCD.GetBootloaderIds();
            ushort serial;
            bool unique = true;

            COM c = null;
            try
            {
                c = new COM(port, Baud);
                serial = c.ReadShort(USB2LCD.Command.ReadSerialNum);
                for (int i = 0; i < ids.Length && unique; i++)
                    unique = USB2LCD.GetBootloaderVersion(ids[i]).serialnumber != serial;
                c.SendCmd(USB2LCD.Command.Firmware);
            }
            catch (COMException ex)
            {
                ProgressDialog.CloseForm();
                ex.Show(this);
                EnableForm(true);
                return;
            }
            catch (Exception ex)
            {
                ProgressDialog.CloseForm();
                ShowErrorMessage("There was an error:\n"+ex.Message, "Error");
                EnableForm(true);
                return;
            }
            finally
            {
                if (c != null) { c.Close(); }
            }

            Thread.Sleep(2000); // takes about 3 seconds, so we might as well just not even check for a little bit

            // We keep checking the attached devices until a bootloader device shows up that wasn't there before
            int[] new_ids;
            int id = -1;
            int tries_left = 114; // about 30 seconds max of waiting
            do
            {
                Thread.Sleep(250);
                new_ids = USB2LCD.GetBootloaderIds();
            } while (((id = findDifference(unique, serial, ids, new_ids)) == -1) && (--tries_left > 0));

            if (id == -1)
            {
                ProgressDialog.CloseForm();
                ShowErrorMessage("The device never showed up after resetting. Try to unplug it, close LCD Setter, plug it back in again, and start LCD Setter again.","Firmware Update Problem");
                EnableForm(true);
                return;
            }

            ProgressDialog.SetText("Updating firmware...");
            ProgressDialog.SetProgressStyle(false);
            retval = USB2LCD.UpdateFirmware(id, openFileDialog.FileName, ProgressDialog.SetProgress);
            ProgressDialog.CloseForm();
            if (retval != USB2LCD.SUCCESS)
                ShowErrorMessage("The firmware failed to update (error: "+retval+").\nTry to unplug the device, close LCD Setter, plug the device back in again, and start LCD Setter again.","Firmware Update Problem");
            else
                ShowMessage("The firmware was successfully updated.\n\nYou must unplug the device and plug it back in to complete the update.\n\nSome saved settings may have changed during this process.","Firmware Updated Successfully",MessageBoxIcon.None);
            EnableForm(true);
        }
Exemple #4
0
 private void SetSerial()
 {
     COM c = null;
     try
     {
         c = new COM(port, Baud);
         ushort cur = c.ReadShort(USB2LCD.Command.ReadSerialNum);
         //string str = Microsoft.VisualBasic.Interaction.InputBox("Enter 4 hex digits for the ID:", "Set ID", cur.ToString("X4"), -1, -1).Trim(); // TODO: remove Microsoft-specific usage
         //if (str.Length == 0)
         //    return;
         //ushort serial = Convert.ToUInt16(str, 16);
         //c.SendCmd(USB2LCD.Command.SetSerialNum, serial);
     }
     catch (COMException ex)
     {
         ex.Show(this);
     }
     catch (Exception ex)
     {
         ShowErrorMessage("There was an error:\n"+ex.Message, "Error");
     }
     finally
     {
         if (c != null) { c.Close(); }
         EnableForm(true);
     }
     UpdateVersionInfo();
 }