Testing COM communication

Hello, I’ve been a programmer for 10+ years and am fascinated by NETMF. I am new to it, but want to keep learning more. For my first project, I want to test communication through (UART) COM ports. From what I’ve read on the documents & this forum, COM1 port is pin Di1 & Di0, COM4 is An2 & An3(Needs to be programmatically remapped).

My question is, can I take a wire and directly connect COM1 to COM4 to test send/receive?

Thanks for your help!

Yes you can or easier just wire Di1 to Di0 and you will be receiving what you are sending.

Aha!!! Very true. I will try that. Thanks for your reply!

And remapping is explained in the free book, if you might not know how.

Hello,

I have received my FEZ_Domino this week and I’m testing it.

When I have checked the serial communication with the example from the page 78 of the “Beginners guide to NETMF” using a jumper between Di0-Di1 I haven’t any response (the same with the COM2).

The analog and digital pins work properly.

I don’t know what happen, how can I tested the serial communication?

Thank you very much for your reply

Please show us the code you are using, and list the assemblies you are referencing.

There was a bug in the book code that was fixed 2 days ago. Maybe the book still has some error?

Hello,

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.

Could I test the serial funtion of the USBizi by other way.

Best regards

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);
            }
        }
    }
}

Code looks correct but I will try this at work tomorrow and let you know.

Where did you add the loop-back wire? You are suing COM1 so the wire has to be in between Di0 and Di1…the pins in the very corner.

OK, I have a couple of versions here…

Both work on my Domino with a jumper between Di0 & Di1

This version fixes the code in the eBook (with additional debug feedback)
NOTE: Only works for sending 3 character strings.

using System;
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", 115200);
            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
                Debug.Print("Writing Data");
                UART.Write(tx_data, 0, tx_data.Length);
                // wait to make sure data is transmitted
                Thread.Sleep(100);
                // read the data
                Debug.Print("Reading Data");
                read_count = UART.Read(rx_data, 0, tx_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!");
                                String receivedDataAsString = new String(Encoding.UTF8.GetChars(rx_data));
                                Debug.Print("Read data=" + receivedDataAsString);
                            }
                        }
                    }
                }
                Thread.Sleep(100);
            }
        }
    }
}

This version uses the event handler “SerialDataReceivedEventHandler”

using System;
using System.Threading;
using System.IO.Ports;
using System.Text;
using Microsoft.SPOT;


namespace MFConsoleApplication1
{
    public class serial_test
    {

        public static int read_count = 0;
        public static byte[] rx_data = new byte[10];
        public static byte[] tx_data;
        public static SerialPort UART = null;
        public static void Main()
        {
            UART = new SerialPort("COM1", 115200);
            UART.Open();
            UART.DataReceived += new SerialDataReceivedEventHandler(UART_DataReceived);

            tx_data = Encoding.UTF8.GetBytes("FEZ");

            while (true)
            {
                // flush all data
                UART.Flush();
                Debug.Print("Writing data");
                // send some data
                UART.Write(tx_data, 0, tx_data.Length);
                // wait to make sure data is transmitted
                Thread.Sleep(5000);
            }
        }
        private static void UART_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            // read the data
            read_count = UART.Read(rx_data, 0, UART.BytesToRead);
            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!");
                            String receivedDataAsString = new String(Encoding.UTF8.GetChars(rx_data));
                            Debug.Print(receivedDataAsString);
                        }
                    }
                }
            }
            Thread.Sleep(100);
        }
    }
}

Thanks,

I put the wire between the Dio0 and Dio1. So I think that isn’t the problem.

Thanks for the example but … I have the same results.

I don’t know what more to do … :frowning: :frowning: :frowning:

The next step is to try a different serial port. Di0 and Di1 may have been damaged somehow?

Look at FEZ Domino brochure and find the other serial port (the one on UEXT header) then try it

In the code above, which used a SerialDataReceivedEventHandler, you might receive a length error even if the com port is working correctly.

The code assumes that when the event occurs there will be three bytes queued for reading. This might be a wrong assumption. Threre could be 1, 2 or 3 bytes in the queue.

The UART.BytesToRead call returns the number of queued bytes.

Does running this code return a read count error with a value greater than zero?

First of all, I would like to thanks you. It’s great to have this “online” support from the other part of the world. :stuck_out_tongue:

Resume.
I have tested another time my COM1 ann the results wasn’t good. A haven’t any response. But COM2 work properly. When I tested it (after having tested COM1 so imagin my face) I put a jumper on the UEXT connector, but the connection wasn’t good. I changed it and all it’s ok to the COM2.

I think COM1 it’s dead.

thanks

dead or you are using the wrong pins? Can you take a picture and post here?

Also look at the pins make sure they are soldered fine…then follow the traces all the way to the processor. Check if you see anything obvious.

Did you connect something to these pins before? It is easy to damage processor pins :frowning:

I found one of the problems with the COM2. The UEXT connector has only soldered only one pin ¡¡¡¡ all the other are into the air. So when a push a little the junper with my hand the communication it’s ok. :smiley:

But the COM1 … I haven’t connect anything before the test and I the connection between Di0 and Di1 is fine (nothing extrange).

Today I haven’t any camera but tomorrow I will send you some photos

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)