Beispiel #1
0
        //Encerra o programa
        private void encerrarButton_Click(object sender, EventArgs e)
        {
            //Registrar no Log
            InterfaceGeral.registrarLog("Encerramento", "Programa de segmento solo Alpha - Cansat encerrado!");

            this.Owner.Close();
        }
        //Abre a porta serial
        public static int OpenSerial()
        {
            //Pesquisa da porta do dispositivo
            for (int porta = 0; porta <= 10; porta++)
            {
                try
                {
                    //Tenta conectar à uma porta
                    serialPort.PortName = "COM" + porta.ToString();
                    serialPort.Open();

                    #region Verificação do dispositivo
                    //Verifica se o dispositivo conectado é a antena
                    if (serialPort.IsOpen)
                    {
                        //Envia dado para o dispositivo
                        serialPort.WriteLine(Properties.Settings.Default.msgSendSerial);

                        //Aguarda 0,1seg pela resposta
                        Thread.Sleep(100);

                        //Recebe resposta do dispositivo
                        string msg = serialPort.ReadExisting(); //Falta verificar se o tempo de resposta é hábil

                        //Confirmação de que o dispositivo é a antena
                        if (msg == Properties.Settings.Default.msgRcvSerial)
                        {
                            InterfaceGeral.registrarLog("Conexao", Properties.Resources.logConexaoSerial);
                            return(1);
                        }
                        else
                        {
                            //Registra que a conexão à porta especificada ocasionou erro
                            InterfaceGeral.registrarLog("Conexao", Properties.Resources.erroPortaSerial + serialPort.PortName);

                            //Fecha a porta serial aberta
                            serialPort.Close();
                        }
                    }
                    #endregion
                }
                catch
                {
                    //Registra que a conexão à porta especificada ocasionou erro
                    InterfaceGeral.registrarLog("Conexao", Properties.Resources.erroPortaSerial + serialPort.PortName);
                }
            }

            return(0);
        }
        private void menuArmazenar_Click(object sender, EventArgs e)
        {
            //Desabilitação do botão de armazenamento
            menuArmazenar.Enabled = false;
            menuArmazenar.Visible = false;
            menuArmazenar.Cursor  = Cursors.Default;

            //Exibe diálogo para seleção de pastas
            FolderBrowserDialog dialog = new FolderBrowserDialog();

            dialog.ShowNewFolderButton = false;
            dialog.Description         = Properties.Resources.msgSelRemovivel;
            dialog.RootFolder          = Environment.SpecialFolder.MyComputer;
            dialog.ShowDialog();

            //Exibe diálogo de erro para o caso de erro do usuário
            if ((dialog.SelectedPath == "") || (dialog.SelectedPath.Contains("C:")))
            {
                ErroRemovivel erroRemovivel = new ErroRemovivel();
                this.AddOwnedForm(erroRemovivel);
                erroRemovivel.Show();

                habilitarConexao(false);
            }
            else
            {
                //Executar o diálogo informativo
                InformativoArmazenamento informativoArmazenamento = new InformativoArmazenamento();
                this.AddOwnedForm(informativoArmazenamento);
                informativoArmazenamento.Show();

                //Registrar no Log
                string nomeArquivo = DateTime.Now + " - Cansat.txt";
                nomeArquivo = nomeArquivo.Replace("/", "-");
                nomeArquivo = nomeArquivo.Replace(":", ".");
                InterfaceGeral.registrarLog("Armazenamento", "Nome do arquivo: " + nomeArquivo);
                InterfaceGeral.registrarLog("Armazenamento", "Local: " + InterfaceGeral.Path);
                InterfaceGeral.registrarLog("Armazenamento", "Removível: " + dialog.SelectedPath);
                InterfaceGeral.registrarLog("Armazenamento", "Rede: " + Properties.Settings.Default.urlServidorLocal); //Falta descrever o local de armazenamento da rede

                //Armazenamento do endereço do PenDrive e do nome do arquivo
                Properties.Settings.Default.enderecoRemovivel = dialog.SelectedPath;
                Properties.Settings.Default.nomeArquivo       = nomeArquivo;
                Properties.Settings.Default.Save();

                habilitarConexao(true);
            }
        }
        public Menu()
        {
            InterfaceGeral.formatarJanela(this);

            InitializeComponent();

            //Atualiza o código de execução do programa
            Properties.Settings.Default.numeroExecucao += 1;
            Properties.Settings.Default.Save();

            //Garante a existência da pasta de registros
            InterfaceGeral.Path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\" + Properties.Resources.pastaLocal;
            if (!Directory.Exists(InterfaceGeral.Path))
            {
                Directory.CreateDirectory(InterfaceGeral.Path);
            }

            //Registrar no Log
            InterfaceGeral.registrarLog("Inicialização", "Programa de segmento solo Alpha-Cansat inicializado!");
        }