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
  | ||||||||||||||
Running code loaded into an Micro SD card on a Netduino
Started by miltonkbenjamin, Dec 23 2013 12:58 PM
1 reply to this topic
#1Posted 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 #2Posted 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 topic0 members, 0 guests, 0 anonymous users | ||||||||||||||
|
||||||||||||||
This webpage is licensed under a Creative Commons Attribution-ShareAlike License. | ||||||||||||||