예제 #1
0
 private void btnOpen_Click(object sender, EventArgs e)
 {
     if (btnOpen.Text == Resources.OpenString)
     {
         if (NewPortInstance())
         {
             try
             {
                 portOperatorBase.Open();
                 btnOpen.Text = Resources.CloseString;
                 EnableControl(false);
             }
             catch { }
         }
     }
     else
     {
         try
         {
             portOperatorBase.Close();
         }
         catch { }
         btnOpen.Text = Resources.OpenString;
         EnableControl(true);
     }
 }
예제 #2
0
 public override bool Open()
 {
     try
     {
         _operator = new USBPortOperator(((USBCfgModel)Configuration).UsbAddress);
         _operator.Open();
     }
     catch (Exception exp)
     {
         throw exp;
     }
     return(true);
 }
 public override bool Open()
 {
     if (IsOpen)
     {
         return(true);
     }
     try
     {
         _operator = new GPIBPortOperator(((GPIBCfgModel)Configuration).GPIBAddress);
         _operator.Open();
     }
     catch (Exception exp)
     {
         throw exp;
     }
     return(true);
 }
예제 #4
0
 private void openSPbtn_Click(object sender, EventArgs e)
 {
     if (openSPbtn.Text == "Open")
     {
         bool   hasAddress   = false;
         bool   hasException = false;
         string str          = devicesCB.SelectedItem.ToString();
         Console.WriteLine("address:" + str);
         if (!str.Contains("ASRL"))
         {
             printInfo("Select port ERROR!", Color.Red);
             return;
         }
         try
         {
             serialopBase = new RS232PortOperator(str,
                                                  (int)baudRateCB.SelectedItem, 0, 0, 8);
             hasAddress = true;
         }
         catch (Exception ex)
         {
             MessageBox.Show("error1:" + ex.ToString());
             hasException = true;
         }
         if (!hasException)
         {
             hasException         = false;
             serialopBase.Timeout = 5000;
             try
             {
                 serialopBase.Open();
                 openSPbtn.Text = "Close";
                 //EnableControl(false);
             }
             catch (Exception ex)
             {
                 MessageBox.Show("error2:" + ex.ToString());
                 hasException = true;
             }
         }
         if (!hasException)
         {
             printInfo("Open Serial port successful!", Color.Green);
         }
         else
         {
             printInfo("Open Serial port fail!", Color.Red);
         }
     }
     else
     {
         bool hasException = false;
         try
         {
             serialopBase.Close();
         }
         catch { hasException = true; }
         openSPbtn.Text = "Open";
         //EnableControl(true);
         if (!hasException)
         {
             printInfo("Close Serial port successful!", Color.Green);
         }
         else
         {
             printInfo("Close Serial port fail!", Color.Red);
         }
     }
 }