public void closeComPort() { if (Variables.COMPORTOPENED == true) { sp.Close(); Variables.COMPORTOPENED = false; PortOK.Visible = false; PortNOK.Visible = true; PortNOK.Refresh(); } }
public bool initComPort() { sp = new SerialPort(Variables.NUMPORT); bool porterror = false; // false = no error, true = error try { sp.Open(); } catch (Exception ex) { stateDisplay.Text = "Cannot open port, exception " + ex.Message.ToString(); porterror = true; } //finally { if (porterror == false) { Variables.COMPORTOPENED = true; PortOK.Visible = true; PortNOK.Visible = false; PortOK.Refresh(); stateDisplay.Refresh(); } else { Variables.COMPORTOPENED = false; PortOK.Visible = false; PortNOK.Visible = true; PortNOK.Refresh(); } // Initialise I2C SCL and SDA lines. i2c_scl(true); // SCL i2c_sda(true); // SDA return(Variables.COMPORTOPENED); }