コード例 #1
0
        private void btnConnect_Click(object sender, EventArgs e)
        {
            if (!CanConnect)
            {
                Helpers.ErrorBox("Internal error at connecting!");
                return;
            }

            if (!this.ComportIsExists)
            {
                this.btnConnect.Enabled = false;
                MessageBox.Show($"Serialport \"{this.CurretPortName}\" does not exists!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            try
            {
                this.Port               = new PySerial();
                this.Port.BaudRate      = Properties.Settings.Default.PyBaudRate;
                this.Port.LineSeparator = "\r\n"; // Properties.Settings.Default.PyPortLineSeparator;
                this.Port.WriteTimeout  = Properties.Settings.Default.PyPortWriteTimeout;
                this.Port.ReadTimeout   = Properties.Settings.Default.PyPortReadTmeout;
                this.Port.Open();
            }
            catch (Exception ex)
            {
                this.Port = null;
                Helpers.ErrorBox(ex.Message);
            }
        }
コード例 #2
0
 private void btnDisconnect_Click(object sender, EventArgs e)
 {
     if (this.Port != null)
     {
         try
         {
             this.Port.Close();
         }
         catch (Exception ex)
         {
             Helpers.ErrorBox(ex);
         }
         finally
         {
             this.Port = null;
         }
     }
 }