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