Jarred Capellman
Putting 1s and 0s to work since 1995
RSS
Twitter
LinkedIn

Tuesday, September 30, 2014

C# on Windows IoT (at least some what)

Posted By Jarred Capellman

After doing some research last night, it looks as though there is limited C# support on the Intel Galileo when using Windows IoT (see my Intel Galileo and Windows IoT post for more information on both the Intel Galileo and Windows IoT) per this August 20th, 2014 post from Pete Brown. This got me thinking what exactly is supported?

Checking the usual folder for Microsoft .NET under c:\Windows\Microsoft.Net was non-existent, so I started poking around. Low and behold under the c:\Windows \System32\CoreCLR\v1.0 folder all of the CLR dlls live.

Windows IoT CoreCLR Dlls
In looking at the list, Pete Brown was correct, outside of the System namespace we've got 0 support, but we do have LINQ, XML Support, Collections and IO. What about adding in let's say System.Net.Http?

Trying a simple HttpClient test with the System.Net.Http copied unfortunately gave a System.BadImageFormatException:
Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.BadImageFormatException: Could not load file or assembly 'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. Reference assemblies should not be loaded for execution.  They can only be loaded in the Reflection-only loader context. (Exception from HRESULT: 0x80131058) ---> System.BadImageFormatException: Cannot load a reference assembly for execution.
   --- End of inner exception stack trace ---
   at winiottest.Program.Main(String[] args)
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at AppDomainManager.HostMain(Int32 argc, Char** argv, Char* assemblyToRun, Int32 flags)
So I got thinking of using the older WebClient with the following code block:

static void Main(string[] args) {            
    using (var webClient = new WebClient()) {
        using (var stream = webClient.OpenRead(new Uri("http://jcbench.azurewebsites.net/api/CompareResults"))) {
            using (var streamReader = new StreamReader(stream)) {
                var result = streamReader.ReadToEnd();

                var list = JsonConvert.DeserializeObject>(result);

                foreach (var item in list) {
                    Console.WriteLine(item);
                }
            }
        }
    }
}
However, I received a System.IO.FileNotFoundException:
Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.FileNotFoundException: Could not load file or assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified.
   at winiottest.Program.Main(String[] args)
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at AppDomainManager.HostMain(Int32 argc, Char** argv, Char* assemblyToRun, Int32 flags)
At this point, I thought well what exactly is supported in the System.Net namespace? So I copied over the System.ni.dll from the c$\Windows\System32\CoreCLR\v1.0 path and opened it in the Object Browser inside of Visual Studio 2013 only to see not a lot is implemented...

Windows IoT System Dll
So at this point I ran out of ideas as far as getting any sort of System.Net component in C# at this time. Crossing my fingers it is on the horizon as I have a few ideas I'd love to implement in C# as opposed to C++ with the Galileo board.

Tuesday, September 30, 2014

Intel Galileo and Windows IoT

Posted By Jarred Capellman


Intel Galileo Development Board
After hearing about and seeing Windows IoT while at BUILD this April, I was waiting for an opportunity to really get started with it. Fortunately, this weekend I was near a Fry's Electronics and picked up an Intel Galileo Development Board for nearly half off.

Intel Galileo Development Board - All included parts
Inside the box you'll find the various power plugs used around the world, a USB cable, the development board and the power brick itself.

After reading through the very thorough (no need to ellaborate on the steps) Updating your Intel Galileo I was able to get Windows IoT onto a Micro SDHC card. Make sure to connect to the Client Port (the one closest to the Ethernet Port).

Installing Windows IoT to Galileo
30 minutes into the installation:

Installing Windows IoT to Galileo - 30 minutes in
The whole process took 45 minutes on my HP dv7 laptop to install to my SDHC card. For those curious I chose to use a Sandisk Ultra Plus 16gb Micro SDHC card, while by no means the fastest (the Sandisk Extreme Pro from what I've read is the fastest), it was the most cost effective at $15.

Intel Galileo Development Board - All included parts
After unplugging the power from the Galileo, removing the SDHC card from my PC and popping it into the Galileo I was pleasantly surprised to be able to Telnet in after a minute or two.

Windows IoT with Telnet into Intel Galileo
For those curious, as I have said in other posts, I find XShell to be the best SSH/SERIAL/TELNET client for Windows, best of all it is free for non-commercial use.

After installing WindowsDeveloperProgramforIOT.msi, I started porting jcBENCH to Windows IoT. Since jcBENCH is C++ and written in a extremely portable manner the only big thing I had to do was recompile the pthreads Win32 library to not take advantage of SSE instructions as the Galileo does not support them. The other thing to note is if you want to run a program in a more traditional route, simply do the following:

int _tmain(int argc, _TCHAR* argv[]) {
	ArduinoInit();
      
        // rest of your program here

        return 0;
}
The base template that is installed in Visual Studio 2013 is focused more on applications that loop continuously (which makes sense given the headless nature of Windows IoT).

So how did the Intel Galileo fair in jcBENCH?

C:\jcBench>jcBENCH.cmdl
jcBENCH 1.0.850.0531(x86/WinIoT Intel Galileo Edition)
(C) 2012-2014 Jarred Capellman

Usage: jcBench [Number of Objects] [Number of Threads]

Example: jcBench 100000 4
This would process 100000 objects with 4 threads

Invalid or no arguments, using default benchmark of 10000 objects using 1 CPUS

CPU Information
---------------------
 Manufacturer: GenuineIntel
        Model: Intel Quartz X1000
        Count: 1x399.245mhz
 Architecture: x86
---------------------

Running Benchmark....

Integer: 1
Floating Point: 1
Submit Result (Y or N):n

Results can be viewed and compared on http://www.jcbench.com
Given that it is a single 400mhz Pentium (P5 essientially) - not bad, but not great. It got a score of 1 in both Floating Point operations and Integer Operations, given the baseline is a Dual Core AMD C-60 running at a much faster clock rate. This isn't discouraging, especially given the applications for this platform including my own ideas from back in March 2014 (at the bottom of the post) having my own Network Monitoring software. Given the lower power usage and the challenge of making my C++ code fast enough to do those operations, I'm up for the task.

As for what is next with the Intel Galileo? I have an Intel Centrino 6235 mPCIe 802.11n/Bluetooth 4.0 card coming today for my Galileo, as it is one of the few confirmed working WiFi cards. In addition I have a 16gb Sandisk Extreme Pro SDHC card on its way to test whether or not the "best" card has any impact on a real-world application. For those curious you can now obtain the Windows IoT version of jcBENCH on the official jcBENCH page.

From a developer perspective, for those needing to make use of Pthreads Library, you can download the source and binary compatible with Windows IoT here.