Exemplo n.º 1
0
 private void ConnectSerial_Click(object sender, EventArgs e)
 {
     if (USBport.IsOpen == false) //buttonConnectSerial.Text == "Connect (USB Port)"
     {
         // Set COM Port
         string str = comboBox1.GetItemText(comboBox1.SelectedItem);
         if (comboBox1.SelectedItem != null)
         {
             USBport.PortName = str;
         }
         textBox1.Text = str;
         try
         {
             USBport.Open();
             buttonConnectSerial.Text = "Disconnect (USB Port)";
         }
         catch (Exception err)
         {
             MessageBox.Show(err.Message);
             //throw;
         }
     }
     else if (USBport.IsOpen == true)  //(buttonConnectSerial.Text == "Disconnect (USB Port)"
     {
         USBport.Close();
         buttonConnectSerial.Text = "Connect (USB Port)";
     }
 }
Exemplo n.º 2
0
        // THIS METHOD IS FOR TESTING PURPOSE

        /*
         * private void JsendCommandTest()
         * {
         *  int axisA = state.Rz;
         *  int axisB = state.Z;
         *  int axisC = state.X;
         *  int axisD = state.Y;
         *
         *  byte val = 0;
         *  //byte g = 255;
         *  if (axisD <= 32768)
         *  {
         *      //val = Convert.ToByte(128 - (axisD / 256));
         *      val = Convert.ToByte(250 + axisD * (175 - 250) / (32767));
         *  }
         *  else if (axisD > 32768)
         *  {
         *     val = Convert.ToByte( 280 + axisD * ( 60- 175) / (32767));
         *  }
         *  textBox1.Text = "" + Convert.ToString(val);
         * }*/

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            USBport.Close();
        }