Exemple #1
0
 public static bool StartHalfKay(uint Serialnumber)
 {
     using (var watcher = new TeensyWatcher())
     {
         var Teensy = watcher.ConnectedDevices.FirstOrDefault(d => d.Serialnumber == Serialnumber);
         if (Teensy == null)
         {
             return(false); // No device with given sn found
         }
         if (Teensy.Type == USB_Device.type.HalfKay)
         {
             return(true); // HalfKay already running on the device
         }
         if (Teensy.Type != USB_Device.type.UsbSerial)
         {
             return(false); // Unsupported USB mode
         }
         //Start HalfKay
         using (var port = new SerialPort(Teensy.Port))
         {
             port.Open();
             port.BaudRate = 134; //This will switch the board to HalfKay. Don't try to access port after this...
         }
     }
     return(true);
 }
Exemple #2
0
        static void Main(string[] args)
        {
            // Two test files 
            string file1 = "blink_slow.hex";
            string file2 = "blink_fast.hex";

            string testfile = file2;

            // Define the board to be programmed (all boards are implemented but currently only Teensy 3.1 is tested) 
            var Board = PJRC_Board.Teensy_31;

            // 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(testfile))
            {
                // 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...
                               
                Console.WriteLine("- Starting Bootloader for Teensy {0}...", 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 {0}...", testfile);
                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) ;
            }
        }
Exemple #3
0
 public static bool StartHalfKay(uint Serialnumber)
 {
     using (var watcher = new TeensyWatcher())
     {
         var Teensy = watcher.ConnectedDevices.FirstOrDefault(d => d.Serialnumber == Serialnumber);
         if (Teensy == null) return false; // No device with given sn found
         if (Teensy.Type == USB_Device.type.HalfKay) return true; // HalfKay already running on the device
         if (Teensy.Type != USB_Device.type.UsbSerial) return false; // Unsupported USB mode
     
         //Start HalfKay                 
         using (var port = new SerialPort(Teensy.Port))
         {
             port.Open();                  
             port.BaudRate = 134; //This will switch the board to HalfKay. Don't try to access port after this...                   
         }
     }
     return true; 
 }        
Exemple #4
0
        static void Main(string[] args)
        {
            var Watcher = new TeensyWatcher();
            Watcher.ConnectionChanged += ConnectedTeensiesChanged; //Connect an eventhandler to get information about changes (optional) 

            // Display currently connected Teensies
            Console.WriteLine("Currently the following Teensies are connected:");
            foreach (var Teensy in Watcher.ConnectedDevices)
            {
                if (Teensy.Type == USB_Device.type.UsbSerial)
                {
                    Console.WriteLine("USBSerial: Serialnumber {0}, on {1}", Teensy.Serialnumber, Teensy.Port);
                }
                else Console.WriteLine("HalfKay: Serialnumber {0}", Teensy.Serialnumber);
            }
            
            // Here is a good place to construct a SerialPort Object
            // For the sake of simplicity lets take the first one from the list
            var myTeensy = Watcher.ConnectedDevices.FirstOrDefault();
            if (myTeensy != null && myTeensy.Type == USB_Device.type.UsbSerial)
            {
                using (var Com = new SerialPort(myTeensy.Port))
                {
                    // lets talk to our Teensy: 
                    Com.Open();
                    Com.WriteLine("Hello Teensy");
                    Com.Close();
                }
            }

            Console.WriteLine("\nPlug Teensies in / out to see the watcher in action\n\nPress any key to exit");
            while (!Console.KeyAvailable) ;

            // CleanUp 
            Watcher.ConnectionChanged -= ConnectedTeensiesChanged;
            Watcher.Dispose();
        }
Exemple #5
0
 public ConnectionChangedEventArgs(TeensyWatcher.ChangeType type, USB_Device changedDevice)
 {
     this.changeType = type;
     this.changedDevice = changedDevice;
 }