Reputation: 205
I about to start learning Xamarin for the first time and was hoping I could be pointed in the right direction. Currently I can write ASP.Net MVC 5 applications. I'm interested in communicating with a Raspberry Pi for IOS and Android devices and from what I read online, the Mono Framework is the best approach for this. Please correct me if I'm wrong.
My question is if I can use Xamarin Forms as opposed to Xamarin Native UI and if Mono Framework is something I can implement with Xamarin Forms or is it a completely separate thing I need to do instead Xamarin Forms. I hope this isn't too confusing, but I'm just trying to understand what works with what so that I can create a roadmap for myself.
Upvotes: 0
Views: 6363
Reputation: 1176
I use a Raspberry Pi as my main computer. I use MonoDevelop to write C# programs and mono to run them. I use System.Windows.Forms for my GUI. When I'm done, I have an .exe that can run on the Raspberry Pi or Windows. I have a class that helps me add controls to the form at run time.
public static class ControlCreator
{
public static void Add(this Control.ControlCollection collection
,out GroupBox box,string id, string text, int left, int top
, int width, int height)
{
box = new GroupBox();
box.Text = text;
AddControl (collection,box,id,left,top,width,height);
return;
}
public static void Add(this Control.ControlCollection collection
,out Button box,string id, string text, int left, int top
, int width, int height)
{
box = new Button();
box.Text = text;
AddControl (collection,box,id,left,top,width,height);
return;
}
public static void Add(this Control.ControlCollection collection
,out Label box,string id, string text, int left, int top
, int width, int height)
{
box = new Label();
box.Text = text;
AddControl (collection,box,id,left,top,width,height);
return;
}
private static void AddControl(
Control.ControlCollection collection,Control box,string id, int left
, int top, int width, int height)
{
box.Name = id;
box.Left = left;
box.Top = top;
box.Width = width;
box.Height = height;
collection.Add(box);
return;
}
}
Upvotes: 2
Reputation: 24460
The Raspberry Pi (RPi) can run Android and only then you would be able to utilise what Xamarin provides. In that case you would be able to make a Xamarin.Android app and run it on the RPi.
However, you want to run some kind of server on the RPi and communicate with an App on an iOS or Android Device, which would run a Xamarin App. Here it doesn't matter whether this app uses Xamarin.Forms or not.
Server side
What you could do server side on the Raspberry Pi, which probably would be the easiest for you. Is to download and install Windows 10 IoT Core. Then you could run a ASP.NET WebAPI or MVC app on it.
Alternatively you could do this on Raspbian or any other Linux based distribution running on the RPi, just using .NET Core instead.
Either solution would give you the possibility of sharing serialization contracts between the server and client.
Phone App Side
On the phone you would just have a client communicating with the server on the RPi. There are several very good articles on writing resilient API Clients when using Xamarin (doesn't matter if you are using Forms or not).
This is a personal preference, but I would use Refit to define the API for the server. Along with Polly to retry or circuit-break failed requests. I am not affiliated with any of those whatsoever.
In the end, it doesn't matter what runs in the App or on the Server, they are two separate entities and the only thing you most likely will share is the contracts for the data you are exchanging.
Upvotes: 3