2017/12/31

Xamarin.Forms on OSX

Not sure how I missed this, but Xamarin.Forms now has preview support for Mac OSX clients.  This is really exciting and I hope they decide to finalize support for OSX as a first-class target.

I spend fair amount of time on OSX, so one of my biggest gripes about Forms was lack of support for a native Mac client.  On Windows I can target UWP and run projects directly on Windows 10.  But, on OSX I have to launch either the iOS or Android target.  Not a deal breaker, but certainly cumbersome.

MvvmCross promises to be a Xamarin.Forms-like MVVM framework that targets more platforms.  But, it seems OSX clients are languishing as a low-priority concern for that project.

Working Client

The xamarin blog's instructions mostly worked.  I added a Cocoa app with the latest version of Xamarin.Forms on nuget (2.5.0) to my Forms solution, and made the required changes.

Everything built, but when I launched it I got a System.NullReferenceException:
1:  Xamarin.Forms.Platform.MacOS.FormsApplicationDelegate.UpdateMainMenu() in   
2:  Xamarin.Forms.Platform.MacOS.FormsApplicationDelegate.DidFinishLaunching(Foundation.NSNotification notification) in   
3:  mobile_app.OSX.AppDelegate.DidFinishLaunching(Foundation.NSNotification notification) in /Users/jake/jade/jade/mobile_app/mobile_app.OSX/AppDelegate.cs:33  
4:  AppKit.NSApplication.NSApplicationMain() in   
5:  AppKit.NSApplication.Main(string[] args) in /Users/builder/data/lanes/5489/c4240f3f/source/xamarin-macios/src/AppKit/NSApplication.cs:100  
6:  mobile_app.OSX.MainClass.Main(string[] args) in /Users/jake/jade/jade/mobile_app/mobile_app.OSX/Main.cs:12  

I found the solution in the xamarin forums.  Need to change the initialization of NSApplication in Main.cs:
1:  static void Main(string[] args)  
2:  {  
3:    NSApplication.Init();  
4:    NSApplication.SharedApplication.Delegate = new AppDelegate();  
5:    NSApplication.SharedApplication.MainMenu = new NSMenu();  // FIX  
6:    NSApplication.Main(args);  
7:  }  
Line 5 is the added line.

Giving me a working- albeit embarrassingly trivial- app:

2017/12/25

Windows 10 IoT Core on Raspberry Pi 3

Following up on my last post, finally got around to trying to install IoT Core on my actual Raspberry Pi device:

My development machine is a 15" Macbook Pro running OSX High Sierra (10.3.2).  Wasn't able to get a Windows 10 VM in VirtualBox to recognize the SD card slot in my adapter (the otherwise fantastic Satechi type-C multi-port adapater), so started looking for how to flash the image without using IoT Core Dashboard.

Image Preparation

Microsoft has some docs about using dism instead of Dashboard.  From the IoT Core download page you can obtain an iso file containing an msi that by default installs the image to:
 C:\Program Files (x86)\Microsoft IoT\FFU\RaspberryPi2\flash.ffu  

ffu2img (https://github.com/t0x0/random/wiki/ffu2img) can be used to convert the ffu to an img file usable with dd found on OSX (and Linux, etc.).

Ensure you're using Python 2.7 and convert the image:
 python ffu2img.py PATH/flash.ffu
Resulting in a flash.img file in the same location as the ffu.

Writing Image to SD Card

To write the image to an SD card I consulted the documentation at raspberrypi.org.

I had trouble getting those instructions to work with my card/reader.  No matter what, dd failed with "Operation not permitted".  In the end I had to:
  1. Insert card into reader and connect reader to laptop
  2. Without unmounting the SD card, run:
     sudo diskutil partitionDisk /dev/disk2 1 MBR "Free Space" "%noformat%" 100%  
    
  3. Disconnect then reconnect the reader (above command seemed to eject the SD card)
  4. Write the image:
     sudo dd bs=1m if=PATH/flash.img of=/dev/rdisk2 conv=sync
In my case, the SD card is /dev/disk2.  /dev/disk2 and /dev/rdisk2 in the above commands should be adjusted appropriately for other cases.

Using df can see several partitions were created (/dev/disk2s1, disk2s2, disk2s3, and disk2s6) on the SD card.  Once inserted in the Raspberry Pi device and powered on, IoT Core should boot.

IoT Core Setup

As it happens, I didn't have a USB keyboard on hand to get the device on the wifi.

Using an ethernet cable to connect the device directly to my laptop, I obtained the device's link-local address from the bottom-left of the touch screen.  The device's admin portal is now accessible by pointing my laptop browser at http://169.254.236.118:8080 (default username/password is Administrator/p@ssw0rd).

In the left panel, selecting Connectivity, then Network, you can configure the wifi AP:

Initially the display was upside-down (assuming the HDMI port is "up" as when using this touchscreen case).  To fix this, in the left panel pick Device Settings and towards the bottom in Display Orientation select "Landscape (Flipped)":