public static void Main()
        {
            daq.Initialize(GoSockets.Socket1);

            var d0 = (GpioOutputPwm)daq.Add(new GpioOutputPwm(GpioId.D0));
            var d1 = (GpioOutputPwm)daq.Add(new GpioOutputPwm(GpioId.D1));
            var d2 = (GpioOutputPwm)daq.Add(new GpioOutputPwm(GpioId.D2));
            var d3 = (GpioOutputPwm)daq.Add(new GpioOutputPwm(GpioId.D3));
            var d4 = (GpioOutputPwm)daq.Add(new GpioOutputPwm(GpioId.D4_33v));
            var d5 = (GpioOutputPwm)daq.Add(new GpioOutputPwm(GpioId.D5));
            var d6 = (GpioOutputPwm)daq.Add(new GpioOutputPwm(GpioId.D6));
            var d7 = (GpioOutputPwm)daq.Add(new GpioOutputPwm(GpioId.D7));

            // Change the duty cyle of each PWM digital output one at a time
            var count = 3;

            while (count-- != 0)
            {
                var dutyCycle = 0.0f;
                for (; dutyCycle <= 1.0f; dutyCycle += 0.1f)
                {
                    for (GpioId id = 0; id < (GpioId)NwazetDAQ.MaxGpios; id++)
                    {
                        daq.Write((GpioOutputPwm)daq.GetGpio(id), dutyCycle);
                    }
                    Thread.Sleep(40);
                }
                for (; dutyCycle >= 0.1f; dutyCycle -= 0.1f)
                {
                    for (GpioId id = 0; id < (GpioId)NwazetDAQ.MaxGpios; id++)
                    {
                        daq.Write((GpioOutputPwm)daq.GetGpio(id), dutyCycle);
                    }
                    Thread.Sleep(40);
                }
            }

            Thread.Sleep(2000);

            // Change the duty cycle of multiple digital PWM outputs with one call
            d1.DutyCycle = 0.33f;
            d3.DutyCycle = 0.33f;
            d5.DutyCycle = 0.33f;
            d7.DutyCycle = 0.33f;

            daq.Write();

            Thread.Sleep(2000);

            daq.Remove(d0);
            daq.Remove(d1);
            daq.Remove(d2);
            daq.Remove(d3);
            daq.Remove(d4);
            daq.Remove(d5);
            daq.Remove(d6);
            daq.Remove(d7);
        }
Example #2
0
 public GpioInput(GpioId Id)
 {
     Identifier        = Id;
     Mode              = GpioMode.Input;
     Type              = GpioType.PushPull;
     ResistorType      = GpioResistorType.PullUp;
     AlternateFunction = GpioAlternateFunction.None;
     State             = false;
 }
Example #3
0
 public GpioOutput(GpioId Id, bool state = false)
 {
     Identifier        = Id;
     Mode              = GpioMode.Output;
     Type              = GpioType.PushPull;
     ResistorType      = GpioResistorType.None;
     AlternateFunction = GpioAlternateFunction.None;
     State             = state;
 }
 private void OnSwitchedOn(GpioId gpioPinId)
 {
     Console.WriteLine("SWITCH ON RECIEVED " + gpioPinId);
     if (_manager.CurrentPin != gpioPinId)
     {
         _manager.SelectPin(gpioPinId);
     }
     _manager.WriteToPin(GpioPinState.Low);
 }
Example #5
0
        public static void DigitalOutputPwmTest()
        {
            Log("DigitalOutputPwmTest begin");

            // No need to do this unless actually needed...
            // Example: switch from the default 1kHz frequency to 500Hz
            //daq.SetGpioPwmTimeBase(GpioId.D0, 500);
            //daq.SetGpioPwmTimeBase(GpioId.D1, 500);
            //daq.SetGpioPwmTimeBase(GpioId.D2, 500);
            //daq.SetGpioPwmTimeBase(GpioId.D3, 500);
            //daq.SetGpioPwmTimeBase(GpioId.D4, 500);
            //daq.SetGpioPwmTimeBase(GpioId.D5, 500);
            //daq.SetGpioPwmTimeBase(GpioId.D6, 500);
            //daq.SetGpioPwmTimeBase(GpioId.D7, 500);

            var d0 = (GpioOutputPwm)daq.Add(new GpioOutputPwm(GpioId.D0));
            var d1 = (GpioOutputPwm)daq.Add(new GpioOutputPwm(GpioId.D1));
            var d2 = (GpioOutputPwm)daq.Add(new GpioOutputPwm(GpioId.D2));
            var d3 = (GpioOutputPwm)daq.Add(new GpioOutputPwm(GpioId.D3));
            var d4 = (GpioOutputPwm)daq.Add(new GpioOutputPwm(GpioId.D4_33v));
            var d5 = (GpioOutputPwm)daq.Add(new GpioOutputPwm(GpioId.D5));
            var d6 = (GpioOutputPwm)daq.Add(new GpioOutputPwm(GpioId.D6));
            var d7 = (GpioOutputPwm)daq.Add(new GpioOutputPwm(GpioId.D7));

            var count = 3;

            while (count-- != 0)
            {
                var dutyCycle = 0.0f;
                for (; dutyCycle <= 1.0f; dutyCycle += 0.1f)
                {
                    for (GpioId id = 0; id < (GpioId)NwazetDAQ.MaxGpios; id++)
                    {
                        daq.Write((GpioOutputPwm)daq.GetGpio(id), dutyCycle);
                    }
                    Thread.Sleep(40);
                }
                for (; dutyCycle >= 0.1f; dutyCycle -= 0.1f)
                {
                    for (GpioId id = 0; id < (GpioId)NwazetDAQ.MaxGpios; id++)
                    {
                        daq.Write((GpioOutputPwm)daq.GetGpio(id), dutyCycle);
                    }
                    Thread.Sleep(40);
                }
            }

            daq.Remove(d0);
            daq.Remove(d1);
            daq.Remove(d2);
            daq.Remove(d3);
            daq.Remove(d4);
            daq.Remove(d5);
            daq.Remove(d6);
            daq.Remove(d7);
            Log("DigitalOutputPwmTest end");
        }
Example #6
0
 public GpioOutputPwm(GpioId Id)
 {
     Identifier        = Id;
     Mode              = GpioMode.Output;
     Type              = GpioType.PushPull;
     ResistorType      = GpioResistorType.PullUp;
     AlternateFunction = GpioAlternateFunction.OutputPwmMode;
     dutyCycle         = 0.0f;
 }
Example #7
0
 public void SetGpioPwmTimeBase(GpioId gpioId, ulong frequencykHz, UInt16 prescaler = 0)
 {
     lock (this) {
         var timeBase = (GpioTimeBase)Timers[(int)gpioId];
         timeBase.SetTimerFrequency(frequencykHz, prescaler);
         BasicTypeSerializer.Put(SendContext, (byte)Command.SetPwmTimeBase);
         timeBase.SerializeTimeBase(SendContext);
         Execute();
     }
 }
 public GpioInputInterrupt(
     GpioId Id,
     GpioResistorType resistorType = GpioResistorType.PullUp,
     GpioInterruptTrigger trigger  = GpioInterruptTrigger.Falling,
     UInt32 rolloverLimit          = DefaultInterruptCountRollOverLimit,
     bool enable = true)
 {
     if (Id == GpioId.D4_33v)
     {
         throw new NotSupportedException("GpioId.GpioD4_33v");
     }
     Identifier         = Id;
     Mode               = GpioMode.Input;
     Type               = GpioType.PushPull;
     ResistorType       = resistorType;
     AlternateFunction  = GpioAlternateFunction.InputInterrupt;
     Trigger            = trigger;
     Enable             = enable;
     RollOverCountLimit = rolloverLimit;
 }
Example #9
0
 public GpioTimeBase(GpioTimerId timer, GpioId gpioId)
 {
     if (timer == GpioTimerId.D0Timer ||
         timer == GpioTimerId.D1Timer ||
         timer == GpioTimerId.D2Timer ||
         timer == GpioTimerId.D3Timer ||
         timer == GpioTimerId.D4Timer ||
         timer == GpioTimerId.D5Timer ||
         timer == GpioTimerId.D6Timer ||
         timer == GpioTimerId.D7Timer)
     {
         TimerId   = timer;
         GpioPinId = gpioId;
     }
     else
     {
         throw new ArgumentOutOfRangeException("timer");
     }
     SetTimerFrequency(DefaultFrequencykHz);
 }
Example #10
0
 public void Read()
 {
     lock (this) {
         BasicTypeSerializer.Put(SendContext, (byte)Command.GetDigitalInputState);
         BasicTypeSerializer.Put(SendContext, (byte)GpioId.GpioCount);
         Execute();
         Receive();
         GpioId id = GpioId.GpioCount;
         while (true)
         {
             id = (GpioId)BasicTypeDeSerializer.Get(ReceiveContext);
             if (id == GpioId.GpioCount)
             {
                 break;
             }
             byte state = BasicTypeDeSerializer.Get(ReceiveContext);
             Gpios[(int)id].State = (state == 0) ? false : true;
         }
     }
 }
 private void OnProbeRecieved()
 {
     Console.WriteLine("StatusProbe RECIEVED ");
     try
     {
         GpioDeviceState data = new GpioDeviceState();
         for (int i = 1; i <= 40; i++)
         {
             GpioId currentPinId = GpioPinMapping.GetGpioId(i);
             if (currentPinId != GpioId.GPIOUnknown)
             {
                 //_manager.SelectPin (GpioPinMapping.GetGPIOId (i));
                 GpioPinState state = _manager.ReadFromPin(currentPinId);
                 data.GpioPinStates.Add(currentPinId, state);
                 //_manager.ReleasePin (currentPinId);
             }
         }
         data.TimeStamp = DateTime.UtcNow.Ticks;
         PiotHubProxy.Invoke <string>("CurrentStatus", data).ContinueWith(sendStatusTask =>
         {
             if (sendStatusTask.IsFaulted)
             {
                 Console.WriteLine("There was an error opening the connection:{0}",
                                   sendStatusTask.Exception.GetBaseException());
             }
             else
             {
                 Console.WriteLine(string.Format("Probe data sent: {0}", new DateTime(data.TimeStamp).ToLongDateString()));
             }
         });
     }
     catch (Exception ex)
     {
         Console.WriteLine("Exception : {0}" + ex.Message);
     }
 }
Example #12
0
 public Gpio GetGpio(GpioId Id)
 {
     lock (this) {
         return(Gpios[(int)Id]);
     }
 }