RAGHUL N M
Posts: 1
Joined: Sat Jul 14, 2018 1:30 pm

C# Visual Studio UART dataReader problem

Sun Jul 15, 2018 4:59 am

I am using Raspberry Pi 3 Model B. I have installed Windows 10 IOT Core in it. I am using Visual Studio 15 to develop a UWP App in C# and deployed an App on the board. It reads GPS data through UART pins 8 and 10 from Neo6mv2 GPS module and displays the raw data in a text box. Simple.

I have configured the UART port using the function below:

public async void UART_Config()
{

string selector = SerialDevice.GetDeviceSelector("UART0");
DeviceInformationCollection devices = await DeviceInformation.FindAllAsync(selector);

if (devices.Count > 0)
{
DeviceInformation deviceInfo = devices[0];
serialDevice = await SerialDevice.FromIdAsync(deviceInfo.Id);
dataReader = new DataReader(serialDevice.InputStream);
dataWriter = new DataWriter(serialDevice.OutputStream);
bytesToRead = await dataReader.LoadAsync(maxReadLength);

}
else
{

}
}


I read the data inside a tick Timer function which is called at an interval of 1 second. The GPS sensor gives a series of string lines with '\n' at the end of each line. So I am separating the lines using a while loop and updating each line in the text box Location.Text.

public void AcQ_Tick(object sender, object e)
{
rxBuffer = ""; // string rxBuffer
try
{
while (dataReader.ReadString(1) != "\n")
{
rxBuffer += dataReader.ReadString(1);
}
Location.Text = rxBuffer;
}
catch (Exception e1)
{
Status.Text = e1.ToString();
}
}

The problem is, after a few lines of successful data output every time I reload the program, the raspberry pi throws an exception at "dataReader.ReadString(1) " function inside while loop . It never reads data after that.

The exception thrown is
"System.Runtime.InteropServices.COMException (0x8000000B): The operation attempted to access data outside the valid range\r\n\r\nThe operation attempted to access data outside the valid range\r\n\r\n at Windows.Storage.Streams.DataReader.ReadString(UInt32 codeUnitCount)\r\n"

I checked the output of the GPS sensor through putty. I can see the values coming continuously. So no problem with the sensor.
Since I can see a few lines of data from the raspberry pi at the beginning, I understood that there is no wrong in connection.

Anyone know where I went wrong?

Thank You for your time.

User avatar
topguy
Posts: 5001
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: C# Visual Studio UART dataReader problem

Mon Jul 16, 2018 11:51 am

Disclaimer: I know nothing of C# and UWP.

I see that examples use:

Code: Select all

while (dataReader.UnconsumedBufferLength > 0)
.. to avoid reading from an empty buffer. ( which is how I interpret the exception )

Return to “Windows 10 for IoT”