Example #1
0
        void tryToConnect()
        {
            String resp;

            String[] respl;
            Char[]   delimn = new Char[] { '\n', '\r' };
            Char[]   deliml = new Char[] { ' ' };
            while (true)
            {
                if (isConnected == false && isBusy == false)
                {
                    serialPort             = new SerialPort(portName);
                    serialPort.ReadTimeout = 1000;
                    resp = "";
                    try
                    {
                        serialPort.Open();
                        serialPort.WriteLine("");
                        resp = serialPort.ReadTo(">");
                        serialPort.WriteLine("ID");
                        serialPort.WriteLine(" ");
                        Thread.Sleep(1000);
                        resp  = serialPort.ReadTo(">");
                        resp  = resp.Replace('-', '_');
                        respl = resp.Split(delimn, StringSplitOptions.RemoveEmptyEntries);
                        respl = respl[1].Split(deliml, StringSplitOptions.RemoveEmptyEntries);
                        if (textRobotName.InvokeRequired)
                        {
                            textRobotName.Invoke(new Action(delegate()
                            {
                                textRobotName.Text = respl[2] + respl[9];
                            }));
                        }
                        if (labStatus.InvokeRequired)
                        {
                            labStatus.Invoke(new Action(delegate()
                            {
                                labStatus.Text      = "Connected";
                                labStatus.BackColor = Color.Chartreuse;
                            }));
                        }
                        soundPlayer = new SoundPlayer(Properties.Resources.maxcon);//(Sounds[1]);
                        soundPlayer.Play();
                        consoleWrite("Connected to " + portName, Color.Green);
                        isConnected = true;
                        if (blockPanel.InvokeRequired)
                        {
                            blockPanel.Invoke(new Action(delegate()
                            {
                                blockPanel.Enabled = true;
                            }));
                        }
                    }
                    catch (Exception e)
                    {
                        serialPort.Close();
                    }
                }
                Thread.Sleep(1000);
            }
        }
Example #2
0
        void backupUSB(String dirName, String robName, ref bool isShowed)
        {
            String resp;

            String[] respl;
            Char[]   delim = new Char[] { '\n' };
            try
            {
                lock (this)
                {
                    if (labStatus.InvokeRequired)
                    {
                        labStatus.Invoke(new Action(delegate()
                        {
                            labStatus.Text      = "Backuping";
                            labStatus.BackColor = Color.Gold;
                        }));
                    }
                    serialPort.WriteLine("USB_FDEL " + dirName);
                    resp  = waitResponse();
                    respl = resp.Split(delim, StringSplitOptions.RemoveEmptyEntries);
                    if (respl[1] == "(P2103)USB memory is not inserted.\r")
                    {
                        if (!isShowed)
                        {
                            consoleWrite("Please input USB memory", Color.Red);
                            Thread.Sleep(1000);
                            soundPlayer = new SoundPlayer(Properties.Resources.maxflash);//(Sounds[5]);
                            soundPlayer.Play();
                            isShowed = true;
                        }
                        return;
                    }
                    soundPlayer = new SoundPlayer(Properties.Resources.maxload);//(Sounds[3]);
                    soundPlayer.Play();
                    consoleWrite("Backuping", Color.Orange);
                    isShowed = false;

                    serialPort.WriteLine("USB_MKDIR " + dirName);
                    resp = waitResponse();
                    consoleWrite("Saving backup", Color.Blue);

                    serialPort.WriteLine("USB_SAVE " + dirName + "\\" + robName);
                    resp = waitResponse();
                    writeArray(resp);
                    consoleWrite("Backup saved\n", Color.Green);

                    consoleWrite("Saving operation log", Color.Blue);
                    serialPort.WriteLine("USB_SAVE/OPLOG " + dirName + "\\" + robName);
                    resp = waitResponse();
                    writeArray(resp);
                    consoleWrite("Operation log saved\n", Color.Green);

                    consoleWrite("Saving error log", Color.Blue);
                    serialPort.WriteLine("USB_SAVE/ELOG " + dirName + "\\" + robName);
                    resp = waitResponse();
                    writeArray(resp);
                    consoleWrite("Error log saved\n", Color.Green);

                    consoleWrite("Finished\n", Color.Green);
                    soundPlayer = new SoundPlayer(Properties.Resources.maxfinished);//(Sounds[4]);
                    soundPlayer.Play();

                    if (labStatus.InvokeRequired)
                    {
                        labStatus.Invoke(new Action(delegate()
                        {
                            labStatus.Text      = "Connected";
                            labStatus.BackColor = Color.Chartreuse;
                        }));
                    }
                    if (blockPanel.InvokeRequired)
                    {
                        blockPanel.Invoke(new Action(delegate()
                        {
                            blockPanel.Enabled = true;
                        }));
                    }
                }
            } catch (Exception e) { };
            mode   = 0;
            isBusy = false;
        }