Exemple #1
0
 private void btnOpen_Click(object sender, EventArgs e)
 {
     if (HartDevice != null)
     {
         HartDevice.Close();
     }
     if (comPortComboBox1.ComPort > 0)
     {
         AppSettings.Current.HartCommport = comPortComboBox1.ComPort;
         HartDevice = new HartSDK.HartDevice(comPortComboBox1.ComPort, 1200);
         HartDevice.PollingAddress = (byte)cmbShortAddress.SelectedIndex;
         HartDevice.Debug          = AppSettings.Current.Debug;
         HartDevice.Connect();
         lblCommportState.Text      = string.Format(HartDevice.IsConnected ? "设备已经连接" : "设备连接失败");
         lblCommportState.ForeColor = HartDevice.IsConnected ? Color.Blue : Color.Red;
         statusStrip1.Refresh();
         btnOpen.Enabled  = !HartDevice.IsConnected;
         btnClose.Enabled = HartDevice.IsConnected;
         ShowDeviceState();
     }
     else
     {
         MessageBox.Show("请先设置通讯串口");
     }
 }
Exemple #2
0
 private void btnClose_Click(object sender, EventArgs e)
 {
     if (HartDevice != null)
     {
         HartDevice.Close();
     }
     HartDevice            = null;
     btnOpen.Enabled       = true;
     btnClose.Enabled      = false;
     lblCommportState.Text = string.Empty;
     ShowDeviceState();
 }