コード例 #1
0
ファイル: MFDeployForm.cs プロジェクト: yisea123/NETMF-LPC
        private MFPortDefinition GetSelectedItem()
        {
            if (comboBoxDevice.SelectedItem == null && comboBoxDevice.Text.Length == 0)
            {
                return(null);
            }

            MFPortDefinition port = comboBoxDevice.SelectedItem as MFPortDefinition;

            if (port == null)
            {
                ArgumentParser parser = new ArgumentParser();
                string         err;

                if (parser.ValidateArgs("/I:TcpIp:" + comboBoxDevice.Text, out err))
                {
                    port = parser.Interface;
                }
            }

            if (port == null)
            {
                MessageBox.Show(Properties.Resources.ErrorInvalidDevice, Properties.Resources.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                comboBoxDevice.SelectionStart  = 0;
                comboBoxDevice.SelectionLength = comboBoxDevice.Text.Length;
                comboBoxDevice.Focus();
            }
            return(port);
        }
コード例 #2
0
 public MfTargetDevice(MFPortDefinition port, MFDevice device)
 {
     _port   = port;
     _device = device;
     _tc     = App.Kernel.Get <TelemetryClient>();
     Task.Run(() => InitializeAsync());
 }
コード例 #3
0
ファイル: USBMonitor.cs プロジェクト: atav32/Stasis-Bot
        /// <summary>
        /// Connects to the device at the specified port
        /// </summary>
        /// <param name="port"></param>
        public void Connect(MFPortDefinition port)
        {
            this._device              = new MFDeploy().Connect(port);
            this._device.OnDebugText += new EventHandler <DebugOutputEventArgs>(Device_OnDebugText);

            this.Connected(this, EventArgs.Empty);
        }
コード例 #4
0
        public static void Main(params string[] args)
        {
            bool             fRunUI              = true;
            MFPortDefinition transport           = null;
            MFPortDefinition transportTinyBooter = null;

            if (args.Length > 0)
            {
                try
                {
                    string error;
                    string all_args = NormalizeArgs(args);

                    ArgumentParser parser = new ArgumentParser();
                    // error condition
                    if (!parser.ValidateArgs(all_args, out error))
                    {
                        fRunUI = false;
                        NativeMethods.AllocConsole( );
                        Console.WriteLine(Properties.Resources.ErrorPrefix + error);
                    }
                    else if (parser.Command != (ArgumentParser.Commands)(-1))
                    {   // valid command, no UI
                        fRunUI = false;
                        NativeMethods.AllocConsole( );
                        parser.Execute();
                    }
                    else if (parser.Interface != null && parser.Interface.Transport != (TransportType)(-1))
                    {    // no command, but interface defined, so update UI transport field
                        transport           = parser.Interface;
                        transportTinyBooter = parser.TinybtrInterface;
                    }
                }
                catch (Exception e)
                {
                    NativeMethods.AllocConsole( );
                    Console.WriteLine(Properties.Resources.ErrorPrefix + e.Message);
                }
            }

            if (fRunUI)
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Form1 form = new Form1();
                form.Transport           = transport;
                form.TransportTinyBooter = transportTinyBooter;
                Application.Run(form);
            }
        }
コード例 #5
0
    private MFPortDefinition FindHeroPortDef()
    {
        MFPortDefinition retval = null;
        ReadOnlyCollection <MFPortDefinition> list = null;

        list = m_deploy.EnumPorts(TransportType.USB);

        if (list.Count > 0)
        {
            retval = list[0];
        }

        return(retval);
    }
コード例 #6
0
        private void AddDeployableTarget(MFPortDefinition item)
        {
            var device = ConnectToNetmfDevice(item);

            if (device != null)
            {
                if (!_devices.Any(x => x is MfTargetDevice && ((MfTargetDevice)x).Name == item.Name && ((MfTargetDevice)x).Transport == item.Transport && ((MfTargetDevice)x).Port == item.Port))
                {
                    lock (_devices)
                    {
                        _devices.Add(new MfTargetDevice(item, device));
                    }
                }
            }
        }
コード例 #7
0
        private MFDevice ConnectToNetmfDevice(MFPortDefinition port)
        {
            MFDevice result = null;

            try
            {
                result = _deploy.Connect(port);
            }
            catch
            {
                MessageBox.Show(
                    "Failed to connect to device. You may need to reset your board or restart this program.", "Error",
                    MessageBoxButton.OK);
                result = null;
            }
            return(result);
        }
コード例 #8
0
ファイル: MFDeployForm.cs プロジェクト: yisea123/NETMF-LPC
        private void OnDefaultSerialPortChange(object sender, EventArgs ea)
        {
            ToolStripMenuItem tsi = sender as ToolStripMenuItem;

            if (tsi != null)
            {
                MFSerialPort port = tsi.Tag as MFSerialPort;
                if (port != null)
                {
                    m_defaultSerialPort.Checked = false;
                    Properties.Settings.Default.DefaultSerialPort = port.Name;
                    tsi.Checked           = true;
                    m_defaultSerialPort   = tsi;
                    m_transportTinyBooter = port;
                }
            }
        }
コード例 #9
0
        private void UpdateNetduinoList()
        {
            this.netduinoSelect.Items.Clear();
            foreach (var obj in this.mfDeployEngine.DeviceList)
            {
                MFPortDefinition port = (MFPortDefinition)obj;
                if (port.Name.Contains("Netduino"))
                {
                    this.netduinoSelect.Items.Add(port);
                }
            }

            if (this.netduinoSelect.Items.Count > 0)
            {
                this.netduinoSelect.SelectedIndex = 0;
            }
        }
コード例 #10
0
ファイル: MFDeployForm.cs プロジェクト: yisea123/NETMF-LPC
        private MFDevice ConnectToSelectedDevice()
        {
            if (m_device != null)
            {
                Interlocked.Increment(ref m_deviceRefCount);
            }
            else
            {
                MFPortDefinition port = null;
                this.Invoke((MethodInvoker) delegate
                {
                    port = GetSelectedItem();
                });

                if (port != null)
                {
                    try
                    {
                        m_device = m_deploy.Connect(port, port is MFTcpIpPort ? m_transportTinyBooter : null);

                        if (m_device != null)
                        {
                            comboBoxTransport.Invoke((MethodInvoker) delegate
                            {
                                comboBoxDevice.Enabled           = false;
                                comboBoxTransport.Enabled        = false;
                                connectToolStripMenuItem.Enabled = false;
                            });

                            m_device.OnDebugText += new EventHandler <DebugOutputEventArgs>(OnDbgTxt);
                            Interlocked.Increment(ref m_deviceRefCount);
                        }
                    }
                    catch (Exception exc)
                    {
                        DumpToOutput(Properties.Resources.ErrorPrefix + exc.Message);
                    }
                }
            }
            return(m_device);
        }
コード例 #11
0
        public static void Main(params string[] args)
        {
            bool             fRunUI              = true;
            MFPortDefinition transport           = null;
            MFPortDefinition transportTinyBooter = null;

            if (args.Length > 0)
            {
                try
                {
                    StringBuilder sb       = new StringBuilder();
                    string        all_args = "";
                    string        error;

                    foreach (string arg in args)
                    {
                        // take care of spaces in path names
                        if (arg.ToUpper().StartsWith(ArgumentParser.Commands.Deploy.ToString().ToUpper() + ArgumentParser.ArgSeparator))
                        {
                            string tmp = arg;
                            // place double quoutes around files
                            tmp = tmp.Replace(ArgumentParser.ArgSeparator.ToString(), ArgumentParser.ArgSeparator + "\"");
                            tmp = tmp.Replace(ArgumentParser.FileSeparator.ToString(), "\"" + ArgumentParser.FileSeparator + "\"");
                            sb.AppendFormat("{0}\"", tmp);
                        }
                        else
                        {
                            sb.AppendFormat("{0} ", arg);
                        }
                    }
                    all_args = sb.ToString().Trim();

                    ArgumentParser parser = new ArgumentParser();
                    // error condition
                    if (!parser.ValidateArgs(all_args, out error))
                    {
                        fRunUI = false;
                        Console.WriteLine(Properties.Resources.ErrorPrefix + error);
                    }
                    // valid command, no UI
                    else if (parser.Command != (ArgumentParser.Commands)(-1))
                    {
                        fRunUI = false;
                        parser.Execute();
                    }
                    // no command, but interface defined, so update UI transport field
                    else if (parser.Interface != null && parser.Interface.Transport != (TransportType)(-1))
                    {
                        transport           = parser.Interface;
                        transportTinyBooter = parser.TinybtrInterface;
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(Properties.Resources.ErrorPrefix + e.Message);
                }
            }

            if (fRunUI)
            {
                NativeMethods.FreeConsole();

                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Form1 form = new Form1();
                form.Transport           = transport;
                form.TransportTinyBooter = transportTinyBooter;
                Application.Run(form);
            }
        }
コード例 #12
0
ファイル: MFDeployForm.cs プロジェクト: yisea123/NETMF-LPC
        private void Form1_Load(object sender, EventArgs e)
        {
            comboBoxTransport.SelectedIndex = 0;
            m_deploy.OnDeviceListUpdate    += new EventHandler <EventArgs>(OnDeviceListUpdate);

            if (m_transport != null)
            {
                comboBoxDevice.Text = m_transport.Name;
            }

            richTextBoxOutput.ScrollToCaret();

            foreach (MFSerialPort pd in m_deploy.EnumPorts(TransportType.Serial))
            {
                ToolStripMenuItem ti = new ToolStripMenuItem(pd.Name);
                ti.Tag    = pd;
                ti.Click += new EventHandler(OnDefaultSerialPortChange);

                defaultSerialPortToolStripMenuItem.DropDownItems.Add(ti);

                if (Properties.Settings.Default.DefaultSerialPort == pd.Name)
                {
                    m_defaultSerialPort = ti;
                    ti.Checked          = true;

                    m_transportTinyBooter = pd;
                }
            }


            this.Height              += 110;
            richTextBoxOutput.Top    += 110;
            richTextBoxOutput.Height -= 110;

            listViewFiles.Visible = true;

            AddPlugIns(typeof(Debug.DebugPlugins).GetNestedTypes(), "Debug");

            foreach (string file in Properties.Settings.Default.MRUFiles)
            {
                bool fAddFiles = true;
                // validate the file set
                foreach (string f in file.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    string f1 = f.Trim();
                    if (f1.Length > 0 && !File.Exists(f1))
                    {
                        fAddFiles = false;
                    }
                }
                if (fAddFiles)
                {
                    comboBoxImageFile.Items.Add(file);
                }
            }

            try   { m_deploy.DiscoveryMulticastAddress = System.Net.IPAddress.Parse(Properties.Settings.Default.DiscoveryMulticastAddress); }
            catch { richTextBoxOutput.AppendText(string.Format(Properties.Resources.ErrorAppSettings, "DiscoveryMulticastAddress")); }

            m_deploy.DiscoveryMulticastPort  = Properties.Settings.Default.DiscoveryMulticastPort;
            m_deploy.DiscoveryMulticastToken = Properties.Settings.Default.DiscoveryMulticastToken;

            try   { m_deploy.DiscoveryMulticastAddressRecv = System.Net.IPAddress.Parse(Properties.Settings.Default.DiscoveryMulticastAddressRecv); }
            catch { richTextBoxOutput.AppendText(string.Format(Properties.Resources.ErrorAppSettings, "DiscoveryMulticastAddressRecv")); }

            m_deploy.DiscoveryMulticastTimeout = Properties.Settings.Default.DiscoveryMulticastTimeout;
            m_deploy.DiscoveryTTL = Properties.Settings.Default.DiscoveryTTL;

            try
            {
                string dir = Properties.Settings.Default.PlugIns;
                if (dir != null && dir.Length > 0)
                {
                    string plugin_dir = AppDomain.CurrentDomain.BaseDirectory + dir;

                    if (Directory.Exists(plugin_dir))
                    {
                        foreach (string file in Directory.GetFiles(plugin_dir, "*.dll"))
                        {
                            FileInfo fi = new FileInfo(file);

                            try
                            {
                                Assembly asm = Assembly.LoadFrom(file);

                                AddPlugIns(asm.GetTypes(), fi.Name.Substring(0, fi.Name.Length - 4));
                            }
                            catch
                            {
                                DumpToOutput(string.Format(Properties.Resources.ErrorUnableToInstallPlugIn, fi.Name));
                            }
                        }
                    }
                }
            }
            catch
            {
            }
        }