Esempio n. 1
0
        //-------------------------------------------------------------------------------------------------------------------
        //In a real application you would use this eventhandler to inform the user, connect / disconnect the SerialPort etc..
        //
        static void ConnectedTeensiesChanged(object sender, ConnectionChangedEventArgs e)
        {
            // Write information about the added or removed Teensy to the console

            USB_Device Teensy = e.changedDevice;

            switch (Teensy.Type)
            {
            case USB_Device.type.HalfKay:
                if (e.changeType == TeensyWatcher.ChangeType.add)
                {
                    Console.WriteLine("Teensy {0} running HalfKay", Teensy.Serialnumber);
                }
                else
                {
                    Console.WriteLine("Teensy {0} removed", Teensy.Serialnumber);
                }
                break;

            case USB_Device.type.UsbSerial:
                if (e.changeType == TeensyWatcher.ChangeType.add)
                {
                    Console.WriteLine("Teensy {0} connected on {1}", Teensy.Serialnumber, Teensy.Port);
                }
                else
                {
                    Console.WriteLine("Teensy {0} removed from {1}", Teensy.Serialnumber, Teensy.Port);
                }
                break;
            }
        }
Esempio n. 2
0
 private void ConnectedTeensiesChanged(object sender, ConnectionChangedEventArgs e)
 {
     Dispatcher.Invoke(() =>
     {
         cbTeensy.Items.Clear();
         foreach (var Teensy in watcher.ConnectedDevices.Where(t => t.UsbType == USB_Device.USBtype.UsbSerial))
         {
             cbTeensy.Items.Add(Teensy);
         }
         cbTeensy.SelectedIndex = 0;
         Teensy = cbTeensy.SelectedItem as USB_Device;
     }
                       );
 }
Esempio n. 3
0
        private void Upload(USB_Device board)
        {
            var Board        = PJRC_Board.Teensy_35;
            var FlashImage   = SharpUploader.GetEmptyFlashImage(Board);
            var parsedResult = SharpHexParser.ParseStream(File.OpenText(firmareToUpload), FlashImage);

            if (!parsedResult)
            {
                MessageBox.Show("Error parsing firmware file.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            // USB_Device Teensy = Watcher.ConnectedDevices.FirstOrDefault();
            var mode = SharpUploader.StartHalfKay(board.Serialnumber);

            if (!mode)
            {
                MessageBox.Show("Error setting mode on board.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            int result = SharpUploader.Upload(FlashImage, Board, board.Serialnumber, reboot: true);

            switch (result)
            {
            case 0:
                MessageBox.Show("Success", "Ok", MessageBoxButton.OK, MessageBoxImage.Information);
                break;

            case 1:
                MessageBox.Show("Board not found", "Problem uploading", MessageBoxButton.OK, MessageBoxImage.Warning);
                break;

            case 2:
                MessageBox.Show("Error during firmware updated", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                break;
            }
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            // Select the board to be programmed
            //var Board = PJRC_Board.Teensy_36;
            //var Board = PJRC_Board.Teensy_35;
            //var Board = PJRC_Board.Teensy_31;
            //var Board = PJRC_Board.Teensy_30;
            var Board = PJRC_Board.Teensy_LC;

            string hexFile;

            //select the firmware to download
            switch (Board)
            {
            case PJRC_Board.Teensy_36:
                hexFile = "blink_36.hex";
                Console.WriteLine("Selected Board: Teensy 3.6");
                break;

            case PJRC_Board.Teensy_35:
                hexFile = "blink_35.hex";
                Console.WriteLine("Selected Board: Teensy 3.5");
                break;

            case PJRC_Board.Teensy_31:
                hexFile = "blink_31.hex";
                Console.WriteLine("Selected Board: Teensy 3.1 / 2");
                break;

            case PJRC_Board.Teensy_LC:
                hexFile = "blink_LC.hex";
                Console.WriteLine("Selected Board: Teensy LC");
                break;

            default:
                Console.WriteLine("no hex file for slected board available. Exiting...");
                Console.WriteLine("\nPress any key");
                while (!Console.KeyAvailable)
                {
                    ;
                }
                return;
            }

            // Check if file is available
            if (!File.Exists(hexFile))
            {
                Console.WriteLine($"Specified hex file ({hexFile}) not found. Exiting...");
                Console.WriteLine("\nPress any key");
                while (!Console.KeyAvailable)
                {
                    ;
                }
                return;
            }
            Console.WriteLine($"Using firmwarefile {hexFile} for download test");


            // Obtain an empty flash image with the correct size and all bytes cleared (set to 0xFF)
            var FlashImage = SharpUploader.GetEmptyFlashImage(Board);

            using (var HexStream = File.OpenText(hexFile))
            {
                // parse the file and write output to the image
                SharpHexParser.ParseStream(HexStream, FlashImage);
                HexStream.Close();
            }

            using (var Watcher = new TeensyWatcher())
            {
                USB_Device Teensy = Watcher.ConnectedDevices.FirstOrDefault(); //We take the first Teensy we find...

                if (Teensy == null)
                {
                    Console.WriteLine("No Teensy found on the USB tree. Exiting....");
                    Console.WriteLine("\nPress any key");
                    while (!Console.KeyAvailable)
                    {
                        ;
                    }
                    return;
                }

                Console.WriteLine($"- Starting Bootloader for Teensy {Teensy.Serialnumber}...");
                bool res = SharpUploader.StartHalfKay(Teensy.Serialnumber);
                Console.WriteLine(res ? "  OK" : "  Bootloader not running");

                // Upload firmware image to the board and reboot
                Console.WriteLine($"\n- Uploading {hexFile}...");
                int result = SharpUploader.Upload(FlashImage, Board, Teensy.Serialnumber, reboot: true);

                // Show result
                switch (result)
                {
                case 0:
                    Console.WriteLine("  Successfully uploaded");
                    break;

                case 1:
                    Console.WriteLine("  Found no board with running HalfKay. Did you press the programming button?");
                    Console.WriteLine("  Aborting...");
                    break;

                case 2:
                    Console.WriteLine("  Error during upload.");
                    Console.WriteLine("  Aborting...");
                    break;
                }
                Console.WriteLine("\nPress any key");
                while (!Console.KeyAvailable)
                {
                    ;
                }
            }
        }