- Netduino Forums
- → Adam Clifford's Content
Adam Clifford's Content
There have been 12 items by Adam Clifford (Search limited from 14-May 23)
#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)
#30430 Socket Exception
Posted by Adam Clifford on 08 June 2012 - 07:04 PM in Netduino Plus 2 (and Netduino Plus 1)
- 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)
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)
#30358 Socket Exception
Posted by Adam Clifford on 07 June 2012 - 10:14 AM in Netduino Plus 2 (and Netduino Plus 1)
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)
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)
#15957 Rotary Encoder Switch class
Posted by Adam Clifford on 27 July 2011 - 07:23 AM in General Discussion
#15926 Rotary Encoder Switch class
Posted by Adam Clifford on 26 July 2011 - 03:33 PM in General Discussion
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)
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; } } }
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
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
- Netduino Forums
- → Adam Clifford's Content
- Privacy Policy