.Net applications can run on Linux by utilizing the Mono Framework. The Mono Framework is already installed on the ComfilePi's default Raspberry Pi OS image.
WinForms applications can be developed and debugged on a Windows PC using Visual Studio, and then simply copied to the ComfilePi and executed with mono
; no re-compiling required!
Mono implements desktop Winforms, so, unlike the .Net Compact Framework and Windows CE, Mono and the ComfilePi support alpha-blending, anti-aliasing, and other rich UI features.
Mono provides the basic System.Windows.Forms
implementation. However, there are many graphics and UI frameworks that are compatible with Mono that can also be used. Below are a few potential offerings.
There are a few plugins that one can use to remote debug .Net/Mono programs running on the ComfilePi from Visual Studio, but they are all in various states of incompleteness or disrepair. Instead it is recommend to debug applications on the Windows host PC before deploying to the ComfilePi. In the unusual case where a program must be debugged on the ComfilePi, one can use the SDB command-line debugger.
NOTE: Mono is not a perfect implementation of the .Net Framework (though it's quite good). You may need to make some adjustments to your code or choose Mono-compatible libraries in some situations, but those situations are typically the exception, not the rule.
Mono does not support WPF applications.
Check if Mono is already installed. Run the command mono -V
to verify.
$ mono -V Mono JIT compiler version 4.8.0 (Stable 4.8.0.495/e4a3cf3 Wed Feb 22 18:27:02 UTC 2017) Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com TLS: __thread SIGSEGV: normal Notifications: epoll Architecture: armel,vfphard Disabled: none Misc: softdebug LLVM: supported, not enabled. GC: sgen
If it isn't installed, it can be installed with sudo apt install mono-complete
or by following the Mono Project's installation instructions for the Raspberry Pi.
If you are using Visual Basic, then you will likely also want to install mono-vbnc
for dependencies such as Microsoft.VisualBasic
.
sudo apt-get install mono-vbnc
This documentation will take you through all of the steps necessary to set up the development environment on a Windows PC, build a .Net application, and deploy and execute it on the ComfilePi.
The following video provides a brief illustration of the procedure.
Download the Visual Studio installer from https://www.visualstudio.com/. Be sure to select the .Net desktop development component during the installation.
Create a new C# WinForms application by selecting Windows Classic Desktop–>Windows Forms App (.NET Framework) project template. Name the project Hello World.
Add a Button and a Label control to the form. Change the button's Text property to Say Hello.
Double-click the button to add a click event handler as shown in the code below.
using System; using System.Windows.Forms; namespace HelloWorld { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { label1.Text = "Hello, World!"; } } }
Press Start in the Visual Studio toolbar to execute and debug the program.
Press the Say Hello button. The button1_click
event handler will fire, and the label will change to read Hello, World!.
The typical way to connect to the ComfilePi from a Windows Desktop PC is via Ethernet. The ComfilePi has built-in Ethernet port, and once connected to a network it will automatically obtain an IP address via DHCP.
To obtain the IP address, run hostname -I
from a command console, or touch or float the mouse cursor over the Wireless & Wired Network Settings item from the ComfilePi's desktop panel.
Typically, a remote connection between the Windows PC and the ComfilePi is established via SSH. Be sure the SSH Server is enabled on the Comfile Pi. Enabling the SSH server also enables an SFTP server for copying files.
At this time, Windows does not include an SSH client, so 3rd party utilities are needed. For this demonstration we'll use the FileZilla Client to copy our executable files from the Windows PC to the ComfilePi. Download the FileZilla Client and install it on the Windows PC.
Once installed run the FileZilla Client and connect to the ComfilePi by entering its IP address, username (default: pi), password (default: raspberry) and port (22 for SFTP), and pressing the Quickconnect button.
Drag and drop the files from the Windows PC to the ComfilePi.
The procedure above can be tedious and inefficient while one is iterating on the development of their software. In the steps below, we will automate the process with the pscp and plink utilities and Visual Studio's post-build event.
plink -no-antispoof -pw raspberry pi@192.168.233.18 mkdir -p $(ProjectName) pscp -r -pw raspberry "$(ProjectDir)$(OutDir)\*" pi@192.168.233.18:$(ProjectName)
The plink
command will ensure a folder home/pi/$(ProjectName)
exists on the ComfilePi, and the pscp
command will upload the necessary binary files to that folder on the ComfilePi.
export DISPLAY=:0.0
on the ComfilePi to ensure the program shows itself on the correct X display, and then executes the command mono HelloWorld/HelloWorld.exe
to execute the program.There are some Mono debugging extensions for Visual Studio, but they are not always maintained.
Another way to debug Mono projects running on the ComfilePi is to load the solution folder in Visual Studio Code, and use Microsoft's Visual Studio Code Mono Debugger:
Download the source code for this demonstration.