Main Site Documentation

FEZ Lynx S4


#1

EDIT:
I am sorry that my question is posted here… My fault. I have no idea why I put it here.

As usual… My bags are packed, I have the ticket, but my ship has already left port…

Having a bit of a problem creating a Serial port. (For the moment only Writing a test string)

Using Socket 4 Pin 4, CDBUS 0 - TX
Using Socket 4 Pin 5, CDBUS 1 - RX

Using a Breadboard X1 to read Socket 4 Pins 4&5.
No output seen

My guess is that I need to do something with ftd2xx_net.ftdi.ft_cbus_options but I have no idea what I should be doing to set the I/O.

A Bit long but what I have so far: The code is mostly code I found at FTDI



using FTD2XX_NET;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

/*
 FEZ Lynx S4 1.0
 FTDI created ports - A,B,C,D
 devices {FTD2XX_NET.FTDI.FT_DEVICE_INFO_NODE[4]}
 FTD2XX_NET.FTDI.FT_DEVICE_INFO_NODE[]

    Device Manager shows - Ports(COM & LTP) 
        USB Serial Port (COM4) Location: on USB Serial Converter A
        USB Serial Port (COM5) Location: on USB Serial Converter B
        USB Serial Port (COM6) Location: on USB Serial Converter C
        USB Serial Port (COM7) Location: on USB Serial Converter D
     
*/

namespace FEZLynx
{
    class Program
    {
        static Timer timerWrite = null;
        static FTDI.FT_STATUS status;
        static FTDI lynx = null;
        static uint written = 0;

        static string TextContent = "This is a test string to be written\r\n";

        static void Main(string[] args)
        {
            
            lynx = new FTDI();

            uint numDevices = 0;
            status = FTDI.FT_STATUS.FT_OK;

            status = lynx.GetNumberOfDevices(ref numDevices);

            if (status != FTDI.FT_STATUS.FT_OK)
            {
                Console.WriteLine("Failed to get number of devices (error " + status.ToString() + ")");
                Console.ReadKey();
                return;
            }
            Console.WriteLine(" Found " + numDevices.ToString() + " devices");
            FTDI.FT_DEVICE_INFO_NODE[] devices = new FTDI.FT_DEVICE_INFO_NODE[numDevices];

            status = lynx.GetDeviceList(devices);

            if (status != FTDI.FT_STATUS.FT_OK)
            {
                Console.WriteLine("Failed to get the list of devices (error " + status.ToString() + ")");
                Console.ReadKey();
                return;
            }

            //Should always be 4
            Console.WriteLine(" Found " + devices[0].Description);
            Console.WriteLine(" Found " + devices[1].Description);
            Console.WriteLine(" Found " + devices[2].Description);
            Console.WriteLine(" Found " + devices[3].Description);

            //Storage for device info list
            FTDI.FT_DEVICE_INFO_NODE[] DeviceList = new FTDI.FT_DEVICE_INFO_NODE[numDevices];

            Console.WriteLine("");
            status = lynx.GetDeviceList(DeviceList);
            if (status == FTDI.FT_STATUS.FT_OK)
            {
                for (UInt32 i = 0; i < numDevices; i++)
                {
                    Console.WriteLine("Device Index: " + i.ToString());
                    Console.WriteLine("Flags: " + String.Format("{0:x}", DeviceList[i].Flags));
                    Console.WriteLine("Type: " + DeviceList[i].Type.ToString());
                    Console.WriteLine("ID: " + String.Format("{0:x}", DeviceList[i].ID));
                    Console.WriteLine("Location ID: " + String.Format("{0:x}", DeviceList[i].LocId));
                    Console.WriteLine("Serial Number: " + DeviceList[i].SerialNumber.ToString());
                    Console.WriteLine("Description: " + DeviceList[i].Description.ToString());
                    Console.WriteLine("");
                }
            }

            Console.WriteLine("Press a key to continue");
            Console.ReadKey();

            Console.WriteLine("");

            // FT4232 Bus available ADBUS, BDBUS, CDBUS, DDBUS
            //Socket 4 S/X
            //CDBUS0, Pin38, CD0/TX, Socket 4 Pin 4 - output
            //CDBUS1, Pin39, CD1/RX, Socket 4 Pin 5 - input
            status = lynx.OpenByDescription(devices[2].Description);

            if (status != FTDI.FT_STATUS.FT_OK)
            {
                Console.WriteLine("Failed to open device C (error " + status.ToString() + ")");
                Console.ReadKey();
                return;
            }
            else
            {
                Console.WriteLine("Opened device C " + devices[2].Description);
            }
            //

            // Not all is needed but I will set anyway

            //Set the speed
            status = lynx.SetBaudRate(9600);
            if (status != FTDI.FT_STATUS.FT_OK)
            {
                Console.WriteLine("Failed to set Baud rate for device C (error " + status.ToString() + ")");
                Console.ReadKey();
                return;
            }
            else
            {
                Console.WriteLine("Set Baud rate for device C to 9600");
            }
            //

            //Set Characteristics
            status = lynx.SetDataCharacteristics(FTDI.FT_DATA_BITS.FT_BITS_8, 
                FTDI.FT_STOP_BITS.FT_STOP_BITS_1, 
                FTDI.FT_PARITY.FT_PARITY_NONE);
            if (status != FTDI.FT_STATUS.FT_OK)
            {
                Console.WriteLine("Failed to set DataCharacteristics for device C (error " + status.ToString() + ")");
                Console.ReadKey();
                return;
            }
            else
            {
                Console.WriteLine("Set DataCharacteristics for device C to DataBits 8, StopBits 1, Parity None");
            }
            //

            //Set flowcontrol
            status = lynx.SetFlowControl(FTDI.FT_FLOW_CONTROL.FT_FLOW_NONE, 0x00, 0x00);
            if (status != FTDI.FT_STATUS.FT_OK)
            {
                Console.WriteLine("Failed to set FlowControl for device C (error " + status.ToString() + ")");
                Console.ReadKey();
                return;
            }
            else
            {
                Console.WriteLine("Set FlowControl for device C to None");
            }
            //

            //Set read timeout to 5 seconds, write timeout to infinite
            status = lynx.SetTimeouts(5000, 0);
            if (status != FTDI.FT_STATUS.FT_OK)
            {
                // Wait for a key press
                Console.WriteLine("Failed to set timeouts (error " + status.ToString() + ")");
                Console.ReadKey();
                return;
            }
            else
            {
                Console.WriteLine("Set SetTimeouts for device C to Read 5 seconds, Write infinite");
            }
            //
            Console.WriteLine("");

            //Start our write timer
            timerWrite = new Timer(new TimerCallback(Timer_TickWrite), null, 2000, 500);

            Thread.Sleep(-1);
            //return;
        }
        //

        static int ctr = 0;

        static void Timer_TickWrite(object sender)
        {
            //Need bytes
            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(TextContent);

            status = lynx.Write(bytes, bytes.Length, ref written);
            
            lynx.Purge(FTDI.FT_PURGE.FT_PURGE_TX);
            Console.WriteLine("Bytes written: " + written.ToString() + " " + ctr.ToString());
            

            ctr++;
            if (status != FTDI.FT_STATUS.FT_OK)
                return;
        }
        //
    }
}


Thanks for any help you can provide


#2

What are you trying to do?

Btw, no need to get device list twice.


#3

@ Architect -

Btw, no need to get device list twice

The code is only a test. I added the second just to see what the information was. There is no need for it other than info. In fact most of the code is only there for my testing to try and find out what is wrong.

I want to read/write using serial on Socket 4, pins 4/5. The write loop is only for continuous output while I looked for a signal. There is no output on TX


#4

@ willgeorge - I may have simply missed it in your source, but I am not seeing the DBUS being setup as a serial device. Not sure what it is in the C# library, but in the C++ library it is FT_SetBitMode.

Please see FTDI AN2232C-02 for the bit modes available:
www.ftdichip.com/Documents/AppNotes/AN2232C-02_FT2232CBitMode.pdf


#5

@ James -

Thank you for the link. I think that will get me going…