Javier,
[quote]The code I used is this.
I can compile and download to the board, and the debug message is always “Wrong size: 0”.
I have reinstalled the firmware (4.0.3) and there is no result.
[/quote]
using System.Threading;
using System.IO.Ports;
using System.Text;
using Microsoft.SPOT;
namespace MFConsoleApplication1
{
public class Program
{
public static void Main()
{
SerialPort UART = new SerialPort("COM1", 19200);
UART.ReadTimeout = 10;
int read_count = 0;
byte[] tx_data;
byte[] rx_data = new byte[10];
tx_data = Encoding.UTF8.GetBytes("FEZ");
UART.Open();
while (true)
{
// flush all data
UART.Flush();
// send some data
UART.Write(tx_data, 0, tx_data.Length);
// wait to make sure data is transmitted
Thread.Sleep(100);
// read the data
read_count = UART.Read(rx_data, 0, rx_data.Length);
if (read_count != 3)
{
// we sent 3 so we should have 3 back
Debug.Print("Wrong size: " + read_count.ToString());
}
else
{
// the count is correct so check the values
// I am doing this the easy way so the cod eis more clearif (tx_data[0] == rx_data[0])
{
if (tx_data[1] == rx_data[1])
{
if (tx_data[1] == rx_data[1])
{
Debug.Print("Perfect data!");
}
}
}
}
Thread.Sleep(100);
}
}
}
}
I noticed that there are some issues in the code you used here,
First, if you use the code as you posted here, it won’t work!
if you look at the code, about line 35-36
you will see that the if statement got commented out.
// the count is correct so check the values
// I am doing this the easy way so the cod eis more clearif (tx_data[0] == rx_data[0])
{
if (tx_data[1] == rx_data[1])
{
it supposed to be like this
// the count is correct so check the values
// I am doing this the easy way so the cod eis more clear
if (tx_data[0] == rx_data[0])
{
if (tx_data[1] == rx_data[1])
{
and secondly, the if statement that encapsulated the Debug.Print(…)
should be number 2 instead of 1, anyway just use this following code, and see what happened, OK?
using System.Threading;
using System.IO.Ports;
using System.Text;
using Microsoft.SPOT;
namespace MFConsoleApplication1
{
public class Program
{
public static void Main()
{
SerialPort UART = new SerialPort("COM1", 19200);
UART.ReadTimeout = 10;
int read_count = 0;
byte[] tx_data;
byte[] rx_data = new byte[10];
tx_data = Encoding.UTF8.GetBytes("FEZ");
UART.Open();
while (true)
{
// flush all data
UART.Flush();
// send some data
UART.Write(tx_data, 0, tx_data.Length);
// wait to make sure data is transmitted
Thread.Sleep(100);
// read the data
read_count = UART.Read(rx_data, 0, rx_data.Length);
if (read_count != 3)
{
// we sent 3 so we should have 3 back
Debug.Print("Wrong size: " + read_count.ToString());
}
else
{
// the count is correct so check the values
// I am doing this the easy way so the cod eis more clear
if (tx_data[0] == rx_data[0])
{
if (tx_data[1] == rx_data[1])
{
if (tx_data[2] == rx_data[2])
{
Debug.Print("Perfect data!");
}
}
}
}
Thread.Sleep(100);
}
}
}
}
[quote]Could I test the serial funtion of the USBizi by other way.
[/quote]
I just put up a tutorial regarding UART(Serial) Interface with FTDI cable.
Another way to use FTDI cable to test your COM port. If you have a cable available.
Follow this link;
(link removed)