1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17

Reading from a COM port

14/11/2016

I was recently researching how to read from a COM (Serial) port in order to communicate with an old embedded system. If you're not familiar with them that's one of these:

a serial port has a 9 pin connection

C# provides the SerialPort class for just this purpose which is hugely helpful. However there's one problem with this class which is that it's just not... very good. I didn't know about this but this post by Ben Voigt should leave you in no doubt that it has some problems.

Setup

In order to test the code on my machine without access to the actual device which was elsewhere, I installed Eltima's Virtual Serial Port Driver which would allow me to test with emulated serial ports. Once I had set up a pair of ports I could send data from one end using PowerShell.

...

New Site

05/11/2016

I've not been able to find time to blog at all since starting my new job in March, working at a startup means learning a lot but also working long hours!

Almost a year and a half after first blogging about vNext/.NET core I've finally written my first (almost) functional program in it. I've changed this blog from a horrible mess of PHP to a nice MVC6 site running on an Ubuntu server using .NET core. The nice part is noticeable in the code, the UI still remains a dumpster-fire.

The motivation to finally get a site running using .NET core was from this blog post by Scott Hanselman which shows just how easy it is to get something running on .NET core. I grabbed a very cheap Ubuntu droplet from Digital Ocean and followed along, all development was done on my awful 8 year old laptop running xUbuntu. It's so nice to be able to build C# apps and have them run across platforms.

Another improvement is I have scripted my entire deployment using a shell script, as soon as I'm happy with my changes I can run one script which will build, package, deploy and start the site. No more tedious manual FTP interaction.

The code for the blog is on GitHub so you can see just how badly written it is and probably hack my terrible home-brew security stuff.

I'm still missing a couple of features from the old blog which I was too lazy to port across but hopefully they won't be missed by anyone, if you want them back (code snippets hosted on this site for some older tutorials) let me know in the comments.

...

Run tests task for Elixir in Visual Studio Code

12/02/2016

In order to learn Linux I'm biting off more than I can chew by trying to learn Elixir at the same time. From the available code editors for Linux I'm using Visual Studio Code.

Visual Studio Code has the ability to configure custom tasks.

To get to the custom task configuration you can use the command palette with Ctrl + Shift + P and type Tasks: Configure Task Runner. This will open "tasks.json". Replace the contents with:

{
    "version": "0.1.0",
    "command": "bash",
    "isShellCommand": true,
    "showOutput": "always",
    "args": [
        "-c"
    ],
    "tasks": [
        {
            "taskName": "Elixir-Test",
            "suppressTaskName": true,
            "isTestCommand": true,
            "args": ["mix test"]
        }
    ]
}

And save the file. Now if you use Ctrl + Shift + T mix will run your tests for the project (assuming you have the mix.exs level folder open) and print the output to the console.

This command could probably be improved by checking that it's executing in the correct folder first but I'm nowhere near confident enough with Bash to write it yet.

Further notes from adventures in Elixir

Function capturing (Capture operator)

This concept took me a little while to get to grips with because I couldn't think of an equivalent from C#.

A typical anonymous function in Elixir might take this form:

square = fn x -> x * x end

You would then call it with the dot "." between the function name and the argument like this:

...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17