Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.

Adam Clifford's Content

There have been 12 items by Adam Clifford (Search limited from 29-March 23)


By content type

See this member's

Sort by                Order  

#30607 serializing a class to json

Posted by Adam Clifford on 12 June 2012 - 10:15 PM in Netduino Plus 2 (and Netduino Plus 1)

This is a great, after lots of headaches with the netduino helpers library this worked great. I just removed the serializing items as i had no need for them :)



#30430 Socket Exception

Posted by Adam Clifford on 08 June 2012 - 07:04 PM in Netduino Plus 2 (and Netduino Plus 1)

these are the exceptions

-		e	{System.Net.WebException}	System.Exception {System.Net.WebException}
+		InnerException	{System.Net.Sockets.SocketException}	System.Exception {System.Net.Sockets.SocketException}
		m_HResult	4278190080	int {uint}



#30370 Socket Exception

Posted by Adam Clifford on 07 June 2012 - 04:52 PM in Netduino Plus 2 (and Netduino Plus 1)

Here is the url I am trying to get to
var url = "http://www.adam-clifford.co.uk/api/values/GetTweetHeaders/efc5adb9f17040e1bcbade6e210a467b";



#30362 Socket Exception

Posted by Adam Clifford on 07 June 2012 - 01:43 PM in Netduino Plus 2 (and Netduino Plus 1)

Hi Nak, I have tried the http_Client and I got the same response, I cant remember the full request URL off of the top of my head as i am in work, but i will respond when I get home in a couple of hours. Adam



#30358 Socket Exception

Posted by Adam Clifford on 07 June 2012 - 10:14 AM in Netduino Plus 2 (and Netduino Plus 1)

Hi Mario,

The service is currently on the web, it is a simple REST service that returns JSON based on the requests.

My Netduino is trying to consume it.

the point at which I get the error is
using (var response = (HttpWebResponse)request.GetResponse())
it errors out and doesn't hit the next lines.

the inner exception is of type SocketExeption.

Adam



#30327 Socket Exception

Posted by Adam Clifford on 06 June 2012 - 10:00 PM in Netduino Plus 2 (and Netduino Plus 1)

Hi All,

I am trying to run a web service that I have built in connection with a project I am building. However I cannot for the life of me get my netduino to actually talk to my service.

Here is the code, does it look bad?
using (var request = (HttpWebRequest)WebRequest.Create(url))
            {
                request.Method = "GET";
                request.Accept = "application/json";
                request.UserAgent = "OomooTweetNetduino";
                try
                {
                    using (var response = (HttpWebResponse)request.GetResponse())
                    {
                        if (response.StatusCode == HttpStatusCode.OK)
                        {
                            Debug.Print(response.StatusCode.ToString());

                            var textStream = response.GetResponseStream();

                            byte[] buffer = new byte[textStream.Length];

                            var count = textStream.Read(buffer, 0, int.Parse(textStream.Length.ToString()));

                            char[] chars = Encoding.UTF8.GetChars(buffer);

                            //var s = new string(chars).TrimEnd('

                            Debug.Print(new string(chars));
                        }

                    }

                    return true;

                }
                catch (Exception e)
                {
                    WriteAllErrors(e);
                    return false;
                }

            }



#16323 SQLite

Posted by Adam Clifford on 04 August 2011 - 12:58 PM in Netduino Plus 2 (and Netduino Plus 1)

please do tell :)



#15957 Rotary Encoder Switch class

Posted by Adam Clifford on 27 July 2011 - 07:23 AM in General Discussion

Thanks Dan I am using the one from sparkfun http://www.sparkfun.com/products/9117 Adam Clifford



#15926 Rotary Encoder Switch class

Posted by Adam Clifford on 26 July 2011 - 03:33 PM in General Discussion

Hi All,

Here is a state machine based rotary encoder switch with push button that is interrupt bassed.

you supply the two pins that output the pulses (grey code) and the pin that is used for the push switch, and when the the switch turns the class fires an event based upon the direction of motion, (clockwise or anti clockwise)

here is the code any improvements feel free to point out.
using System;
using Microsoft.SPOT.Hardware;

namespace RotaryEncoderSwitch
{
    public class RotarySwitch
    {
        private static readonly bool[] stateOne = new bool[2] {false, false};
        private static readonly bool[] stateTwo = new bool[2] {false, true};
        private static readonly bool[] stateThree = new bool[2] {true,true};
        private static readonly bool[] stateFour = new bool[2] {true,false};

        private static bool[] oldState = new bool[2];
        private static bool[] newState = new bool[2];

        private static InterruptPort _pinAInterrupt;
        private static InterruptPort _pinBInterrupt;
        private static InterruptPort _switchPinInterrupt;

        
        public delegate void ClockwiseEventHandler();
        public delegate void CounterClockWiseEventHandler();
        public delegate void ButtonPushedEventHandler();

        public static event ClockwiseEventHandler ClockWise;
        public static event CounterClockWiseEventHandler CounterClockWise;
        public static event ButtonPushedEventHandler ButtonPushed;

        public RotarySwitch(Cpu.Pin pinA, Cpu.Pin pinB, Cpu.Pin switchPin)
        {
            _pinAInterrupt = new InterruptPort(pinA, true, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);
            _pinBInterrupt = new InterruptPort(pinB, true, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);
            _switchPinInterrupt = new InterruptPort(switchPin, true, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeHigh);

            _pinAInterrupt.OnInterrupt += new NativeEventHandler(_pinAInterrupt_OnInterrupt);
            _pinBInterrupt.OnInterrupt += new NativeEventHandler(_pinBInterrupt_OnInterrupt);

            _switchPinInterrupt.OnInterrupt += new NativeEventHandler(_switchPinInterrupt_OnInterrupt);

            oldState[0] = _pinAInterrupt.Read();
            oldState[1] = _pinBInterrupt.Read();
        }


        static void _switchPinInterrupt_OnInterrupt(uint data1, uint data2, DateTime time)
        {
            if (ButtonPushed != null)
            {
                ButtonPushed();
            }
        }

        static void _pinAInterrupt_OnInterrupt(uint data1, uint data2, DateTime time)
        {
            newState[0] = data2 == 1;
            newState[1] = _pinBInterrupt.Read();

            CheckDirection();
        }

        static void _pinBInterrupt_OnInterrupt(uint data1, uint data2, DateTime time)
        {
            newState[0] = _pinBInterrupt.Read();
            newState[1] = data2 == 1;

            CheckDirection();
        }

        private static void CheckDirection()
        {
            int newStateInt = 0;
            int oldStateInt = 0;
            int direction = 0;
            
            if (newState == stateOne)
                newStateInt = 1;
            if (newState == stateTwo)
                newStateInt = 2;
            if (newState == stateThree)
                newStateInt = 3;
            if (newState == stateFour)
                newStateInt = 4;

            if (oldState == stateOne)
                oldStateInt = 1;
            if (oldState == stateTwo)
                oldStateInt = 2;
            if (oldState == stateThree)
                oldStateInt = 3;
            if (oldState == stateFour)
                oldStateInt = 4;

            direction = newStateInt - oldStateInt;

            if(direction > 0)
            {
                
                if (ClockWise != null)
                    ClockWise();
            }

            if(direction < 0)
            {
                oldState = newState;
                newState = null;
                if(CounterClockWise != null)
                {
                    CounterClockWise();
                }
            }

            oldState = newState;
            newState = null;

            return;
        }
    }
}



#15918 Adding an interupt port to a class

Posted by Adam Clifford on 26 July 2011 - 11:12 AM in Netduino Plus 2 (and Netduino Plus 1)

Hi Guys and Gals,

I am trying to write an interrupt based rotary encoder switch library that has three events, clockwise, counterclockwise and button push.

However when I try to add an interupt port to the class it just doesnt show up.

Here is my code so far
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.NetduinoPlus;
using SecretLabs.NETMF;

namespace RotaryEncoderSwitch
{
    public class RotarySwitch
    {
        private int _pinA;
        private int _pinB;
        private int _switchPin;
        private bool _positiveEdge;
        
        public delegate void ClockwiseEventHandler();
        public delegate void CounterClockWiseEventHandler();
        public delegate void ButtonPushedEventHandler();

        public event ClockwiseEventHandler ClockWise;
        public event CounterClockWiseEventHandler CounterClockWise;
        public event ButtonPushedEventHandler ButtonPushed;

        public RotarySwitch(int pinA, int pinB, int switchPin, bool positiveEdge)
        {
            _pinA = pinA;
            _pinB = pinB;
            _switchPin = switchPin;
            _positiveEdge = positiveEdge;
        }
    }
}

I would like to add a static private interrupt port to the class but it wont let me.

does anyone have any ideas why?


Doh, Forgot to add all of the correct references
Adam Clifford



#15867 Netduino Plus Firmware v4.2.0 BETA 1

Posted by Adam Clifford on 24 July 2011 - 07:17 PM in Beta Firmware and Drivers

Hi Chris,

Just to see if it was the firmware or not I flashed back to 4.1, I'll reflash the beta and see if I can reproduce, if I can get it to consistently BSOD i will add steps to the ticket already open.

Adam

Hi Adam,

If this happens to you again, would it be possible to grab the crash info and submit it as a bug to the netmf.codeplex.com website?

As a side note: Netduino uses the standard NETMF driver. So the info you provide to Microsoft will help anyone using .NET MF (and possibly anyone using Windows--if it's a more generic Windows USB glitch).

Chris




#15848 Netduino Plus Firmware v4.2.0 BETA 1

Posted by Adam Clifford on 24 July 2011 - 08:33 AM in Beta Firmware and Drivers

I'm not sure if this is a bug or just unfortunate. I was doing a deploy to the netduino+ and it just seemed to hang, and unfortunately i pulled the cable out from the PC and it BSOD me. I'm running win7 64bit, vs2010 professional. Adam Clifford




home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.