I try to communicate with device with serial communication.
My code is:
using System.Diagnostics;
using System.Threading;
using Bauland.Pins;
using GHIElectronics.TinyCLR.Devices.SerialCommunication;
using GHIElectronics.TinyCLR.Storage.Streams;
namespace TestNetduino3Serial
{
static class Program
{
private static DataReader _dataReader;
private static DataWriter _dataWriter;
static void Main()
{
var serial = SerialDevice.FromId(Netduino3.UartPort.Uart6);
serial.BaudRate = 9600;
_dataWriter=new DataWriter(serial.OutputStream);
_dataReader=new DataReader(serial.InputStream);
Thread t=new Thread(Receiver);
t.Start();
while (true)
{
Thread.Sleep(20);
}
// ReSharper disable once FunctionNeverReturns
}
private static void Receiver()
{
while (true)
{
var count=_dataReader.Load(1);
if (count > 0)
{
byte b = _dataReader.ReadByte();
Debug.WriteLine("Data: 0x"+b.ToString("X"));
}
Thread.Sleep(20);
}
}
}
}
When I execute it, I have an allocation failure message:
Found debugger!
Create TS.
Loading Deployment Assemblies.
Attaching deployed file.
Assembly: TestNetduino3Serial (1.0.0.0) Attaching deployed file.
Assembly: mscorlib (0.8.0.0) Attaching deployed file.
Assembly: GHIElectronics.TinyCLR.Devices (0.8.0.0) Attaching deployed file.
Assembly: GHIElectronics.TinyCLR.Storage (0.8.0.0) Resolving.
The debugging target runtime is loading the application assemblies and starting execution.
Ready.
'GHIElectronics.TinyCLR.VisualStudio.dll' (Managed): Loaded 'd:\Documents\Visual Studio 2017\Projects\TestNetduino3Serial\TestNetduino3Serial\bin\Debug\pe\..\GHIElectronics.TinyCLR.Storage.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'GHIElectronics.TinyCLR.VisualStudio.dll' (Managed): Loaded 'd:\Documents\Visual Studio 2017\Projects\TestNetduino3Serial\TestNetduino3Serial\bin\Debug\pe\..\GHIElectronics.TinyCLR.Devices.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'GHIElectronics.TinyCLR.VisualStudio.dll' (Managed): Loaded 'd:\Documents\Visual Studio 2017\Projects\TestNetduino3Serial\TestNetduino3Serial\bin\Debug\pe\..\TestNetduino3Serial.exe', Symbols loaded.
The thread '<No Name>' (0x2) has exited with code 0 (0x0).
Failed allocation for 122041945 blocks, 1952671120 bytes
If I try with FEZPandaIII (by changing to Usart1), I don’t have this issue. Does someone have an explanation ? a clue ? or is it a bug ???