0

I have a relatively simple Winform application used to communicate with an Arduino via USB to Serial. I would like to make it as universal as possible, using Xamarin Forms.

My problem is that it seems there is no way to do this for both Android and UWP (my priorities, IoS "maybe" in the future). Googling around I found there is a System.IO.Ports.SerialPortdocumented in Xamarin documentation, but I did not find any way to add this library to either Droid and UWP projects.

If I need to, I guess I could write an Interface and have different implementations depending on which project is compiled, but I would love to find some examples.

I would also like to use WiFi as serial instead of USB and let the user choose which way he wants to link to the Arduino. All of this is no big deal in Winform, so I am quite surprised this looks close to be impossible on Xamarin!

Thanks for any help and pointers in the right direction. I would hate to have to abandon this project, but in the same time I cannot spend a lot of time on something which does not seems to be implemented (as of now).

BernardG
  • 1,921
  • 3
  • 16
  • 25

2 Answers2

1

It looks like you need to use an external library for Droid portion. See: Comunicating with serial USB device over Android and specifically the project at https://github.com/felHR85/UsbSerial. How to add this to Xamarin is something I don't understand, yet.

UWP uses the Device.Serial class, not System.IO.Serial class. So in the end this level of code will be in a platform dependent layer of your code, one for each platform.

Community
  • 1
  • 1
gerritv
  • 21
  • 3
0

You should review the source of the Monkey.Robotics project as it has examples of using USB, Wifi, Bluetooth for commucations with .NET MF micro controllers and non-.Net MF controllers like Arduino.

Monkey.Robotics

The Mobile stack consists of three different parts:

  • Low-level Bluetooth LE (BLE) API - A cross-platform API (iOS and Android only right now) that supports communicating with BLE devices.

  • Low-Level Wifi API - A cross-platform API (iOS and Android only right now) that supports connecting to WiFi enabled devices. Note that the WiFi API is still in progress.

  • Messaging Framework - A high-level cross-platform protocol for messaging peripherals via WiFi or BLE.

  • Peripheral Libraries - Strongly typed libraries for communicating with various vendor-specific peripherals such as health monitoring devices, smart watches, and the like.

Ref: https://github.com/xamarin/Monkey.Robotics

Community
  • 1
  • 1
SushiHangover
  • 68,368
  • 9
  • 89
  • 150
  • Thank you for your answer, I will have a look. Not sure if it really matches my needs, but I'll investigate. – BernardG Aug 26 '16 at 18:40