Exemple #1
0
        private void SSHInfoDelete(SSHInfo info)
        {
            SSHInfoHashSet.Remove(info);
            SshClient ssh = new SshClient(info.IP, int.Parse(info.Port), info.UserName, info.Password);

            if (info.Type == "NAS")
            {
                foreach (var sshClient in SSHNASClientList)
                {
                    if (sshClient.ToString() == ssh.ToString())
                    {
                        SSHNASClientList.Remove(sshClient);
                        break;
                    }
                }
            }
            else
            {
                foreach (var sshClient in SSHWSLClientList)
                {
                    if (sshClient.ToString() == ssh.ToString())
                    {
                        SSHWSLClientList.Remove(sshClient);
                        break;
                    }
                }
            }
            ConfigFileSave();
        }
Exemple #2
0
 private void SSHSave()
 {
     if (SSHUserName != null && SSHIP != null && SSHPort != null && SSHSystem != null && SSHType != null && SSHPassword != null)
     {
         var newSSHInfo = new SSHInfo(SSHUserName, SSHIP, SSHPort, SSHSystem, SSHType, SSHPassword);
         SSHInfoHashSet.Add(newSSHInfo);
         SshClient ssh = new SshClient(newSSHInfo.IP, int.Parse(newSSHInfo.Port), newSSHInfo.UserName, newSSHInfo.Password);
         if (newSSHInfo.Type == "NAS")
         {
             SSHNASClientList.Add(ssh);
         }
         else
         {
             SSHWSLClientList.Add(ssh);
         }
         ssh.Connect();
         ResetSSHVars();
     }
     ConfigFileSave();
 }
        private void button1_Click(object sender, EventArgs e)
        {
            float DeF_X = Convert.ToSingle(AxisX.Text);
            float DeF_Y = Convert.ToSingle(AxisY.Text);

            CarPosition.Refresh();
            SSHInfo.Clear();
            DrawingPlot();

            DrawingRectangle((int)Math.Floor(DeF_X / 10), (int)Math.Floor(DeF_Y / 10));
            DrawingLine((int)Math.Floor(DeF_X / 10), (int)Math.Floor(DeF_Y / 10));

            previousX = CarPosition.Width / 2;
            previousY = CarPosition.Height / 2;

            RPi = new SshClient(IPBox.Text, UsernameBox.Text, PasswordBox.Text);

            RPi.Connect();

            shell = RPi.CreateShellStream("shell", 100, 100, 100, 100, 1024);
            shell.Write("python3 /home/pi/Documents/fuzzy/fuzzy_script.py \n");
            shell.Write(Convert.ToString(DeF_X) + "\n");
            shell.Write(Convert.ToString(DeF_Y) + "\n");

            shell.Flush();

            bool fl      = true;
            int  counter = 0;

            while (fl)
            {
                if (shell != null && shell.DataAvailable)
                {
                    string[] info;
                    string   data = shell.Read();

                    if (counter > 56)
                    {
                        char[] deter = { '\r', '\n' };
                        info = data.Split(deter);
                        foreach (string s in info)
                        {
                            if (s == "")
                            {
                                continue;
                            }

                            SSHInfo.AppendText(s + "\r\n");

                            if (s == "DONE" || s == "Terminated")
                            {
                                fl = false;
                                shell.Close();
                                RPi.Disconnect();
                                break;
                            }

                            if (s[0] == 'D')
                            {
                                SensorReading.Clear();
                                SensorReading.ForeColor = Color.Black;
                                SensorReading.AppendText(s);
                            }
                            if (s[0] == 'P')
                            {
                                PWM.Clear();
                                PWM.AppendText(s);
                            }
                            if (s[0] == 'S')
                            {
                                Speed.Clear();
                                Speed.AppendText(s);
                            }
                            if (s[0] == 'T')
                            {
                                TraveledDistance.Clear();
                                TraveledDistance.AppendText(s);
                            }

                            if (s[0] == 'X')
                            {
                                drawRobotWay(Convert.ToSingle(s.Substring(4, s.IndexOf(':') - 4)), Convert.ToSingle(s.Substring(s.IndexOf(':') + 5)));
                            }
                        }
                    }
                    else
                    {
                        counter++;
                        data = null;
                    }
                }
            }
        }