Пример #1
0
 private void Clear()
 {
     COM c = null;
     try
     {
         c = new COM(port, Baud);
         c.SendCmd(USB2LCD.Command.ClearDisplay);
     }
     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);
     }
 }
Пример #2
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);
        }
Пример #3
0
 private void SetCur()
 {
     Control.CheckForIllegalCrossThreadCalls = false;
     COM c = null;
     try
     {
         c = new COM(port, Baud);
         if (checkDisplay.Checked)
             c.SendCmd(USB2LCD.Command.DisplayOn, radioOnAlways.Checked ? (byte)0 : (byte)numericOnFor.Value);
         else
             c.SendCmd(USB2LCD.Command.DisplayOff);
         c.SendCmd(checkBlink.Checked	? USB2LCD.Command.BlinkOn  : USB2LCD.Command.BlinkOff);
         c.SendCmd(checkCursor.Checked	? USB2LCD.Command.CursorOn : USB2LCD.Command.CursorOff);
         c.SendCmd(USB2LCD.Command.Contrast,  (byte)trackBarContrast.Value );
         c.SendCmd(USB2LCD.Command.Backlight, (byte)trackBarBacklight.Value);
         c.SendCharacter(USB2LCD.Command.DefineCustom, 0, customChar1.GetData());
         c.SendCharacter(USB2LCD.Command.DefineCustom, 1, customChar2.GetData());
         c.SendCharacter(USB2LCD.Command.DefineCustom, 2, customChar3.GetData());
         c.SendCharacter(USB2LCD.Command.DefineCustom, 3, customChar4.GetData());
         c.SendCharacter(USB2LCD.Command.DefineCustom, 4, customChar5.GetData());
         c.SendCharacter(USB2LCD.Command.DefineCustom, 5, customChar6.GetData());
         c.SendCharacter(USB2LCD.Command.DefineCustom, 6, customChar7.GetData());
         c.SendCharacter(USB2LCD.Command.DefineCustom, 7, customChar8.GetData());
         c.SendCmd(USB2LCD.Command.Position, 1, 1);
         c.SendLine(textLine1.RealText, true);
         c.SendCmd(USB2LCD.Command.Position, 1, 2);
         c.SendLine(textLine2.RealText, true);
         c.SendCmd(USB2LCD.Command.Position, 1, 3);
         c.SendLine(textLine3.RealText, true);
         c.SendCmd(USB2LCD.Command.Position, 1, 4);
         c.SendLine(textLine4.RealText, true);
     }
     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);
     }
 }
Пример #4
0
 private void SetMem()
 {
     COM c = null;
     try
     {
         c = new COM(port, Baud);
         c.SendCmd(USB2LCD.Command.Remember, 1); //activate remembering
         if (checkDisplay.Checked)
             c.SendCmd(USB2LCD.Command.DisplayOn, radioOnAlways.Checked ? (byte)0 : (byte)numericOnFor.Value);
         else
             c.SendCmd(USB2LCD.Command.DisplayOff);
         c.SendCmd(checkBlink.Checked	? USB2LCD.Command.BlinkOn  : USB2LCD.Command.BlinkOff);
         c.SendCmd(checkCursor.Checked	? USB2LCD.Command.CursorOn : USB2LCD.Command.CursorOff);
         c.SendCmd(USB2LCD.Command.Contrast,  (byte)trackBarContrast.Value );
         c.SendCmd(USB2LCD.Command.Backlight, (byte)trackBarBacklight.Value);
         c.SendCmd(USB2LCD.Command.Remember, 0); //deactivate remembering
         c.SendCharacter(USB2LCD.Command.RememberCustom, 0, customChar1.GetData());
         c.SendCharacter(USB2LCD.Command.RememberCustom, 1, customChar2.GetData());
         c.SendCharacter(USB2LCD.Command.RememberCustom, 2, customChar3.GetData());
         c.SendCharacter(USB2LCD.Command.RememberCustom, 3, customChar4.GetData());
         c.SendCharacter(USB2LCD.Command.RememberCustom, 4, customChar5.GetData());
         c.SendCharacter(USB2LCD.Command.RememberCustom, 5, customChar6.GetData());
         c.SendCharacter(USB2LCD.Command.RememberCustom, 6, customChar7.GetData());
         c.SendCharacter(USB2LCD.Command.RememberCustom, 7, customChar8.GetData());
         c.SendCmd(USB2LCD.Command.SaveStartup);
         c.SendLine(textLine1.RealText, false);
         c.SendLine(textLine2.RealText, false);
         c.SendLine(textLine3.RealText, false);
         c.SendLine(textLine4.RealText, false);
     }
     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);
     }
 }
Пример #5
0
 private void butSetMem_Click(object sender, EventArgs e)
 {
     COM c = null;
     try
     {
         c = new COM(port, baud);
         c.SendCmd(USB2LCD.Command.RememberGPOpwm, 1, (byte)trackBar1.Value);
         c.SendCmd(USB2LCD.Command.RememberGPO, 1, (byte)(radioOn1.Checked ? 1 : 0));
         c.SendCmd(USB2LCD.Command.RememberGPOpwm, 2, (byte)trackBar2.Value);
         c.SendCmd(USB2LCD.Command.RememberGPO, 2, (byte)(radioOn2.Checked ? 1 : 0));
         c.SendCmd(USB2LCD.Command.RememberGPOpwm, 3, (byte)trackBar3.Value);
         c.SendCmd(USB2LCD.Command.RememberGPO, 3, (byte)(radioOn3.Checked ? 1 : 0));
         c.SendCmd(USB2LCD.Command.RememberGPOpwm, 4, (byte)trackBar4.Value);
         c.SendCmd(USB2LCD.Command.RememberGPO, 4, (byte)(radioOn4.Checked ? 1 : 0));
         c.SendCmd(USB2LCD.Command.RememberGPOpwm, 5, (byte)trackBar5.Value);
         c.SendCmd(USB2LCD.Command.RememberGPO, 5, (byte)(radioOn5.Checked ? 1 : 0));
     }
     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(); }
 }