Пример #1
0
 private void Button_Disconnect_Click(object sender, EventArgs e)
 {
     COMport.Close();
     RichTextBox_Log.Text             = RichTextBox_Log.Text + Environment.NewLine + COMport.PortName + " closed";
     GroupBox_SeriaL_Receive.Enabled  = false;
     GroupBox_Serial_Transmit.Enabled = false;
 }
Пример #2
0
    // Update is called once per frame
    void Update()
    {
        if (init && Dropdowns.Count > 0)
        {
            Init();
            init = false;
        }

        if (!getingData)
        {
            if (thread != null)
            {
                if (thread.IsAlive)
                {
                    thread.Abort();
                }
            }
            thread = new Thread(delegate()
            {
                getingData = true;
                COMport.ReceiveData();
                getingData = false;
            });
            thread.Start();
        }


        if (ScrollViews.Count > 0)
        {
            ScrollViews[0].text = COMport.getLastLog(10);
        }
    }
Пример #3
0
 private void flushbutton_Click(object sender, EventArgs e)
 {
     try
     {
         COMport.DiscardInBuffer();
     }
     catch (Exception E)
     { }
 }
Пример #4
0
 private void flushbutton_Click(object sender, EventArgs e)
 {
     try
     {
         COMport.DiscardInBuffer();
     }
     catch (Exception E)
     {
         MessageBox.Show(E.ToString());
     }
 }
Пример #5
0
 // Update is called once per frame
 void Update()
 {
     if (COMport.isConnected())
     {
         transform.GetChild(0).GetComponent <Text>().text = COMport.getInfo();
     }
     else
     {
         transform.GetChild(0).GetComponent <Text>().text = "Not Connected";
     }
 }
Пример #6
0
    public void ConnectBTN(int ID)
    {
        switch (Dropdowns[ID].value)
        {
        case 0: { thread.Abort(); COMport.Disconnect(); thread.Abort(); getingData = false; } break;

        case 1: COMport.Connect(port); break;

        default: break;
        }
    }
Пример #7
0
 private static void Init()
 {
     PortNames.Clear();
     PortNames.AddRange(COMport.getPortNames());
     Dropdowns[1].options.Clear();
     port = PortNames[0];
     foreach (string item in PortNames)
     {
         Dropdowns[1].options.Add(new Dropdown.OptionData(item));
     }
     Dropdowns[1].value = 0;
 }
Пример #8
0
        private void parsePacket(string idata1)
        {
            if (idata1[0] == '1')
            {
                MessageBox.Show("Checksum fail");
            }

            if (idata1[0] == '4')
            {
                //Splitting string into two parts 30 bytes and 2 bytes for checksum
                char[] result1 = idata1.ToCharArray();


                // char[] rec2 = receive_data.Substring(30, 31).ToCharArray();
                char[] new_result2 = new char[2];


                //Again getting the checksum of received string
                uint chkval = checksum(result1);

                chkval         = chkval % 256;
                new_result2[0] = int2hex(chkval / 16);
                new_result2[1] = int2hex(chkval % 16);

                if ((new_result2[0] == result1[30] && new_result2[1] == result1[31]))         //checksum validation
                {
                    float theta   = float.Parse(idata1.Substring(1, 4)) / 1000;
                    float Epsilon = float.Parse(idata1.Substring(7, 4)) / 1000;

                    th_Field.Text   = theta.ToString();
                    bige_Field.Text = Epsilon.ToString();
                }
                else
                {
                    MessageBox.Show("Checksum failed");         //if checksum char(s) validation fails, show fail
                }


                string feedback2 = "20000000000000000000000000000027";
                char[] fee       = feedback2.ToCharArray();

                try
                {
                    Thread.Sleep(300);
                    COMport.Write(fee, 0, 32);
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.ToString());
                }
            }
        }
Пример #9
0
 public bool writeport(char[] data, int len)
 {
     try
     {
         COMport.Write(data, 0, len);
     }
     catch (Exception E)
     {
         MessageBox.Show(E.ToString());
         return(false);
     }
     return(true);
 } // writeport
Пример #10
0
 // Update is called once per frame
 void Update()
 {
     for (int i = 0; i < 5; i++)
     {
         if (COMport.isConnected())
         {
             transform.GetChild(i).GetComponent <Text>().text = name[i] + ": " + COMport.getLight(i);
         }
         else
         {
             transform.GetChild(i).GetComponent <Text>().text = name[i] + ": " + 0;
         }
     }
 }
Пример #11
0
        private void Button_Connect_Click(object sender, EventArgs e)
        {
            string Port_Name = ComboBox_Available_SerialPorts.SelectedItem.ToString();
            int    Baud_Rate = Convert.ToInt32(ComboBox_Standard_Baudrates.SelectedItem);
            string Data      = "Neki";

            COMport.BaudRate = Baud_Rate;
            COMport.PortName = Port_Name;

            try
            {
                COMport.Open();
            }
            catch (System.IO.IOException SerialException)
            {
                MessageBox.Show(SerialException.ToString());
                COMport.Close();
            }
            catch (UnauthorizedAccessException SerialException)
            {
                MessageBox.Show(SerialException.ToString());
                COMport.Close();
            }
            catch (InvalidOperationException SerialException)
            {
                MessageBox.Show(SerialException.ToString());
                COMport.Close();
            }
            catch
            {
                MessageBox.Show("Unknown ERROR when opening serial port" + COMport);
                COMport.Close();
            }

            if (COMport.IsOpen == true)
            {
                Label_COM_Status.Text            = "Open";
                RichTextBox_Log.Text             = RichTextBox_Log.Text + Environment.NewLine + Port_Name + " opened at " + ComboBox_Standard_Baudrates.SelectedItem.ToString() + " baudrate";
                GroupBox_SeriaL_Receive.Enabled  = true;
                GroupBox_Serial_Transmit.Enabled = true;
            }
            else
            {
                COMport.Close();
                RichTextBox_Log.Text = RichTextBox_Log.Text + Environment.NewLine + Port_Name + " failed to open";
            }
        }
Пример #12
0
        private void Health_Button_Click(object sender, EventArgs e)
        {
            char[] feedbackchar = new char[32];
            if (COMport.IsOpen == true)
            {
                string healthreq = "500000000000000000000000000000";
                char[] reqh      = new char[32];
                for (int i = 0; i < 30; i++)
                {
                    reqh[i] = healthreq[i];
                }
                char[] ckval = new char[2];


                //Again getting the checksum of received string
                uint chkval = checksum(reqh);

                chkval   = chkval % 256;
                ckval[0] = int2hex(chkval / 16);
                ckval[1] = int2hex(chkval % 16);

                reqh[30] = ckval[0];
                reqh[31] = ckval[1];

                try
                {
                    Thread.Sleep(300);
                    COMport.Write(reqh, 0, 32);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }

                var CurDate = DateTime.Now;
                Time_Field.Text = CurDate.Hour.ToString() + " : " + CurDate.Minute.ToString() + " : " + CurDate.Millisecond.ToString();
            }
            else
            {
                Log_Box.Text = "Unable to write to PORT";
            }
        }
Пример #13
0
 // Update is called once per frame
 void Update()
 {
     if (COMport.isConnected())
     {
         transform.GetChild(0).GetComponent <Text>().text = "Winkel:" + COMport.getServoAngle(ID);
     }
     else
     if (Direktion == 'X' || Direktion == 'x')
     {
         transform.GetChild(0).GetComponent <Text>().text = "Winkel:" + (Main.Gelenk[ID].GetComponent <Gelenk_Parameter>().transform.eulerAngles.x).ToString();
     }
     else
     if (Direktion == 'Y' || Direktion == 'y')
     {
         transform.GetChild(0).GetComponent <Text>().text = "Winkel:" + (Main.Gelenk[ID].GetComponent <Gelenk_Parameter>().transform.eulerAngles.y).ToString();
     }
     else
     if (Direktion == 'Z' || Direktion == 'z')
     {
         transform.GetChild(0).GetComponent <Text>().text = "Winkel:" + (Main.Gelenk[ID].GetComponent <Gelenk_Parameter>().transform.eulerAngles.z).ToString();
     }
 }
Пример #14
0
        private void Health_Button_Click(object sender, EventArgs e)
        {
            char[] feedbackchar = new char[32];
            if (COMport.IsOpen == true)
            {
                char[] reqh = new char[32];
                reqh = "500000000000000000000000000000".ToCharArray();
                char[] ckval = new char[2];


                //Again getting the checksum of received string
                uint chkval = checksum(reqh);

                chkval   = chkval % 256;
                ckval[0] = int2hex(chkval / 16);
                ckval[1] = int2hex(chkval % 16);

                reqh[30] = ckval[0];
                reqh[31] = ckval[1];

                try
                {
                    Thread.Sleep(300);
                    COMport.Write(reqh, 0, 32);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }

                COMport.ReadTimeout = 3500;
            }
            else
            {
                Log_Box.Text = "Unable to write to PORT";
            }
        }
Пример #15
0
    // Update is called once per frame
    void Update()
    {
        if (!COMport.isConnected())
        {
            if (Direktion == 'X' || Direktion == 'x')
            {
                RotateVector.x = RotateSpeed;
            }
            if (Direktion == 'Y' || Direktion == 'y')
            {
                RotateVector.y = RotateSpeed;
            }
            if (Direktion == 'Z' || Direktion == 'z')
            {
                RotateVector.z = RotateSpeed;
            }
            transform.Rotate(RotateVector);
            RotateAngles = transform.localEulerAngles;
        }
        else
        {
            if (Direktion == 'X' || Direktion == 'x')
            {
                RotateAngles.x = (float)Angle;
            }
            if (Direktion == 'Y' || Direktion == 'y')
            {
                RotateAngles.y = (float)Angle;
            }
            if (Direktion == 'Z' || Direktion == 'z')
            {
                RotateAngles.z = (float)Angle;
            }
            double schritt = (COMport.getServoAngle(ID) - OldAngle) / 12;//Interval;

            Angle += schritt;

            if (schritt > 0)
            {
                if (Angle >= COMport.getServoAngle(ID))
                {
                    Angle = COMport.getServoAngle(ID);
                }
            }


            if (schritt < 0)
            {
                if (Angle <= COMport.getServoAngle(ID))
                {
                    Angle = COMport.getServoAngle(ID);
                }
            }



            //if (Math.Round(Angle, 4) == Math.Round(COMport.getServoAngle(ID)))
            //    Angle = COMport.getServoAngle(ID);

            if (TempAngle != COMport.getServoAngle(ID))
            {
                Interval        = IntervalCounter;
                IntervalCounter = 0;
                OldAngle        = TempAngle;
                TempAngle       = COMport.getServoAngle(ID);
            }
            IntervalCounter++;
            transform.localEulerAngles = RotateAngles;
        }
    }
Пример #16
0
        private void COMport_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            string indata = COMport.ReadLine();

            RichTextBox_Log.Text = RichTextBox_Log.Text + Environment.NewLine + indata;
        }
Пример #17
0
 void OnApplicationQuit()
 {
     thread.Abort();
     COMport.Disconnect();
 }