Example #1
0
 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;
 }
Example #2
0
 private void butReadMem_Click(object sender, EventArgs e)
 {
     COM c = null;
     try
     {
         c = new COM(port, baud);
         c.ReadGPOVal(radioOn1, radioOff1, trackBar1, label1, 1, false);
         c.ReadGPOVal(radioOn2, radioOff2, trackBar2, label2, 2, false);
         c.ReadGPOVal(radioOn3, radioOff3, trackBar3, label3, 3, false);
         c.ReadGPOVal(radioOn4, radioOff4, trackBar4, label4, 4, false);
         c.ReadGPOVal(radioOn5, radioOff5, trackBar5, label5, 5, false);
     }
     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(); }
 }
Example #3
0
        private void ReadCur()
        {
            Control.CheckForIllegalCrossThreadCalls = false;
            COM c = null;
            try
            {
                c = new COM(port, Baud);
                int display = c.ReadByte(USB2LCD.Command.ReadDisplay);
                checkDisplay.Checked = ((display >> 2) & 1) == 1;
                checkBlink.Checked   = ((display >> 1) & 1) == 1;
                checkCursor.Checked  = ((display >> 0) & 1) == 1;
                int mins = c.ReadByte(USB2LCD.Command.ReadDisplayMin);
                radioOnAlways.Checked = mins == 0;
                radioOnFor.Checked = mins > 0;
                if (mins > 0)
                    numericOnFor.Value = mins;
                trackBarContrast.Value	= c.ReadByte(USB2LCD.Command.ReadContrast);
                trackBarBacklight.Value= c.ReadByte(USB2LCD.Command.ReadBacklight);

                customChar1.SetData(c.ReadBytes(USB2LCD.Command.ReadCustom, 0, 8));
                customChar2.SetData(c.ReadBytes(USB2LCD.Command.ReadCustom, 1, 8));
                customChar3.SetData(c.ReadBytes(USB2LCD.Command.ReadCustom, 2, 8));
                customChar4.SetData(c.ReadBytes(USB2LCD.Command.ReadCustom, 3, 8));
                customChar5.SetData(c.ReadBytes(USB2LCD.Command.ReadCustom, 4, 8));
                customChar6.SetData(c.ReadBytes(USB2LCD.Command.ReadCustom, 5, 8));
                customChar7.SetData(c.ReadBytes(USB2LCD.Command.ReadCustom, 6, 8));
                customChar8.SetData(c.ReadBytes(USB2LCD.Command.ReadCustom, 7, 8));

                string s = LCDText.GetStringFromBytes(c.ReadBytes(USB2LCD.Command.ReadMessage, 80));
                textLine1.RealText = s.Substring( 0, 20);
                textLine2.RealText = s.Substring(20, 20);
                textLine3.RealText = s.Substring(40, 20);
                textLine4.RealText = s.Substring(60, 20);
            }
            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);
            }
        }
Example #4
0
 private void ReadButtons()
 {
     COM c = null;
     try
     {
         c = new COM(port, Baud);
         string bs = "";
         for (byte i = 1; i <= 5; i++)
         {
             char ch = (char)c.ReadByte(USB2LCD.Command.ReadButton, i);
             if (Char.ToLower(ch) != ch)
                 bs += i + ", ";
         }
         bs = bs.Trim().Trim(',');
         ShowMessage((bs == "") ? "No buttons are pressed" : "Buttons pressed: "+bs, "Buttons", MessageBoxIcon.None);
     }
     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);
     }
 }
Example #5
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);
     }
 }
Example #6
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;
 }
Example #7
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);
        }
Example #8
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();
 }
Example #9
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);
     }
 }
Example #10
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);
     }
 }
Example #11
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(); }
 }