Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SerialData.Chars event doesn't work properly #610

Closed
rparrozzani opened this issue May 19, 2020 · 0 comments · Fixed by nanoframework/nf-interpreter#1645 or nanoframework/nf-interpreter#1658

Comments

@rparrozzani
Copy link

Details about Problem

nanoFramework area: (C# code)

VS version: (2017)

VS extension version: (1.4.0.196)

Target: (ESP32_WROOM_32)

Device capabilities output:

System Information
HAL build info: nanoFramework running @ ESP32
  Target:   ESP32_WROOM_32
  Platform: ESP32

Firmware build Info:
  Date:     May 17 2020
  Type:     MinSizeRel build with IDF v3.3.1
  Version:  1.4.0.196
  Compiler: GNU ARM GCC v5.2.0

OEM Product codes (vendor, model, SKU): 0, 0, 0

Serial Numbers (module, system):
  00000000000000000000000000000000
  0000000000000000


AppDomains:

Assemblies:
  ExampleSerial, 1.0.0.0
  nanoFramework.Hardware.Esp32, 1.2.1.0
  Windows.Devices.SerialCommunication, 1.2.1.0
  mscorlib, 1.7.2.0
  nanoFramework.System.Text, 1.0.0.0
  Windows.Storage.Streams, 1.8.2.0
  nanoFramework.Runtime.Events, 1.4.2.0

Native Assemblies:
  mscorlib v100.4.9.0, checksum 0x65E9CC45
  nanoFramework.Runtime.Native v100.0.6.2, checksum 0x210110C2
  nanoFramework.Hardware.Esp32 v100.0.7.1, checksum 0x1B75B894
  nanoFramework.Devices.OneWire v100.0.3.4, checksum 0xA5C172BD
  nanoFramework.Networking.Sntp v100.0.4.4, checksum 0xE2D9BDED
  nanoFramework.ResourceManager v100.0.0.1, checksum 0xDCD7DF4D
  nanoFramework.System.Collections v100.0.0.1, checksum 0x5A31313D
  nanoFramework.System.Text v100.0.0.1, checksum 0x8E6EB73D
  nanoFramework.Runtime.Events v100.0.7.1, checksum 0x0EAB00C9
  EventSink v1.0.0.0, checksum 0xF32F4C3E
  System.Math v100.0.4.4, checksum 0x39DA4F21
  System.Net v100.1.3.1, checksum 0x1118F266
  Windows.Devices.Adc v100.1.3.3, checksum 0xCA03579A
  Windows.Devices.Gpio v100.1.2.2, checksum 0xC41539BE
  Windows.Devices.I2c v100.2.0.2, checksum 0x79EDBF71
  Windows.Devices.Pwm v100.1.3.3, checksum 0xBA2E2251
  Windows.Devices.SerialCommunication v100.1.1.1, checksum 0x82260711
  Windows.Devices.Spi v100.1.4.1, checksum 0x59B5BFC3
  Windows.Devices.Wifi v100.0.6.1, checksum 0xDF2FD922
  Windows.Storage v100.0.2.0, checksum 0x5160A7B6


++++++++++++++++++++++++++++++++
++        Memory Map          ++
++++++++++++++++++++++++++++++++
  Type     Start       Size
++++++++++++++++++++++++++++++++
  RAM   0x3ffe436c  0x0001bc00
  FLASH 0x08000000  0x00400000


+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++                   Flash Sector Map                        ++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  Region     Start      Blocks   Bytes/Block    Usage
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      0    0x00010000       1      0x180000     nanoCLR
      1    0x00190000       1      0x1B0000     Deployment
      2    0x00340000       1      0x040000     Configuration


+++++++++++++++++++++++++++++++++++++++++++++++++++
++              Storage Usage Map                ++
+++++++++++++++++++++++++++++++++++++++++++++++++++
  Start        Size (kB)           Usage
+++++++++++++++++++++++++++++++++++++++++++++++++++
  0x00340000    0x040000 (256kB)    Configuration
  0x00010000    0x180000 (1536kB)   nanoCLR
  0x00190000    0x1B0000 (1728kB)   Deployment


Deployment Map
Empty

Description

During the reading operation on the serial port the "SerialData.Chars" event doesn't never fire up and "serialDevice.BytesToRead" is always 0.
Instead, if WatchChar is defined, "SerialData.WatchChar" event is successfully fired up.

Sample Project

Serial configuration on esp32

// Set pin configuration
Configuration.SetPinFunction(4, DeviceFunction.COM2_TX);
Configuration.SetPinFunction(5, DeviceFunction.COM2_RX);
Int32 pinTX = Configuration.GetFunctionPin(DeviceFunction.COM2_TX);
Int32 pinRX = Configuration.GetFunctionPin(DeviceFunction.COM2_RX);
Console.WriteLine("COM2 pins: TX " + pinTX + " - RX " + pinRX);

 // open COM
_serialDevice = SerialDevice.FromId("COM2");    // UART1

// set parameters
_serialDevice.BaudRate = 115200;
_serialDevice.Parity = SerialParity.None;
_serialDevice.StopBits = SerialStopBitCount.One;
_serialDevice.Handshake = SerialHandshake.None;
_serialDevice.DataBits = 8;
_serialDevice.ReadTimeout = new TimeSpan(0, 0, 2);

DataReader inputDataReader = new DataReader(_serialDevice.InputStream);
inputDataReader.InputStreamOptions = InputStreamOptions.Partial;

_serialDevice.DataReceived += SerialDataReceivedEventHandler;
// _serialDevice.WatchChar = '\r';

Event handler:

private static void SerialDataReceivedEventHandler(object sender, SerialDataReceivedEventArgs e)
        {
            if (e.EventType == SerialData.Chars)
            {
                Console.WriteLine("Chars event");   // This never works!!!!!!!!!!
            }
            else if (e.EventType == SerialData.WatchChar)
            {
                 Console.WriteLine("WatchChar event");    // This is OK if WatchChar is defined!!!
            }
        }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment