Below is firmware info - I’ve checked both sides and they match.
I’m getting an exception error when checking amount of data received on the com port in the serial event code.
Below is my code.
The code runs in the debugger. It flashes the LED and sends data out the com port to teraterm which is connected to the com port. When I send data into the com port, the serial event fires, but I get an exception error when checking how many bytes are in the com port buffer -
int Bytes2Read = UART.BytesToRead;
This code works on .net framework and .net compactframework. Am I doing something wrong?
Any help is greatly appreciated.
using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using GHIElectronics.NETMF.FEZ;
using System.Threading;
using System.IO.Ports;
using System.Text;
using BuffMgr;//needed to build a scan or swipe
namespace FEZ_Mini_Application1
{
public class Program
{
public static int read_count = 0;
public static byte[] rx_data = new byte[10];
public static byte[] tx_data;
public static SerialPort UART = null;
// Blink board LED
public static bool ledState = true;
public static OutputPort led = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.LED, ledState);
public static void Main()
{
int counter = 0;
SerialPort UART = new SerialPort("COM1", 115200);
UART.Open();
UART.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);
while (true)
{
// create a string
string counter_string = "Count: " + counter.ToString() +
"\r\n";
// convert the string to bytes
byte[] buffer = Encoding.UTF8.GetBytes(counter_string);
// send the bytes on the serial port
UART.Write(buffer, 0, buffer.Length);
// increment the counter;
counter++;
//wait...
Thread.Sleep(100);
// toggle LED state
ledState = !ledState;
led.Write(ledState);
}
}
static void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
// Visual indication of data received.
led.Write(false);
// Read the number of bytes to read from the serialport
int Bytes2Read = UART.BytesToRead;
// Create local array to put data from serialport in.
byte[] bytearray = new byte[Bytes2Read];
// Read the bytes from the serial port
UART.Read(bytearray, 0, Bytes2Read);
}
}
}
Using FEZ Mini· FEZ Mini V 4.1.6.0
SDK Version 1.0.15
ClrInfo.targetFrameworkVersion: 4.1.2821.0
SolutionReleaseInfo.solutionVersion: 4.1.6.0
SolutionReleaseInfo.solutionVendorInfo: GHI Electronics, LLC
SoftwareVersion.BuildDate: Jun 24 2011