Fez Spider Uart to PC serial port data transfer

Hi,
I have just bought a Fez Spider. I am trying to send data from Spider Uart ports to my PC serial port. I didnt use any Gadgeteer module. I have connected Fez Spider socket 4 pins 5,4 as TX ,RX as com2 to MAX232 and 9 pin serial connector. And also socket 8 pins 5,4 and socket 11 pins 5,4 on spider are connected to two more MAX232 with 9 pin serial connecters. And I connected one of these 3 connecters to my PC com port. From hyperterminal on my PC I can connect to each 3 com ports, but can not get or send any data. The below is the code.
Do I miss anything?


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

using System.IO;

namespace MFConsoleApplication1
{
    public class Program
    {
        
        static SerialPort UART1 = new SerialPort("COM1", 57600, Parity.None, 8, StopBits.One);
        static SerialPort UART2 = new SerialPort("COM2", 57600, Parity.None, 8, StopBits.One);
        static SerialPort UART3 = new SerialPort("COM3", 57600, Parity.None, 8, StopBits.One);
       
        static void port1_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            byte[] buffer = new byte[UART3.BytesToRead];
            UART3.Read(buffer, 0, buffer.Length);
            UART3.DiscardInBuffer();
            UART3.Flush();
            string output_imu = bytesToString(buffer);
            Debug.Print("com1:" + output_imu);
            output_imu = null;
            buffer = null;
        }
        static void port2_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            byte[] buffer = new byte[UART3.BytesToRead];
            UART3.Read(buffer, 0, buffer.Length);
            UART3.DiscardInBuffer();
            UART3.Flush();
            string output_imu = bytesToString(buffer);
            Debug.Print("com2:" + output_imu);
            output_imu = null;
            buffer = null;
        }
        static void port3_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            byte[] buffer = new byte[UART3.BytesToRead];
            UART3.Read(buffer, 0, buffer.Length);
            UART3.DiscardInBuffer();
            UART3.Flush();
            string output_imu = bytesToString(buffer);
            Debug.Print("com3:" + output_imu);
            output_imu = null;
            buffer = null;
        }
        public static string bytesToString(byte[] bytes)
        {
            string s = "";
            for (int i = 0; i < bytes.Length; ++i)
                s += (char)bytes[i];
            return s;
        }


        
        public static void Main()
        {
            UART1.DataReceived += new SerialDataReceivedEventHandler(port1_DataReceived);
            UART2.DataReceived += new SerialDataReceivedEventHandler(port2_DataReceived);
            UART3.DataReceived += new SerialDataReceivedEventHandler(port3_DataReceived); 
          
            UART3.ReadTimeout = 10;
            int counter = 0;
            
            UART1.Open();
            UART2.Open();
            UART3.Open();
          
              while (true)
            {
                
              string counter_string =  counter.ToString() + "\r\n";
                                                    
              byte[] buffer1 = Encoding.UTF8.GetBytes("UART1:" +counter_string);
              byte[] buffer2 = Encoding.UTF8.GetBytes("UART2:" + counter_string);
              byte[] buffer3 = Encoding.UTF8.GetBytes("UART3:" + counter_string);

                UART1.Write(buffer1, 0, buffer1.Length);
                UART2.Write(buffer2, 0, buffer2.Length);
                UART3.Write(buffer3, 0, buffer3.Length);
               
                counter++;
               
                Thread.Sleep(500);
            }
           
        }

    }
}

I don’t have spider to check on the pins, but maybe you could advice my post with a USB to TTL board i had before 5 months:
http://www.tinyclr.com/forum/topic?id=6370&page=2

What i did was to put RX - RX and TX - TX on the board and fez mini.
Hope it works

1 Like

@ zorlualtun - Welcome…

try a new micro console app and see if this works…should send the date every second

static SerialPort xBeePort = new SerialPort("COM3",57600,Parity.None,8,StopBits.One);
        private static Timer _sendTimer;
 
        public static void Main()
        {
           xBeePort.Open();
           _sendTimer = new Timer(new TimerCallback(SendMessage), null, 1000, 100);
            Thread.Sleep(-1);
        }
        static void SendMessage(object o)
        {
            byte[] buffer = Encoding.UTF8.GetBytes(DateTime.Now.ToString() + "\r\n");
            xBeePort.Write(buffer, 0, buffer.Length);
            xBeePort.Flush();
        }

also wrap your code with code tags - (binary icon)

1 Like

It was my mistake. I reversed the RX and TX . It worked fine.
Thanks.

BTW. You should register for serial port events after you have opened the port, not before as you have done.