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; }
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); } }
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); } }
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; }