Esempio n. 1
0
 public void Send(string data)
 {
     if (StateManager.TcpState.IsClientConnected == true)
     {
         TcpManager tempTcpManager = TcpManager.GetInstance();
         tempTcpManager.TcpServerSend(InterNetwork.GetInstance().GetRemoteClient(), data + Environment.NewLine);
     }
     else
     {
         FormArduinoControlPanel.GetInstance().WriteToConsole("Error: No Client Connected !");
     }
 }
Esempio n. 2
0
 public void Send(MotorDirection dirA, int speedA, MotorDirection dirB, int speedB, int time)
 {
     if (StateManager.TcpState.IsClientConnected == true)
     {
         string     data           = "Motor" + Separator + (int)dirA + Separator + speedA + Separator + (int)dirB + Separator + speedB + Separator + time + Separator + Environment.NewLine;
         TcpManager tempTcpManager = TcpManager.GetInstance();
         tempTcpManager.TcpServerSend(InterNetwork.GetInstance().GetRemoteClient(), data);
         StateManager.ArduinoState.IsBusy = true;
     }
     else
     {
         FormArduinoControlPanel.GetInstance().WriteToConsole("Error: No Client Connected !");
     }
 }
Esempio n. 3
0
            private void Receive(object argClient)
            {
                var           client = (TcpManager.TcpClientWithGuid)argClient;
                NetworkStream ns     = client.TcpStream;
                StreamReader  sr     = new StreamReader(ns);

                while (true)
                {
                    string data;
                    try
                    {
                        data = sr.ReadLine();
                    }
                    catch (IOException e)
                    {
                        client.Stop();
                        StateManager.TcpState.IsClientConnected = false;
                        break;
                    }

                    if (data == null)
                    {
                        client.Stop();
                        StateManager.TcpState.IsClientConnected = false;
                        break;
                    }
                    string[] items = data.Split(Separators, StringSplitOptions.RemoveEmptyEntries);
                    //Get Picture
                    if (items[0] == "Picture")
                    {
                        long         contentLen = Convert.ToInt64(items[1]);
                        MemoryStream ms         = new MemoryStream();
                        long         size       = 0;
                        while (size < contentLen)
                        {
                            //Receive 256 bytes for every loop
                            byte[] bits = new byte[4096];
                            int    r    = client.TcpClient.GetStream().Read(bits, 0, bits.Length);
                            if (r <= 0)
                            {
                                break;
                            }
                            ms.Write(bits, 0, r);
                            size += r;
                        }
                        System.Drawing.Image img;
                        try
                        {
                            img = System.Drawing.Image.FromStream(ms);
                        }
                        catch (Exception e)
                        {
                            InterNetwork.GetInstance().AcquirePicture();
                            continue;
                        }
                        TcpIpFileManager.GetInstance().AddTempFile(img);
                    }
                    //Motor State Feedback
                    else if (items[0] == "Motor")
                    {
                        if (items[1] == "Finished")
                        {
                            StateManager.ArduinoState.IsBusy = false;
                        }
                        else if (items[1] == "GetCommand")
                        {
                            StateManager.ArduinoState.IsBusy = true;
                        }
                        else
                        {
                            throw new NotImplementedException();
                        }
                    }
                    //MPU data send back
                    else if (items[0] == "MPU")
                    {
                        if (items[1] == "Angle")
                        {
                            if (items[2] == "Z")
                            {
                                FormArduinoControlPanel.GetInstance().WriteToConsole("Z angle = " + items[3]);
                            }
                            else
                            {
                                throw new NotImplementedException();
                            }
                        }
                        else
                        {
                            throw new NotImplementedException();
                        }
                    }
                    //Get Distance Result
                    else if (items[0] == "DISTANCE")
                    {
                        FormArduinoControlPanel.GetInstance().WriteToConsole("Distance = " + items[1]);
                        Arduino.GetInstance().SonicDistance = Convert.ToSingle(items[1]);
                    }
                    //ELSE
                    else
                    {
                        throw new NotImplementedException();
                    }
                }
            }
 public static FormArduinoControlPanel GetInstance()
 {
     return(_instance ?? (_instance = new FormArduinoControlPanel()));
 }
Esempio n. 5
0
 private void arduinoControlPanelToolStripMenuItem_Click(object sender, EventArgs e)
 {
     FormArduinoControlPanel.GetInstance().Show();
 }
Esempio n. 6
0
 private void FormMain_Load(object sender, EventArgs e)
 {
     InterNetwork.GetInstance().Init();
     StateManager.TcpState.IsClientConnected = false;
     FormArduinoControlPanel.GetInstance().Show();
 }