internal Pin11(TreehopperBoard device)
     : base(device, 11)
 {
     ioName =  "RB6";
 }
 internal Pin13(TreehopperBoard device)
     : base(device, 13)
 {
     ioName =  "RC0";
     AnalogIn = new AnalogIn(this);
 }
 internal Pin9(TreehopperBoard device) : base(device, 9)
 {
     ioName =  "RB5";
     AnalogIn = new AnalogIn(this);
 }
 internal Pin10(TreehopperBoard device)
     : base(device, 10)
 {
     ioName =  "RB4";
     AnalogIn = new AnalogIn(this);
 }
 internal AnalogOut(TreehopperBoard board)
 {
     Board = board;
 }
 internal Pin8(TreehopperBoard device)
     : base(device, 8)
 {
     ioName =  "RB7";
 }
 internal Pin5(TreehopperBoard device)
     : base(device, 5)
 {
     ioName =  "RC6";
     AnalogIn = new AnalogIn(this);
     Pwm = new Pwm(this);
 }
 internal Pin3(TreehopperBoard device)
     : base(device, 3)
 {
     ioName =  "RC4";
 }
 private bool PassesFilter(TreehopperBoard board)
 {
     if (SerialFilterIsEnabled && board.SerialNumber != SerialFilter)
         return false;
     if (NameFilterIsEnabled && board.Name != NameFilter)
         return false;
     return true;
 }
 internal SoftPwm(TreehopperBoard board, Pin pin)
 {
     this.Board = board;
     this.Pin = pin;
 }
        private void Scan()
        {
            // get a list of all current devices attached to the computer
            
           
            // Go through the list of existing Boards and remove any that no longer exist.
            List<TreehopperBoard> BoardsToRemove = new List<TreehopperBoard>();
            foreach(var board in Boards.ToList())
            {
                bool boardExistsInDeviceList = false;
                foreach (UsbRegistry regDevice in UsbDevice.AllDevices)
                {
                    if (regDevice.Vid == vid && regDevice.Pid == pid)
                    {
                        if(regDevice.Device != null)
                        {
                            TreehopperBoard newBoard = new TreehopperBoard(regDevice.Device);
                            if (newBoard.Equals(board))
                            {
                                boardExistsInDeviceList = true;
                            }
                        }
                        else
                        { // If this property reads null, it's probably because the board is open.
                            boardExistsInDeviceList = true;
                        }
                        
                    }
                }
                if (!boardExistsInDeviceList)
                {
                    BoardsToRemove.Add(board);
                }
            }

            foreach(var board in BoardsToRemove)
            {
                Boards.Remove(board);
                Debug.WriteLine("New board list has " + Boards.Count + " Boards");
            }
            

            // Now add any new boards
            foreach (UsbRegistry regDevice in UsbDevice.AllDevices)
            {
                if (regDevice.Vid == vid && regDevice.Pid == pid)
                {
                    if(regDevice.Device != null)
                    {
                        TreehopperBoard newBoard = new TreehopperBoard(regDevice.Device);
                        if (PassesFilter(newBoard))
                        {
                            // add the board to the list if it doesn't already exist
                            bool alreadyInList = false;
                            foreach (var board in Boards)
                            {
                                if (board.Equals(newBoard))
                                {
                                    alreadyInList = true;
                                }
                            }
                            if (!alreadyInList)
                            {
                                Boards.Add(newBoard);
                                Debug.WriteLine("Adding " + newBoard.ToString() + ". New board list has " + Boards.Count + " Boards");
                            }

                        }
                    }
                   
                }
            }
        }
 internal I2c(TreehopperBoard device)
 {
     this.device = device;
 }
 internal SoftPwmManager(TreehopperBoard board)
 {
     this.board = board;
     pins = new Dictionary<int, SoftPwmPinConfig>();
 }
 internal Pin14(TreehopperBoard device)
     : base(device, 14)
 {
     ioName = "RA5";
 }
 internal Pin6(TreehopperBoard device) : base(device, 6)
 {
     ioName =  "RC7";
     AnalogIn = new AnalogIn(this);
 }
 internal Pin2(TreehopperBoard device)
     : base(device, 2)
 {
     ioName =  "RC5";
     Pwm = new Pwm(this);
 }
 internal Pin7(TreehopperBoard device) : base(device, 7)
 {
     ioName =  "RC2";
     AnalogIn = new AnalogIn(this);
 }
 internal Pin4(TreehopperBoard device)
     : base(device, 4)
 {
     ioName =  "RC3";
     AnalogIn = new AnalogIn(this);
 }
 internal Pin(TreehopperBoard board, byte pinNumber)
 {
     this.board = board;
     this.PinNumber = pinNumber;
     interruptMode = PinInterruptMode.NoInterrupt;
     SoftPwm = new SoftPwm(Board, this);
 }