Example #1
0
 void OnCommunications(DeviceLoader sender, Direction direction, string content)
 {
     if (InvokeRequired)
     {
         BeginInvoke(new Action(() => { OnCommunications(sender, direction, content); }));
         return;
     }
     // Safe to use UI
     LogMessage(m_txtComms, String.Format("{0} {1}", (direction == Direction.Input) ? "<" : ">", content));
 }
Example #2
0
 void OnConnectionStateChanged(DeviceLoader sender, ConnectionState state)
 {
     if (InvokeRequired)
     {
         BeginInvoke(new Action(() => { OnConnectionStateChanged(sender, state); }));
         return;
     }
     // Safe to use UI
     UpdateUI();
     LogMessage(m_txtMessages, String.Format("Programmer {0}", state));
 }
Example #3
0
        public MainForm()
        {
            InitializeComponent();
            m_loader = new DeviceLoader();
            m_loader.ConnectionStateChanged += OnConnectionStateChanged;
            m_loader.Error          += OnError;
            m_loader.Communications += OnCommunications;
            m_loader.Progress       += OnProgress;
            // Populate known EEPROM types
            m_eeproms = new Dictionary <string, EEPROM>();
            m_eeproms.Add(
                "25AA640A",
                new EEPROM(ConnectionType.SPI, 5, 13, 2)
                );
            m_eeproms.Add(
                "25AA1024",
                new EEPROM(ConnectionType.SPI, 8, 17, 3)
                );
            // Populate lists
            m_lstChipType.Items.Add(ConnectionType.I2C.ToString());
            m_lstChipType.Items.Add(ConnectionType.SPI.ToString());
            for (int i = 0; i <= 8; i++)
            {
                m_lstPageSize.Items.Add((1 << i).ToString());
            }
            for (int i = 0; i <= 7; i++)
            {
                m_lstCapacity.Items.Add((1 << i).ToString() + "K");
            }
            for (int i = 1; i <= 4; i++)
            {
                m_lstAddressSize.Items.Add(i.ToString());
            }
            // Populate the list of available COM ports
            List <string> ports = new List <string>(SerialPort.GetPortNames());

            ports.Sort();
            m_lstPort.Items.AddRange(ports.ToArray());
            if (m_lstPort.Items.Count > 0)
            {
                m_lstPort.SelectedIndex = 0;
            }
            // Do EEPROM last, it will trigger changes in other fields
            foreach (string name in m_eeproms.Keys)
            {
                m_lstEEPROM.Items.Add(name);
            }
            m_lstEEPROM.SelectedIndex = 0;
        }
Example #4
0
 void OnError(DeviceLoader sender, string message, Exception ex)
 {
     if (InvokeRequired)
     {
         BeginInvoke(new Action(() => { OnError(sender, message, ex); }));
         return;
     }
     // Safe to use UI
     if (ex != null)
     {
         message = message + "\n" + ex.Message;
     }
     LogMessage(m_txtMessages, "ERROR: " + message + "\n");
     MessageBox.Show(message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
 }
Example #5
0
 void OnProgress(DeviceLoader sender, ProgressState state, int position, int target, string message)
 {
     if (InvokeRequired)
     {
         BeginInvoke(new Action(() => { OnProgress(sender, state, position, target, message); }));
         return;
     }
     // Safe to use UI
     m_progress.Maximum = target;
     m_progress.Value   = position;
     if (message != null)
     {
         LogMessage(m_txtMessages, message);
     }
 }