Esempio n. 1
0
 public Motor(Cpu.Pin pin, bool initialState = false)
 {
     if (!IsMotorPin(pin))
     {
         throw new IndexOutOfRangeException(string.Concat(pin.ToString(), " is not a valid pin for motor usage."));
     }
     _Enabled = initialState;
     Port     = new OutputPort(pin, _Enabled);
 }
        public MFTestResults HWObjectPinTest()
        {
            int i;

            if (Microsoft.SPOT.Hardware.SystemInfo.SystemID.SKU != 3)  //The Emulator on Windows Host
            {
                Log.Comment("Emulate Hardware test is restricted to emulator");
                return(MFTestResults.Skip);
            }
            else
            {
                Log.Comment("EmulateHardware Pin Test Starting");
            }
            ArrayList portObjectList = new ArrayList();

            try
            {
                Log.Comment("Assign all pins to OutputPort");

                for (i = 0; i < pinObjectList.Count; ++i)
                {
                    Cpu.Pin pin = (Cpu.Pin)pinObjectList[i];

                    if (pin.Equals(Cpu.Pin.GPIO_NONE))
                    {
                        Log.Comment("Skip creation of port with GPIO_NONE throws exception. Tested below in this function");
                        continue;
                    }

                    portObjectList.Add(new OutputPort(pin, false));
                }
            }
            catch (Exception E)
            {
                string str = "Unable to create output port object with pin " +
                             E.Message;
                Log.Comment(str);

                return(MFTestResults.Fail);
            }

            // Test that creation  of port with GPIO_NONE throws exception.

            try
            {
                Log.Comment("Creating Output port with Cpu.Pin.GPIO_NONE. Should through exception");
                portObjectList.Add(new OutputPort(Cpu.Pin.GPIO_NONE, false));
            }
            catch (Exception E)
            {
                Log.Comment("Catching exception as result of creation OutputPort with Cpu.Pin.GPIO_NONE" + E.Message);
            }

            int exceptionCount = 0;

            for (i = 0; i < pinObjectList.Count; ++i)
            {
                Cpu.Pin pin = (Cpu.Pin)pinObjectList[i];

                try
                {
                    portObjectList.Add(new OutputPort(pin, false));
                    Log.Comment("Using pin " + pin.ToString() + " in object instance unexpected success");
                }
                catch
                {
                    exceptionCount++;
                }
            }
            if (exceptionCount != (pinObjectList.Count))
            {
                Log.Comment("A pin reservation succeeded and expected to fail");
                return(MFTestResults.Fail);
            }

            return(MFTestResults.Pass);
        } //HWObjectDispose
Esempio n. 3
0
        public static void Main()
        {
            Debug.Print("\n\n");
            Debug.Print("Hello world - i'm trying to find what are hidden to this firmware ");
            Debug.Print("\n\n");

            HardwareProvider provider = HardwareProvider.HwProvider;

            var cnt = provider.GetAnalogChannelsCount();

            for (int i = 0; i < cnt; i++)
            {
                var     channel    = (Cpu.AnalogChannel)i;
                Cpu.Pin pin        = provider.GetAnalogPinForChannel(channel);
                int[]   precisions = provider.GetAvailablePrecisionInBitsForChannel(channel);

                Debug.Print("AnalogChannel" + channel + ": pin=" + pin.ToString() + "(" + STM32F411RE.Hardware.Pin.GetPinName(pin) + "): precisions=" + precisions[0].ToString() + " bit");
            }
            Debug.Print("\n\n");

            cnt = 0;
            cnt = provider.GetAnalogOutputChannelsCount();
            for (int i = 0; i < cnt; i++)
            {
                var     channel    = (Cpu.AnalogOutputChannel)i;
                Cpu.Pin pin        = provider.GetAnalogOutputPinForChannel(channel);
                int[]   precisions = provider.GetAvailableAnalogOutputPrecisionInBitsForChannel(channel);

                Debug.Print("AnalogOutputChannel" + ": pin=" + pin.ToString() + "(" + STM32F411RE.Hardware.Pin.GetPinName(pin) + "): precisions=" + precisions[0].ToString() + " bit");
            }
            Debug.Print("\n\n");

            /* find pwm */
            cnt = 0;
            cnt = provider.GetPWMChannelsCount();
            for (int i = 0; i < cnt; i++)
            {
                var     channel = (Cpu.PWMChannel)i;
                Cpu.Pin pin     = provider.GetPwmPinForChannel(channel);
                Debug.Print("PWMChannel" + channel + ": pin=" + pin.ToString() + "(" + STM32F411RE.Hardware.Pin.GetPinName(pin) + ")");
            }
            Debug.Print("\n\n");

            /*find uart */
            cnt = 0;
            cnt = provider.GetSerialPortsCount();
            for (int i = 0; i < cnt; i++)
            {
                string  comPort = Serial.COM1.Substring(0, 3) + (i + 1);
                Cpu.Pin rxPin, txPin, ctsPin, rtsPin;
                provider.GetSerialPins(comPort, out rxPin, out txPin, out ctsPin, out rtsPin);
                uint max, min;
                provider.GetBaudRateBoundary(i, out max, out min);

                Debug.Print(comPort + ": (rx, tx, cts, rts)=(" +
                            STM32F411RE.Hardware.Pin.GetPinName(rxPin) + ", " +
                            STM32F411RE.Hardware.Pin.GetPinName(txPin) + ", " +
                            STM32F411RE.Hardware.Pin.GetPinName(ctsPin) + ", " +
                            STM32F411RE.Hardware.Pin.GetPinName(rtsPin) + ")" +
                            " baud=" + min + "..." + max);
            }
            Debug.Print("\n\n");
            /* find i2c */
            Cpu.Pin i2cscl, i2csda;
            provider.GetI2CPins(out i2cscl, out i2csda);
            Debug.Print("I2C module:(scl value=" + i2cscl.ToString() + "(" + STM32F411RE.Hardware.Pin.GetPinName(i2cscl) + "),sda=" + i2csda.ToString() + "(" + STM32F411RE.Hardware.Pin.GetPinName(i2csda) + "));");
            Debug.Print("\n\n");

            /* find SPI */
            var spicnt = provider.GetSpiPortsCount();

            for (int i = 0; i < spicnt; i++)
            {
                var module = (SPI.SPI_module)i;

                Cpu.Pin msk, miso, mosi;
                provider.GetSpiPins(module, out msk, out miso, out mosi);
                Debug.Print("SPI_module" + (i + 1) + ": (msk=" + msk.ToString() + "(" + STM32F411RE.Hardware.Pin.GetPinName(msk) + "), miso=" + miso.ToString() + "(" + STM32F411RE.Hardware.Pin.GetPinName(miso) + "), mosi=" + mosi.ToString() + "(" + STM32F411RE.Hardware.Pin.GetPinName(mosi) + "));");
            }
            Debug.Print("\n\n");

            UsbController[] controllers = UsbController.GetControllers();
            for (int i = 0; i < controllers.Length; i++)
            {
                Debug.Print("USB" + i + ": " + Convert(controllers[i].Status));
                Thread.Sleep(500);
            }

            Debug.Print("\n\n");
            Debug.Print("Finished check of hardware ");
        }