Esempio n. 1
0
 public MainWindow()
 {
     InitializeComponent();
     _watcher = new TeensyWatcher();
     foreach (var device in _watcher.ConnectedDevices)
     {
         Boards.Add(device);
     }
     _watcher.ConnectionChanged += Watcher_ConnectionChanged;
 }
Esempio n. 2
0
        public MainWindow()
        {
            InitializeComponent();

            cnv.Width  = columns;
            cnv.Height = 8 * rows;

            watcher = new TeensyWatcher();
            watcher.ConnectionChanged += ConnectedTeensiesChanged;   // get notifications about plugged in/out Teensies
            ConnectedTeensiesChanged(null, null);                    // fill combobox initially

            worker.DoWork += doWork;
        }
Esempio n. 3
0
        public frmFirmware(frmMain CallingForm)
        {
            InitializeComponent();
            mf = CallingForm;

            watcher = new TeensyWatcher(SynchronizationContext.Current);
            watcher.ConnectedTeensies.CollectionChanged += ConnectedTeensiesChanged;
            foreach (var teensy in watcher.ConnectedTeensies)
            {
                lbTeensies.Items.Add(teensy);
            }
            if (lbTeensies.Items.Count > 0)
            {
                lbTeensies.SelectedIndex = 0;
            }
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            var watcher = new TeensyWatcher();
            var teensy  = watcher.ConnectedDevices.FirstOrDefault(); // Use the first teensy we find on the Bus

            SerialPort port = new SerialPort(teensy.Port, 115200);   // open a serial port for the teensy

            port.Open();

            while (!Console.KeyAvailable)
            {
                Console.WriteLine(port.ReadLine());
            }

            port.Close();
        }
Esempio n. 5
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();
        }
Esempio n. 6
0
        public bool connect()
        {
            var watcher = new TeensyWatcher();

            teensy = watcher.ConnectedDevices
                     .FirstOrDefault();

            if (teensy != null && !String.IsNullOrEmpty(teensy.Port))
            {
                try
                {
                    port = new SerialPort(teensy.Port);
                    port.WriteBufferSize = 1024 * 30;
                    // port.WriteTimeout = 1000;
                    port.Open();
                    //port.Close();
                }
                catch
                {
                    port?.Dispose();
                    port     = null;
                    TeensyID = $"Can't open port {teensy.BoardId}";
                    return(false);
                }
                TeensyID     = $"{teensy.BoardId} connected";
                serialnumber = teensy.Serialnumber;
                board        = teensy.BoardType;
                isConnected  = true;
                return(true);
            }
            else
            {
                TeensyID = $"No compatible Teensy found";
                return(false);
            }
        }
Esempio n. 7
0
 private static void Main(string[] args)
 {
     _watcher = new TeensyWatcher(250);
     _watcher.ConnectionChanged += WatcherOnConnectionChanged;
     Console.ReadLine();
 }
Esempio n. 8
0
        public bool isOpen => port != null && port.IsOpen;  // Do we have an open connection to the Teensy?

        public IFace()
        {
            watcher = new TeensyWatcher();
            watcher.connectionChanged += connectionChanged;
            connectionChanged(null, null);
        }
Esempio n. 9
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)
                {
                    ;
                }
            }
        }