public bool Open(WcaInterfaceType type, string name, int baudrate)
        {
            if (!m_Initilized)
            {
                Debug.WriteLine(String.Format("WcaInterface::Open:{0}:{1}:{2}", type.ToString(), name, baudrate));

                switch (type)
                {
                case WcaInterfaceType.UART:
                    m_SerialInterface = new SerialInterface(name, baudrate, Parity.None, 8);
                    m_Initilized      = m_SerialInterface.Open();

                    Debug.WriteLine(String.Format("WcaInterface::Open:Result:{0}", m_Initilized));

                    if (m_Initilized)
                    {
                        m_Target = new Target();
                    }
                    break;

                case WcaInterfaceType.USB:
                    break;
                }
            }
            return(m_Initilized);
        }
Exemple #2
0
        public void Run(string com_port, string full_file_name)
        {
            bool abort = false;

            m_full_file_name = full_file_name;
            m_interface      = new WcaInterfaceLibrary.SerialInterface(com_port, globals.baud, Parity.None, 8);
            m_target         = new Target();
            m_interface.RegisterListener(this);

            Console.WriteLine("Wait until charger is ready.");

            if (m_interface.Open() && File.Exists(m_full_file_name))
            {
                while (!abort)
                {
                    if (Console.KeyAvailable)
                    {
                        ConsoleKey key = Console.ReadKey().Key;

                        switch (key)
                        {
                        case ConsoleKey.Escape:
                            abort = true;
                            break;
                        }
                    }

                    if (m_start_indication_received.WaitOne(2000))
                    {
                        m_start_indication_received.Reset();
                        Thread.Sleep(400);
                        GeneralCommand set_bl = new GeneralCommand(m_interface, 0x01, 0x24, new byte[] { 0x01, 0x03, 0x7D }, "keep bootloader running");
                        set_bl.RegisterListener(this);
                        m_target.Queue(set_bl);
                        m_target.Wait();
                        Thread.Sleep(500);
                        GetApplicationVersionSync();
                        Upload();
                        Thread.Sleep(200);
                        GetApplicationVersionSync();
                        Console.WriteLine("Flashing done.");
                        abort = true;
                    }
                }
            }
            else
            {
                Console.WriteLine("COM port cannot be opened or file does not exists. Pls. check both of them.");
            }

            m_interface.Close();
        }