public void Close() { if (m_Initilized) { m_SerialInterface.Close(); m_Target.Dispose(); m_Initilized = false; } }
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(); }