0

I have Xamarin PCL project and I try to read from serial port in Android part ("/dev/ttyS2") . When I try use SerialPort from System.IO.Ports I'm getting exception:

System.PlatformNotSupportedException: System.IO.Ports is currently only supported on Windows.

I also tried use SerialPortLib but I'm getting another exception:

System.TypeLoadException: Could not load type of field 'SerialPortLib.SerialPortInput:serialPort' (1) due to: Could not resolve type with token 01000002 (from typeref, class/assembly System.IO.Ports.SerialPort, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089) assembly:System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 type:System.IO.Ports.SerialPort member::

What is the best solution for reading from serial port in Xamarin Android?

Kambey
  • 96
  • 1
  • 7
  • You have access the usb controller in order to communicate with the "serial ports", There are a several OSS Android Usb to Serial libraries available in Java. I've used (https://github.com/mik3y/usb-serial-for-android) and (https://github.com/felHR85/UsbSerial) via `Xamarin.Android` binding libraries to talk to barcode readers, point-of-sale equipment, etc... This is **not** an endorsement of either library as they both have pros/cons and support different chipsets and use those chipsets in different ways. As always when dealing with hardware access, *buyer beware* ;-) – SushiHangover Aug 31 '17 at 15:00
  • As a side note, if you are using a particular USB-2-Serial adapter with your app, check with the vendor as they almost always have a Java library that is tuned for its usage with their chipsets (i.e FTDI, Prolific, etc.. have android java libraries for their chipset/hardware adapters) – SushiHangover Aug 31 '17 at 15:19

1 Answers1

2

Your exception is thrown because the class is not supported in .Net standard. I think because serial ports need to communicate with hardware and it depends on how the platform does this. Here is a similar question. If you want to use USB I think this can help you.

momvart
  • 1,737
  • 1
  • 20
  • 32