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.
Photo

Running code loaded into an Micro SD card on a Netduino


  • Please log in to reply
1 reply to this topic

#1 miltonkbenjamin

miltonkbenjamin

    Member

  • Members
  • PipPip
  • 22 posts

Posted 23 December 2013 - 12:58 PM

All,

 

When we copy an executable to a MicroSd Card, how do we tell the Netduino to run that code, except by just

 

plugging it into the SD port on the Netduino?

 

Thanks,

 

Milt



#2 ShVerni

ShVerni

    Advanced Member

  • Members
  • PipPipPip
  • 138 posts
  • LocationNew York, New York

Posted 23 December 2013 - 07:43 PM

Hi Milt,

 

Unfortunately, running a program from an SD card is not as simple as plugging in the SD card. These are two excellent posts regarding how to do it:

 

http://fabienroyer.w...ith-a-netduino/

 

http://forums.netdui...ot-implemented/

 

In short, you compile a program you want to run, and then copy the portable executable (PE) file to the SD card, then you load that program from the SD card with another program you deploy to the Netduino in the usual way,

 

For example, if you had a program on your SD card called foo.pe, with a namespace of foo, a class called Program and with a method called Start() in that class, this would launch it and pass an object array of arguments to the method:

string test = "Test";
int bar = 10;
object[][] args = { new object[] { test, bar } };
using (FileStream assmfile = new FileStream(@"SDfoo.pe", FileMode.Open, FileAccess.Read, FileShare.None))
{     
     byte[] assmbytes = new byte[(int)assmfile.Length];    
     assmfile.Read(assmbytes, 0, (int)assmfile.Length);     
     var assm = Assembly.Load(assmbytes);
     var type = assm.GetType("foo.Program");
     var obj = AppDomain.CurrentDomain.CreateInstanceAndUnwrap(assm.FullName, type.FullName);
     MethodInfo mi = type.GetMethod("Start");
     mi.Invoke(obj, args);
}

If you don't want to pass any arguments, you can make this alteration:

mi.Invoke(obj, null);

Additionally, you'll need to add these includes:

using System.Diagnostics;
using System.Reflection;
using System.IO;
using SecretLabs.NETMF.IO;

On the other side, the program foo would look something like this:

namespace foo
{
    public class Program
    {
        public static void Main()
        {
            // This intentionally left blank
        }
        public static void Start(object[] args)
        {
            string test = (string)args[0];
            int bar = (int)args[1];
            Debug.Print("Test=" + test + " bar=" + bar.ToString());
        }
    }
}

I've found this to be a very touchy bit of code, so it can take a while to get everything to work properly. Best of luck!






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

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.