Wednesday
Sep172014

MacBook Pro + Parallels + Windows 8.1 + Visual Studio + Xamarin = awesome

I went searching for the ultimate developer machine setup, and I've found it. The title of this post says it all.

I started with a full blown MacBook Pro. It's got 16GB of RAM, the retina display, and a 1TB PCIeX-based flash drive, supposedly faster than SSD. Basically, I got all the options, and I'm not regretting it. I don't miss the touch screen, either.

At first I thought I should sign in to all of my social services, so I did. That got very annoying very fast. I started by turning off notifications, then I just decided to remove the accounts. This is a developer machine. I use my phone to check Facebook, and the web-based GMail client works just fine for me.

Then, I added Parallels, which lets me run Windows and OSX at the same time. You can either switch full screen or use "Coherence," a mode in which Windows apps can run right alongside Mac apps on the same desktop.

Parallels let me install Windows 8.1 with the option to make it look like Windows 7. This option actually installs the Stardock apps, Start8 (gives you a Windows 7 style start menu) and ModernMix (lets you run Windows Store apps on the desktop). That was a seamless experience that just delighted me to no end.

After figuring out how to navigate Windows with Parallels (switching in and out of Coherence mode) I made sure all the latest updates were installed, and then started installing Windows apps: 

NOTE: In order for you to get the Visual Studio experience you know and love, you must disable the Function Key mapping that the Mac imposes. Go to System Preferences/Keyboard. From the Keyboard Tab, check the box that says Use all F1, F2, etc. keys as standard function keys. Then go to the Shortcuts Tab, Select Mission Control and uncheck Show Desktop (F11) and Show Dashboard (F12). That will give you back your function keys in Visual Studio. :)

On the Mac side I installed the following:

I also had to install the Samsung USB Driver for Mobile Phones so I could connect my Galaxy S5 and use it for development. If you plan on using an Android device, there are instructions on Xamarin's website, but I found this didn't go so far as to explain that you might need to go online to find your phone manufacturer's USB drivers. I had to find that by GoogleBinging it. 

Also, as noted in the documentation, I had to enable USB debugging on my S5. That's tricky. First you have to enable developer mode on the phone by standing on your head and reciting a spell. Then, you have to enable USB debugging. This won't work unless the USB Driver is installed.

After all that I was able to create a new Xamarin Forms app with Visual Studio 2013. I created a Shared project in VS2013. I set the Android project to be the startup project, ran it, and after a few minutes I saw "Hello Forms" on my S5 screen. Great.

The Windows Phone option was easy. It ran in the emulator, which is pretty good.

The iOS app was a bit trickier to set up.

First, you need to run the Xamarin iOS Build Host app on the Mac side, an app which comes with Xamarin Tools, and press the Pair button. 

The Xamarin tools in Visual Studio will look for this app on the same machine. This is the reason why I chose a MacBook Pro with Parallels. It just works.

In Visual Studio you select the iOS emulator, and then you get to select which iOS device you wish to emulate. Set the iOS project as the startup project and run the app.

To summarize, if you want to minimize the cross-platform headaches involved in developing with Xamarin tools, go with a MacBook and Parallels.

Tuesday
Jul292014

"Stay away from Buffalo Hard Drives"

That's what they told me at The Oliver Group, a local data recovery company where I took my Buffalo DriveStation Axis Velocity external 3TB hard drive. "They have their own software that sits on a controller board between the drive and the OS. We've seen it cook the hard drives to the point of physical damage."

I tested the theory by taking the Seagate 3TB drive out of the enclosure and connecting it to my PC with a USB3 dock I use for many other drives. Turns out Windows sees it as an uninitialized drive, and only in Drive Manager. Pop it back in the Buffalo enclosure and everything is there.

It all started when I was recording a .NET Rocks! show with Ted Pattison. The recording stopped abruptly and I was unable to access the files I was just recording to. Other files started giving me trouble as well. I could read the directory data just fine. There was no typical skipping noise or churning noise coming from the drive indicating bad sectors. There was only a problem when I went to copy or otherwise access the files. The OS hung like it no idea how to deal with the issue. That's becuase it didn't. 

The Oliver Group was able to restore all the data onto a new hard drive except for about 50MB worth of files, some of which hadn't been touched in over a year. $500 later, as the technician was handing me my drives he said, "a word of warning. Stay away from these Buffalo external drives."

And so I shall.

Monday
Jun232014

Prepare your Mac for use with Xamarin iOS.

Before you can get started with Xamarin.iOS, whether or not you plan to use Xamarin Forms, you must prepare your Mac for network use. This document will show you how to configure the network, install VNC for remote access, and connect using either a crossover cable or a network hub.

The Connection

I recommend making a hard Ethernet connection to your Mac using a Static IP address. You can either use a network hub or a crossover cable to make the physical connection.

If you use a hub or switch, connect both your Windows machine and the Mac to the hub/switch using standard network patch cables. If you want to avoid the extra hardware, just connect the Windows machine directly to the mac using a crossover cable, a network cable in which the Transmit and Receive wires are crossed. You can get one online at MonoPrice for less than $2.00.

Select an IP Address for your Mac

If you're already using the network port on your Windows machine, you'll have to find an available IP address. If you're behind a NAT router your Windows IP address will be something like 192.168.X.X or 10.1.X.X. That means you need to know what IP addresses are available and which are reserved for DHCP. You can find this by connecting to your router as an admin.

First, we need to find the address of the router. This would be listed as your Default Gateway in your network settings. You can find this by opening a command prompt and typing "ipconfig/all". My default gateway is 192.168.1.1. Connect to this address with your browser ("http://192.186.1.1"), log in as the admin and find your DHCP settings. There will be a range of addresses to use for DHCP. In my case, the range is 192.168.1.2 to 192.168.1.100. That means we can safely use 192.168.1.101 and higher for static IP addresses.

My Windows machine actually has a static IP address of 192.168.1.101, so I will assign my Mac Mini to use 192.168.1.102.

If you're not using the Ethernet port on your Windows machine, you can give it any IP address you like, so long as it doesn't conflict with your current IP address. To be safe, make up something non-standard. Give yourself 100.9.33.1 and give the Mac 100.9.33.2. The rest of this document assumes the first scenario: 192.168.1.101 for the Windows machine and 192.168.1.102 for the Mac.

Windows Network Settings

IP Address: 192.168.1.101

Subnet Mask: 255.255.255.0

Default Gateway: 192.168.1.1

Refer to this document if you don't know how to change your IP address on Windows.

Mac Network Settings

Open up System Preferences on the Mac and navigate to the Network screen. Select Ethernet Connected and enter the following settings:

Click to enlarge

IP Address: 192.168.1.102

Subnet Mask: 255.255.255.0

Default Gateway: 192.168.1.1

 

 

 

Add DNS Server

Click the Advanced button and navigate to the DNS Tab. Click the + button in the bottom left, and enter 192.168.1.1 (or whatever your Default Gateway address is). Click the Apply button. You are networked!

Install VNC

VNC is a free remote-desktop app with support for every platform. You can get this for free from http://realvnc.com. Go there with Safari on your Mac and download VNC. Make sure you download the complete version, not just the viewer. Follow the installation instructions.

Run VNC Server

Run the VNC Server app on the mac and configure a password from the Options menu.

click to enlargeOnce you enter a password you're good to go. 

Install VNC on your Windows machine, run the VNC Viewer, and enter the Mac's IP address and the VNC password, and you should be able to connect to it.

Now you are ready to rock and roll in the world of Xamarin.

 

 

 

Monday
Jun022014

My findings after day 1 with Xamarin Forms

Xamarin Forms

I couldn't reist any longer. I dove in. Full on. Mac Mini, Galaxy S5, iPad Air. Got it all set up in my hotel room awaiting the comencement of the awesomeness that is the Norwegian Developer's Conference. Here's what I found after my first day.

First of all, Xamarin Forms is the latest abstraction from Xamarin that lets you build a solution in Visual Studio with projects for iOS, Android, and Windows Phone all sharing a single UI layer which you can build in XAML and C#. Kind of.

XAML and not XAML

The XAML you know and love is in there somewhere, but it's not all there. Xamarin has it's own controls with its own properties and bindings, and for obvious reasons. Still, it's XAML and XAML is awesome.

No Intellisense

Unless I'm missing something, the XAML editor has no intellisense, so that brings you back to the dark ages a bit. Please, someone tell me I'm wrong and that there's a tweak somewhere that I didn't find.

Shared Projects vs Portable Class Libraries

These are the two project types via which you can use Xamarin Forms. I chose to go down the Shared Projects rabbit hole. The main UI project doesn't compile an assembly. Each platform-specific project calls for the UI, which gets compiled to native code on that platform. Sweet, but there are some drawbacks.

No ValueConverters in Shared Projects?

I could not find a workaround to this one. Since ValueConverters are made accessible as local resources, and local resources are dependent on assembly bindings, and Shared Projects do not produce assemblies, voila. Not supported. I looked for a hack for hours. No luck. The ugly workaround is to create bindable formatted string properties. A better workaround is to move your valueconverters to a PCL, or use a Portable project.

iOS doesn't like empty string fields when binding

For iOS, String Fields of Labels must be initialized to non-empty before bindings will work. I found this out by binding the Text property of a label to a string property of an object. While it worked in Android and Windows Phone, I had to initialize the bound property to some non-empty string value otherwise the binding wouldn’t work.

The Good News

Despite all that, I was able to make an app that displayed location data in real time on all three platforms in one day, setup to done. That would have never happened if I had to learn Objective C and Java.

Good job Xamarin.

 

 

 

Saturday
Jan112014

Simplifying Kinect for Windows 1.x Skeleton Drawing

KinectTools is an abstraction over the code that handles the Kinect v1 sensors, Skeleton data, and drawing the skeleton. It exposes Brush and Pen properties for drawing so you have control over the look of your skeleton. It also can place a PNG file over the head as you move around, providing hours of jocularity.

If you've done any work with the Kinect for Windows 1.x SDK you've probably already created an abstraction such as this. But if you haven't here's a nice one for you.

What's cool about this is that it uses the term Body which is what SDK 2.0 calls a Skeleton. I've also written this abstraction for SDK 2.0 (only in pre-release) so using this will get you ready for the future. The next version of the GesturePak Recorder and sample code uses this abstraction as well.

Here's a very simple WPF app that uses the KinectTools SimpleBodyEngine class to draw the skeleton in real time, put an image of my head on top of it, and turn the background of the window red if you move your right hand out in front of your body 1/3 of a meter.

XAML:
<Window x:Class="SimpleBodyEngineTest.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="600" Width="800">
    <StackPanel>
        <StackPanel Orientation="Horizontal">
            <TextBlock Text="Sensor: "/>
            <TextBlock Text="{Binding SensorStatusName}" />
        </StackPanel>
        <Image x:Name="BodyImage" Source="{Binding ImageSource}" Stretch="None" />
    </StackPanel>
</Window>
Code:
using System;
using System.Windows;
using System.Windows.Media;
using Microsoft.Kinect;
using KinectTools;

namespace SimpleBodyEngineTest
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        // This object makes handling Kinect Skeleton objects easy!
        SimpleBodyEngine BodyEngine = new SimpleBodyEngine();

        public MainWindow()
        {
            InitializeComponent();
            // event handlers
            this.Closing += MainWindow_Closing;
            BodyEngine.BodyTracked += BodyEngine_BodyTracked;

            // put Carl's head on top of the Skeleton
            BodyEngine.HeadImageUri = new Uri("carl.png", UriKind.Relative);
            
            // bind the XAML to the SimpleBodyEngine
            this.DataContext = BodyEngine;
        }

        /// <summary>
        /// This event fires when a *tracked* skeleton frame is available
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void BodyEngine_BodyTracked(object sender, BodyTrackedEventArgs e)
        {
            // Get the Z position of the hand and spine
            var hand = e.Body.Joints[JointType.HandRight].Position.Z;
            var spine = e.Body.Joints[JointType.Spine].Position.Z;

            // if the hand is in front of the spine...
            if (Math.Abs(hand - spine) > .3)
                // turn the background red
                Background = Brushes.Red;
            else
                Background = Brushes.White;
        }

        void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            BodyEngine.Dispose();
        }
       
    }
}
Forget about the hundreds of lines of code to draw the Skeleton. If you just want to handle the data, read this blog post I wrote on the basics of Skeleton tracking. This code is so simple. Put up an image and bind it to a property. Create a new SimpleBodyEngine object and make it the DataContext. Done.

Download the code here and enjoy.

Carl