- Netduino Forums
- → entens's Content
entens's Content
There have been 10 items by entens (Search limited from 20-April 23)
#5236 Kalman Filters
Posted by entens on 24 November 2010 - 07:12 AM in Netduino 2 (and Netduino 1)
#5865 Program Storage and Execution
Posted by entens on 07 December 2010 - 05:24 PM in Netduino 2 (and Netduino 1)
The contents of 'AppLoader.cs' is probably what you'll want to use. It essentially grabs a byte array and uses 'System.Reflection' to load it as an executable assembly. This should work, but I see problems with a lack of memory while using the Netduino.
Contents of AppLoader.cs so you don't have to download the Pyxis source:
/* Copyright 2010 Thomas W. Holtquist Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ using System; using System.Collections; using System.IO; using System.Reflection; using System.Runtime; using Microsoft.SPOT; namespace Skewworks.Pyxis.Kernel { internal static class AppLoader { /// <summary> /// The interface for a standlone application /// </summary> interface IApplication { void RunFromBytes(ref ApplicationKey AppKey, ref PyxisAPI APIRef, ref string path, ref string[] parameters); AppIcon GetAppIcon(byte[] bytes); } /// <summary> /// A class that can be loaded across applicaiton domains which /// implements the IApplicaiton interface /// </summary> public class Application : MarshalByRefObject, IApplication { /// <summary> /// we need a defautl consturctor to create an instance of this object /// across an application domain /// </summary> public Application() { } public AppIcon GetAppIcon(byte[] bytes) { // Attempt to execute DLL try { Assembly asm; MethodInfo[] m; asm = Assembly.Load(bytes); if (asm == null) { return new AppIcon(); } Type[] t = asm.GetTypes(); for (var j = 0; j < t.Length; j++) { m = t[j].GetMethods(BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance); for (int i = 0; i < m.Length; i++) { if (m[i].Name == "PyxisIcon") { return (AppIcon)m[i].Invoke(asm, null); } } } } catch (Exception e) { // Do nothing } return new AppIcon(); } public void RunFromBytes(ref ApplicationKey AppKey, ref PyxisAPI APIRef, ref string path, ref string[] parameters) { string[] supporting = Directory.GetFiles(Path.GetDirectoryName(path)); for (int i = 0; i < supporting.Length; i++) { if (supporting[i] != path) { try { Assembly.Load(File.ReadAllBytes(supporting[i])); } catch (Exception) { // move along } } } RunAppFromBytes(AppKey, APIRef, File.ReadAllBytes(path), parameters); } private void RunAppFromBytes(ApplicationKey AppKey, PyxisAPI APIRef, byte[] bytes, string[] parameters) { // Attempt to execute DLL try { Assembly asm; MethodInfo[] m; asm = Assembly.Load(bytes); if (asm == null) { return; } Type[] t = asm.GetTypes(); for (var j = 0; j < t.Length; j++) { m = t[j].GetMethods(BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance); for (int i = 0; i < m.Length; i++) { if (m[i].Name == "PyxisApp") { AppStartup myStartup = (AppStartup)m[i].Invoke(asm, new object[] { AppKey, APIRef, parameters }); APIRef.ActivateApplication(myStartup, AppKey); } } } } catch (Exception e) { // Do nothing APIRef.Prompt("Failed to launch program.\n" + e.Message, "System Alert", PromptType.OKOnly); } } } #region Variables private static IApplication iApp = null; #endregion /// <summary> /// The executable entry point. /// </summary> public static void LaunchApplication(PyxisAPI APIRef, string path, string[] parameters) { int AppID = GetAppID(APIRef); // Create the Application PyxisApplication PA = new PyxisApplication(); PA.Forms = new ArrayList(); PA.Domain = AppDomain.CreateDomain("PyxisApp" + AppID); PA.Key = new ApplicationKey(AppID, PA.Domain); APIRef._runningApps.Add(PA); // create an instance of the IApplication type // please note that the following call will also load the assembly that contains that type // which we pass as first parameter try { iApp = (IApplication)PA.Domain.CreateInstanceAndUnwrap(typeof(IApplication).Assembly.FullName, typeof(Application).FullName); // Allow system time to catch up System.Threading.Thread.Sleep(100); // Launch the Program iApp.RunFromBytes(ref PA.Key, ref APIRef, ref path, ref parameters); } catch (Exception e) { APIRef.Prompt("Failed to launch application!\n" + e.Message + "\n" + e.InnerException.ToString(), "System Alert", PromptType.OKOnly); APIRef._runningApps.Remove(PA); return; } } public static AppIcon GetApplicationIcon(byte[] bytes) { AppIcon AI; // Create the Domain AppDomain ad = AppDomain.CreateDomain("PyxisAppDesktopIcon"); // create an instance of the IApplication type // please note that the following call will also load the assembly that contains that type // which we pass as first parameter if (iApp == null) { try { iApp = (IApplication)ad.CreateInstanceAndUnwrap(typeof(IApplication).Assembly.FullName, typeof(Application).FullName); } catch (Exception e) { AppDomain.Unload(ad); return new AppIcon(); } } // Get the Icon AI = iApp.GetAppIcon(bytes); // Destroy Domain iApp = null; AppDomain.Unload(ad); return AI; } private static int GetAppID(PyxisAPI APIRef) { bool bConflict = false; int AppID = 0; int i; PyxisApplication PA; while (true) { bConflict = false; for (i = 0; i < APIRef._runningApps.Count; i++) { PA = (PyxisApplication)APIRef._runningApps[i]; if (PA.Domain.FriendlyName == "PyxisApp" + AppID) { bConflict = true; break; } } if (!bConflict) return AppID; AppID++; } } } }
Unrelated side note: Would it be possible to get a 'spoiler' tag added so you can embed long pieces of code in collapsible block?
#5491 Netdunio TRNG
Posted by entens on 29 November 2010 - 04:00 PM in General Discussion
@entens according to Rob Seward (the source of my circuit design) it uses "avalanche noise" between 2 of the transistors, though to be honest I'm a complete EE n00b and I have no idea what this means .
if your curious as to what is providing your noise take a look at this wikipedia article [http://en.wikipedia....che_breakdown]. It gives a pretty good explanation of what causes avalanche noise in electrical circuits. Basically your using the first transistor pair to step the current up to the point where an unknown amount of current is leaking through the insulation thereby creating a noisy signal. The third transistor is stepping the noisy signal to a level that is easily measured by the microcontroller.
You probably already understand this by now, but I figured it be nice to have a short explanation of the methodology for the non EE people here.
#5442 Netdunio TRNG
Posted by entens on 28 November 2010 - 04:40 AM in General Discussion
#7526 Little Hydraulic Arm
Posted by entens on 12 January 2011 - 07:32 PM in General Discussion
Hi all,
I'm still learning electronics and the Netduino but just wanted to float a question out there to see if I'm going in the right direction. I'm trying to control a small hydraulic arm (just a cylinder and a rod that goes out and back) and I was thinking I'd need a small air pump and a three way solenoid valve (one way to pump/push the arm out and one to release the air letting a weak spring in the cylinder push the arm back.
Anyone seen a netduino/arduino project like that or any components that might suit. Any help at all most gratefully received.
Many Thanks in advance.
Eddie
I think your looking for a solenoid actuated spool valve. In my experience, I've only used them with PLC's to actuate powerful hydraulic servos so I'm not exactly sure of the availability for something small scale.
If you shooting for small scale, I would actually use two small solenoid valves with a pressure relief valve feeding back into my supply reservoir.
#5388 Netduino as an extension to a WinForms app?
Posted by entens on 27 November 2010 - 06:43 AM in Netduino 2 (and Netduino 1)
Thanks for your responses.
Phil: That is similar to what I am trying to do, but mine is far simpler! I want to interface with my mechanical padlock to unlock a door via my phone. In order to interface with the deadbolt, I need to be able to close the circuits to the right pins of the numeric keypad in the right order.
Perhaps I don't even need a Netduino? This might be a dumb question, but can I simply use different pin combinations of a PC's RS-232 port (and some programming with .NET's System.IO.Ports) to close 6 independent circuits on command? (5 numeric keypad buttons, and a 6th "lock" button)
Or would I need some hardware with more logic (i.e. the Netduino) and perhaps Chris' approach with the serial connectivity?
-E
you can use just the serial port, but you will be limited to three outputs, plus it will be an epic pain in the butt to get working. i would recommend getting the Netduino to save yourself some gray hairs. If you still want to go down that rabbit hole, this article should get you started [http://slicksolution...dsdriver.shtml]
#5816 DTMF chip coding problem
Posted by entens on 06 December 2010 - 05:58 PM in Visual Studio
You can make the leds match the input using this code:
public static void Main() { // setup LEDs OutputPort led1 = new OutputPort(Pins.GPIO_PIN_D5, false); OutputPort led2 = new OutputPort(Pins.GPIO_PIN_D5, false); OutputPort led4 = new OutputPort(Pins.GPIO_PIN_D5, false); OutputPort led8 = new OutputPort(Pins.GPIO_PIN_D5, false); // instantiate the DTFM driver DTFM toneDecoder = new DTFM(Pins.GPIO_PIN_D0, Pins.GPIO_PIN_D1, Pins.GPIO_PIN_D2, Pins.GPIO_PIN_D3); // main loop while (true) { int value = toneDecoder.Read(); // initialize leds led1.Write(false); led2.Write(false); led4.Write(false); led8.Write(false); // set LED array based on value switch(value) { case 0: // no leds lit break; case 1: led1.Write(true); break; case 2: led2.Write(true); break; case 3: led1.Write(true); led2.Write(true); break; case 4: led4.Write(true); break; case 5: led1.Write(true); led4.Write(true); break; case 6: led2.Write(true); led4.Write(true); break; case 7: led1.Write(true); led2.Write(true); led4.Write(true); break; case 8: led8.Write(true); break; case 9: led1.Write(true); led8.Write(true); break; case 10: led2.Write(true); led8.Write(true); break; case 11: led1.Write(true); led2.Write(true); led8.Write(true); break; case 12: led4.Write(true); led8.Write(true); break; default: // cannot have value for 13-16 break; } // wait for next round of input Thread.Sleep(200); } }
#5815 DTMF chip coding problem
Posted by entens on 06 December 2010 - 05:42 PM in Visual Studio
public class DTFM : IDisposable { private Thread ListenThread; private bool Listening; private int LastValue; private InputPort Binary1; private InputPort Binary2; private InputPort Binary4; private InputPort Binary8; public delegate void OutputHandler(object sender, int value); public event OutputHandler Output; public DTFM(Cpu.Pin Binary1, Cpu.Pin Binary2, Cpu.Pin Binary4, Cpu.Pin Binary8) { // Initialize the local InputPort's utilized by the DTFM this.Binary1 = new InputPort(Binary1, false, Port.ResistorMode.Disabled); this.Binary2 = new InputPort(Binary2, false, Port.ResistorMode.Disabled); this.Binary4 = new InputPort(Binary4, false, Port.ResistorMode.Disabled); this.Binary8 = new InputPort(Binary8, false, Port.ResistorMode.Disabled); // Initialize the listener thread Listening = true; ListenThread = new Thread(new ThreadStart(Listen)); ListenThread.Start(); } public void Dispose() { // Make the thread expire Listening = false; Thread.Sleep(10); // Force the thread dead just in case if (ListenThread.IsAlive) ListenThread.Abort(); // Free the InputPort's Binary1.Dispose(); Binary2.Dispose(); Binary4.Dispose(); Binary8.Dispose(); } public int Read() { int result = 0; // Build the current value from the DTFM if (Binary1.Read()) result += 1; if (Binary2.Read()) result += 2; if (Binary4.Read()) result += 4; if (Binary8.Read()) result += 8; } void Listen() { while (Listening) { // Don't execute if nothing is attached to the event if (Output != null) { int CurrentValue = 0; CurrentValue = Read(); // If the value has changed, throw a new event if (CurrentValue != LastValue) { LastValue = CurrentValue; Output(this, CurrentValue); } } // Wait Thread.Sleep(100); } } }
Using your provided code, you can either manually read using the Read() function, or receive events by attaching to the Output event like:
DTFM toneDecoder = new DTFM(Pins.GPIO_PIN_D0, Pins.GPIO_PIN_D1, Pins.GPIO_PIN_D2, Pins.GPIO_PIN_D3); toneDecoder.Output += new OutputHandler(ToneReceived);
#5686 equivalent c# code for a embedded c code
Posted by entens on 03 December 2010 - 07:24 AM in Visual Studio
If your using the HT9170 like in the PDF you linked to, you'll want to connect them something like:
HT9170 Netduino ======== ========== Pin 11 D6 Pin 12 D7 Pin 13 D8 Pin 14 D9
public class DTFM : IDisposable { private Thread ListenThread; private bool Listening; private int LastValue; private InputPort Binary1; private InputPort Binary2; private InputPort Binary4; private InputPort Binary8; public delegate void OutputHandler(object sender, int value); public event OutputHandler Output; public DTFM(Cpu.Pin Binary1, Cpu.Pin Binary2, Cpu.Pin Binary4, Cpu.Pin Binary8) { // Initialize the local InputPort's utilized by the DTFM this.Binary1 = new InputPort(Binary1, false, Port.ResistorMode.Disabled); this.Binary2 = new InputPort(Binary1, false, Port.ResistorMode.Disabled); this.Binary4 = new InputPort(Binary1, false, Port.ResistorMode.Disabled); this.Binary8 = new InputPort(Binary1, false, Port.ResistorMode.Disabled); // Initialize the listener thread Listening = true; ListenThread = new Thread(new ThreadStart(Listen)); ListenThread.Start(); } public void Dispose() { // Make the thread expire Listening = false; Thread.Sleep(10); // Force the thread dead just in case if (ListenThread.IsAlive) ListenThread.Abort(); // Free the InputPort's Binary1.Dispose(); Binary2.Dispose(); Binary4.Dispose(); Binary8.Dispose(); } void Listen() { while (Listening) { // Don't execute if nothing is attached to the event if (Output != null) { int CurrentValue = 0; // Build the current value from the DTFM if (Binary1.Read()) CurrentValue += 1; if (Binary2.Read()) CurrentValue += 2; if (Binary4.Read()) CurrentValue += 4; if (Binary8.Read()) CurrentValue += 8; // If the value has changed, throw a new event if (CurrentValue != LastValue) { LastValue = CurrentValue; Output(this, CurrentValue); } } // Wait Thread.Sleep(100); } } }
Note: 10 = '0'; 11 = '*'; 12 = '#'
#5762 Netduino and the Zune?
Posted by entens on 05 December 2010 - 04:39 AM in General Discussion
Has anyone been able to, or have any insight on how to, 'talking' to the Netduino with a Zune?
is it possible to do without wifi, so with a cable?
I guess you can get started with the cable pinouts
source: http://www.zuneboard...ne-pinouts.htmlPin 01 - USB 5VDC(+) (common with Pins 2,3)
Pin 02 - 5VDC(+) (common with pins 1,3)
Pin 03 - 5VDC(+) (common with pins 1,2)
Pin 04 - Unknown (used on travel remote) 1.75 VDC (+)
Pin 05 - Unknown (used on travel remote) 1.75 VDC (+)
Pin 06 -
Pin 07 -
Pin 08 -
Pin 09 - Video (+)
Pin 10 -
Pin 11 -
Pin 12 -
Pin 13 - Audio L (+) (also audio on travel remote)
Pin 14 - Audio R (+) (Also audio on travel remote)
Pin 15 -
Pin 16 -
Pin 17 - Unknown (used on travel remote) these are likely our trigger
Pin 18 - Unknown (used on travel remote) these are likely our trigger
Pin 19 - Ground (common with Pins 22,23,24,and shield)
Pin 20 - USB Data (-)
Pin 21 - USB Data (+)
Pin 22 - USB Ground (common with Pins 19,23,24,and shield)
Pin 23 - Ground (common with Pins 22,19,24,and shield)
Pin 24 - Ground (common with Pins 22,23,19,and shield)
You also might contemplate taking a look at the datasheet for the Wolfson WM8978 chip. Eventually, thats what that cable connnects to. http://www.wolfsonmi...s/en/WM8978.pdf
- Netduino Forums
- → entens's Content
- Privacy Policy