2017-04-14 209 views
0

我第一次開始學習Xamarin,並希望我能指出正確的方向。目前我可以編寫ASP.Net MVC 5應用程序。我有興趣與IOS和Android設備的Raspberry Pi進行通信,並且從我在線閱讀的內容來看,Mono Framework是最好的方法。如果我錯了,請糾正我。Xamarin和Raspberry Pi

我的問題是,如果我可以使用Xamarin Forms而不是Xamarin Native UI,並且如果Mono Framework是我可以用Xamarin Forms實現的東西,或者是我需要做的完全獨立的事情,而不是Xamarin Forms。我希望這不是太令人困惑,但我只是想了解什麼與什麼一起工作,以便我可以爲自己制定路線圖。

+0

XF是Android和iOS的UI層。它不在RPi上運行。您可以使用在PI上運行的任何語言編寫Web服務,並與運行在Android/iOS上的XF應用程序進行通信。 – Jason

+0

我明白你在說Xamarin Forms是UI層,從我讀的內容,Xamarin,IOS和Xamarin.Android構建在Mono之上。這與Xamarin Forms相同嗎? – Andy

+0

XF在X.iOS和X.Android之上運行 – Jason

回答

2

的樹莓派(RPI)可以運行Android和只有這樣,你將能夠利用什麼Xamarin提供。在這種情況下,您將能夠製作Xamarin.Android應用程序並在RPi上運行它。

然而,要在RPI運行某種服務器和iOS或Android設備,這將運行一個應用程序Xamarin與應用程序進行通信。 這裏應用程序是否使用Xamarin.Forms並不重要。

服務器端

,你可以在樹莓派,這可能將是最容易爲你做什麼服務器端。是下載並安裝Windows 10 IoT Core。然後你可以運行一個ASP.NET WebAPI或MVC應用程序。

或者你可以做到這一點上Raspbian或在RPI運行的任何其他基於Linux的發行,只是用.NET的核心來代替。

兩種解決方案會給你的共享服務器和客戶端之間的系列化合同的可能性。

手機應用程序方面

在手機上,你只會有一個客戶端上的RPI服務器通信。在使用Xamarin編寫彈性API客戶端時,有幾篇非常好的文章(如果您使用的是Forms,則無關緊要)。

這是個人喜好,但我會用Refit定義服務器的API。隨着Polly重試或斷路失敗的請求。我不附屬於任何這些。

最後,它並不重要的應用程序或服務器上運行,它們是兩個獨立的實體,您最有可能會分享的唯一事情是你正在交換數據的合同。

+0

感謝您的解釋。這有助於很多 – Andy

0

我使用Raspberry Pi作爲我的主電腦。我使用MonoDevelop編寫C#程序和單聲道來運行它們。我爲我的GUI使用System.Windows.Forms。當我完成後,我有一個可以在Raspberry Pi或Windows上運行的.exe。我有一個類可以幫助我在運行時向窗體添加控件。

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; 
    } 
}