Exemplo n.º 1
0
        private void OpenFile(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            openFileDialog.Filter           = "LadderApp files (*.xml;*.a43)|*.xml;*.a43|XML files (*.xml)|*.xml|MSP430 Executable files (*.a43)|*.a43";
            if (openFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                string fileName = openFileDialog.FileName;
                switch (Path.GetExtension(fileName).ToLower())
                {
                case ".xml":

                    try
                    {
                        XmlReader     fileReader    = new XmlTextReader(new FileStream(fileName, FileMode.Open));
                        XmlSerializer xmlSerializer = new XmlSerializer(typeof(LadderProgram));
                        if (xmlSerializer.CanDeserialize(fileReader))
                        {
                            LadderProgram ladderProgram = (LadderProgram)xmlSerializer.Deserialize(fileReader);
                            projectForm              = new ProjectForm(ladderProgram, AddressingServices.Instance);
                            projectForm.Status       = ProjectForm.ProgramStatus.Open;
                            projectForm.PathFile     = fileName;
                            projectForm.Program.Name = Path.GetFileNameWithoutExtension(fileName);
                            projectForm.MdiParent    = this;
                            projectForm.Show();
                            projectForm.SetText();
                        }
                        fileReader.Close();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error reading file! " + ex.InnerException.Message, "Open files ...", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    break;

                case ".a43":
                    try
                    {
                        MicIntegrationServices p = new MicIntegrationServices();
                        String readContent       = p.ConvertHex2String(fileName);
                        if (CheckPassword(readContent))
                        {
                            ReadExecutable(readContent, fileName.Substring(fileName.LastIndexOf(@"\") + 1, fileName.Length - fileName.LastIndexOf(@"\") - 1));
                        }
                    }
                    catch
                    {
                        MessageBox.Show("Unknown file format!", "Open files ...", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    break;

                default:
                    MessageBox.Show("Unknown file format!", "Open files ...", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    break;
                }
            }
        }
Exemplo n.º 2
0
        private void mnuMicrocontrollerCommunicationUpload_Click(object sender, EventArgs e)
        {
            MicIntegrationServices micIntegrationServices = new MicIntegrationServices();

            try
            {
                string content = micIntegrationServices.ReadsViaUSB();
                if (CheckPassword(content))
                {
                    ReadExecutable(content, "No Name");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }