private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
        {
            FTD2XX_NET.FTDI dev = new FTDI();
            UInt32 numDevices = 0;
            dev.GetNumberOfDevices(ref numDevices);

            var pDest = new FTD2XX_NET.FTDI.FT_DEVICE_INFO_NODE[numDevices];
            dev.GetDeviceList(pDest);

            VIDPIDList = string.Empty;
            for (int i = 0; i < numDevices; i++ )
            {
                VIDPIDList += string.Format("{0} \n", pDest[i].ID);
            }
        }
Example #2
0
        public static Device CreateDevice(FTD2XX_NET.FTDI.FT_DEVICE_INFO_NODE deviceInfo)
        {
            if (deviceInfo.SerialNumber.Length < 2)
            {
                return(null);
            }
            string snPrefix = deviceInfo.SerialNumber.Substring(0, 2);

            switch (snPrefix)
            {
            case Devices.MultiradioV1.SN_PREFIX:
                if (Device.CheckDevice(deviceInfo, Devices.MultiradioV1.TYPE))
                {
                    return(new Devices.MultiradioV1(deviceInfo));
                }
                break;

            case Devices.MultiradioV1WithEncoder.SN_PREFIX:
                if (Device.CheckDevice(deviceInfo, Devices.MultiradioV1WithEncoder.TYPE))
                {
                    return(new Devices.MultiradioV1WithEncoder(deviceInfo));
                }
                break;

            case Devices.MCP737.SN_PREFIX:
                if (Device.CheckDevice(deviceInfo, Devices.MCP737.TYPE, true))
                {
                    return(new Devices.MCP737(deviceInfo));
                }
                break;
            }
            return(null);
        }
Example #3
0
        public void Initialize()
        {
            uint count  = 0;
            var  status = _device.GetNumberOfDevices(ref count);

            if (status != FTD2XX_NET.FTDI.FT_STATUS.FT_OK && count == 0)
            {
                throw new Exception("Device not found");
            }

            var description = new FTD2XX_NET.FTDI.FT_DEVICE_INFO_NODE[count];

            status = _device.GetDeviceList(description);

            if (status != FTD2XX_NET.FTDI.FT_STATUS.FT_OK)
            {
                throw new Exception("Failed to list Devices");
            }

            status = _device.OpenByDescription(description[0].Description);
            if (status != FTD2XX_NET.FTDI.FT_STATUS.FT_OK)
            {
                throw new Exception("Failed to open Device");
            }

            _thread      = new Thread(Loop);
            _thread.Name = "CAN Driver Loop";
            _thread.Start();
        }
Example #4
0
 protected Device(FTD2XX_NET.FTDI.FT_DEVICE_INFO_NODE deviceInfo, string name, DeviceType deviceType)
 {
     Running       = false;
     Name          = name;
     SerialNumber  = deviceInfo.SerialNumber;
     DeviceType    = deviceType;
     Configuration = Globals.Instance.GetConfiguration(SerialNumber, deviceType);
     Configuration.ConfigurationChangeEvent += new EventHandler(Configuration_ConfigurationChangeEvent);
     _enabled = Configuration.Enable;
 }
Example #5
0
        private void enablebtn_Click(object sender, EventArgs e)
        {
            try
            {
                UInt32 ftdiDeviceCount = 0;
                device.GetNumberOfDevices(ref ftdiDeviceCount);
                FTD2XX_NET.FTDI.FT_DEVICE_INFO_NODE[] devicelist = new FTD2XX_NET.FTDI.FT_DEVICE_INFO_NODE[ftdiDeviceCount];
                device.GetDeviceList(devicelist);

                ftstatus = device.OpenBySerialNumber(devicelist[0].SerialNumber);
                ftstatus = device.SetBitMode(0xff, 1);
                Console.WriteLine("Urzadzenie: " + ftstatus.ToString());
                stepLeftbtn.Enabled  = true;
                stepRightbtn.Enabled = true;
            }
            catch (Exception ee)
            {
                Console.WriteLine("Urzadzenie nie zostalo podlaczone!\nNacisnij [ENTER] aby zamknac program");
                Console.ReadLine();
                Environment.Exit(0);
            }
        }
 public MultiradioV1WithEncoder(FTD2XX_NET.FTDI.FT_DEVICE_INFO_NODE deviceInfo)
     : base(deviceInfo)
 {
     ChangeName("MultiRadio (Encoder)");
 }
Example #7
0
        public static bool CheckDevice(FTD2XX_NET.FTDI.FT_DEVICE_INFO_NODE deviceInfo, DeviceType deviceType, bool resetCommunication)
        {
            FTD2XX_NET.FTDI driver = null;
            try
            {
                // połączenie z urządzeniem
                driver = new FTD2XX_NET.FTDI();
                FTD2XX_NET.FTDI.FT_STATUS ret = driver.OpenByLocation(deviceInfo.LocId);
                if (ret == FTD2XX_NET.FTDI.FT_STATUS.FT_OK)
                {
                    ret = driver.ResetDevice();
                    //ret = driver.ResetPort();
                    ret = driver.SetBaudRate(56700);
                    ret = driver.SetDataCharacteristics(8, 2, 0);
                    ret = driver.SetFlowControl(FTD2XX_NET.FTDI.FT_FLOW_CONTROL.FT_FLOW_NONE, 0, 0);

                    uint available = 0;
                    uint red       = 0;
                    uint written   = 0;

                    // resetowanie urządzenia
                    if (resetCommunication)
                    {
                        // wysłanie resetu
                        ret = driver.GetRxBytesAvailable(ref available);
                        red = 0;
                        if (ret != FTD2XX_NET.FTDI.FT_STATUS.FT_OK)
                        {
                            driver.Close();
                            driver = null;
                            return(false);
                        }
                        if (available > 0)
                        {
                            byte[] tmp = new byte[available];
                            ret = driver.Read(tmp, (uint)tmp.Length, ref red);
                            if (ret != FTD2XX_NET.FTDI.FT_STATUS.FT_OK)
                            {
                                driver.Close();
                                driver = null;
                                return(false);
                            }
                        }

                        available = 0;
                        int tries = 16;
                        while (available < 3 && tries-- > 0)
                        {
                            ret = driver.Write(new byte[] { 254 }, 1, ref written);
                            if (ret != FTD2XX_NET.FTDI.FT_STATUS.FT_OK || written != 1)
                            {
                                driver.Close();
                                driver = null;
                                return(false);
                            }

                            Thread.Sleep(20);

                            ret = driver.GetRxBytesAvailable(ref available);
                            red = 0;
                            if (ret != FTD2XX_NET.FTDI.FT_STATUS.FT_OK)
                            {
                                driver.Close();
                                driver = null;
                                return(false);
                            }
                        }

                        if (available < 3)
                        {
                            driver.Close();
                            driver = null;
                            return(false);
                        }

                        if ((available % 3) != 0)
                        {
                            Thread.Sleep(20);
                            ret = driver.GetRxBytesAvailable(ref available);
                            red = 0;
                            if (ret != FTD2XX_NET.FTDI.FT_STATUS.FT_OK)
                            {
                                driver.Close();
                                driver = null;
                                return(false);
                            }
                        }

                        byte[] tmp3 = new byte[available];
                        ret = driver.Read(tmp3, (uint)tmp3.Length, ref red);
                        if (ret != FTD2XX_NET.FTDI.FT_STATUS.FT_OK)
                        {
                            driver.Close();
                            driver = null;
                            return(false);
                        }
                    }

                    // wysłanie rozkazu ciszy
                    byte[] data = new byte[3] {
                        255, 1, 204
                    };
                    written = 0;
                    ret     = driver.Write(data, data.Length, ref written);
                    if (ret != FTD2XX_NET.FTDI.FT_STATUS.FT_OK)
                    {
                        return(false);
                    }

                    // odczytanie wszystkich danych
                    available = 0;
                    ret       = driver.GetRxBytesAvailable(ref available);
                    red       = 0;
                    if (ret != FTD2XX_NET.FTDI.FT_STATUS.FT_OK)
                    {
                        return(false);
                    }
                    if (available > 0)
                    {
                        byte[] tmp = new byte[available];
                        ret = driver.Read(tmp, (uint)tmp.Length, ref red);
                        if (ret != FTD2XX_NET.FTDI.FT_STATUS.FT_OK)
                        {
                            return(false);
                        }
                    }

                    // wysłanie zapytania o typ urządzenia
                    data = new byte[3] {
                        255, 1, 202
                    };
                    written = 0;
                    ret     = driver.Write(data, data.Length, ref written);

                    if (ret == FTD2XX_NET.FTDI.FT_STATUS.FT_OK)
                    {
                        int count = 0;
                        while (count++ < 5)
                        {
                            Thread.Sleep(50);
                            ret = driver.GetRxBytesAvailable(ref available);
                            if (ret == FTD2XX_NET.FTDI.FT_STATUS.FT_OK && available > 2)
                            {
                                // odczytanie danych
                                data[0] = data[1] = data[2] = 0;
                                ret     = driver.Read(data, (uint)data.Length, ref red);
                                if (ret == FTD2XX_NET.FTDI.FT_STATUS.FT_OK && red == data.Length)
                                {
                                    // sprawdzenie czy jest to raport o typie urządzenia i czy typ zgadza się z przekazanym typem
                                    if (data[0] == 2)
                                    {
                                        byte tmp = (byte)(data[1] & 0x0f);
                                        return(tmp == (byte)deviceType);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch { }
            finally
            {
                if (driver != null && driver.IsOpen)
                {
                    try
                    {
                        driver.Close();
                    }
                    catch { }
                }
            }
            return(false);
        }
Example #8
0
 public static bool CheckDevice(FTD2XX_NET.FTDI.FT_DEVICE_INFO_NODE deviceInfo, DeviceType deviceType)
 {
     return(CheckDevice(deviceInfo, deviceType, false));
 }