1

I was going through planty of nf samples (many thanks for that), but couldn't find any, where I can read data sent by USB cable (serial port).

In arduino I would simply write: Serial.readString() to get data sent through COM. How that could be acomplished in nanoframework?

titol
  • 999
  • 13
  • 25

1 Answers1

1

You should use the System.IO.Ports API. Windows.Devices.SerialCommunication is the UWP API that we're discontinuing and replacing with the IoT Core API.

Please check the sample pack here and look at Scenario3 Read. After properly setting up the SerialPort device, you can call serialDevice.Read(buffer, 0, buffer.Length).

José Simões
  • 606
  • 1
  • 5
  • 12
  • Thanks Jose, I've seen that, but will this read from connected USB cable, or external device that is connected to GPIO? I have ESP-WROOM-32 kit. There is an USB port. Can I make nano framework to read from that USB port? Also, what is the difference between `Windows.Devices.SerialCommunication` and `SerialCommunication`? Thanks for response – titol Sep 20 '21 at 18:02
  • 1
    SerialDevice will read from the MCU UART, if that's connected to a serial converter, you can read what's being received on the UART. If you're asking about the MCU acting as USB Host, that's not currently supported. Now, for reading GPIO pins you'll need the [GpioPin](https://docs.nanoframework.net/api/System.Device.Gpio.GpioPin.html) class. – José Simões Sep 21 '21 at 08:45