Ejemplo n.º 1
0
 public MainPage()
 {
     this.InitializeComponent();
     ftManager = new FTManager();
     App.Current.Suspending += OnSuspending;
     App.Current.Resuming   += OnResuming;
 }
        private async void Page_Loaded(object sender, RoutedEventArgs e)
        {
            ftManager = new FTManager();
            timer = ThreadPoolTimer.CreatePeriodicTimer(Timer_Tick, TimeSpan.FromMilliseconds(500));

            await seClient.Connect();
        }
Ejemplo n.º 3
0
 /// <summary>
 /// browser 页面添加下载任务的响应事件
 /// </summary>
 /// <param name="downloadTask">文件/文件夹任务</param>
 public void AddTask(FileTask task)
 {
     FTManager.AddTask(task);
     if (!IsTransfering)
     {
         FTManager.InitDownload();
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// This test open and closes the handle to the FTDI device 100 times.
        /// </summary>
#if DAVE
        public async Task <Boolean> OpenCloseTest(FTManager ftManager, String deviceID)
        {
            try
            {
                int errorCode = (int)ERROR_CODES.SUCCESS;

                double start = DateTime.Now.TimeOfDay.TotalSeconds;
                String s     = "\r\n\r\nStarted OpenCloseTest\r\n";
                AppendLogFile(s);
                AppendConsole(s);

                var res = await Task <Boolean> .Factory.StartNew(async (source) =>
                {
                    for (int i = 0; i < 100; i++)
                    {
                        var devList = ftManager.GetDeviceList();
                        if (devList.Count == 0)
                        {
                            errorCode = (int)ERROR_CODES.NO_DEVICES_FOUND;
                            return(false);
                        }

                        IFTDevice dev = ftManager.OpenByDeviceID(deviceID);
                        if (dev == null)
                        {
                            errorCode = (int)ERROR_CODES.FAILED_TO_OPEN;
                            return(false);
                        }

                        await SetUARTSettings(dev);

                        dev.Close();
                    }

                    return(true);
                }, WorkItemPriority.Normal);

                double finish = DateTime.Now.TimeOfDay.TotalSeconds;
                s = String.Format(
                    @"Finished OpenCloseTest:
                                Result: {0}
                                ErrorCode: {1}
                                Duration: {2}secs",
                    res,
                    errorCode,
                    Math.Round(finish - start, 2));
                AppendLogFile(s);
                AppendConsole(s);

                return(res);
            }
            catch
            {
                return(false);
            }
        }
Ejemplo n.º 5
0
 private void ButtonResume_Click(object sender, RoutedEventArgs e)
 {
     FTManager.Load();
     this.ListViewTask.ItemsSource = FTManager.FileTasks;
     // ************* todo *******************
     // 确定目前是否有 severIP 2020.02.12 ***********
     if (!IsTransfering)
     {
         FTManager.InitDownload();
     }
 }
Ejemplo n.º 6
0
 public void AddTasks(List <FileTask> fileTasks)
 {
     foreach (FileTask task in fileTasks)
     {
         FTManager.AddTask(task);
     }
     if (!IsTransfering)
     {
         FTManager.InitDownload();
     }
 }
Ejemplo n.º 7
0
        public FtdiSampleViewModel()
        {
            ftManager           = new FTManager();
            SelectDeviceCommand = new DelegateCommand <DeviceNode>(OnSelectDevice);

            // for some reason the ftManager returns 0 devices at startup, so poll for new devices
            deviceStatusWatcher          = new DispatcherTimer();
            deviceStatusWatcher.Tick    += OnTick;
            deviceStatusWatcher.Interval = TimeSpan.FromMilliseconds(1000);
            deviceStatusWatcher.Start();
        }
Ejemplo n.º 8
0
        public FtdiSampleViewModel()
        {
            ftManager = new FTManager();
            SelectDeviceCommand = new DelegateCommand<DeviceNode>(OnSelectDevice);

            // for some reason the ftManager returns 0 devices at startup, so poll for new devices
            deviceStatusWatcher = new DispatcherTimer();
            deviceStatusWatcher.Tick += OnTick;
            deviceStatusWatcher.Interval = TimeSpan.FromMilliseconds(1000);
            deviceStatusWatcher.Start();
        }
Ejemplo n.º 9
0
        private FTManager InitializeDriver()
        {
#if CUSTOM_VID_PID
            bool result = FTManager.AddVIDPID(0x1234, 0x4321);
            result = FTManager.RemoveVIDPID(0x0403, 0x6001);
            result = FTManager.RemoveVIDPID(0x0403, 0x6010);
            result = FTManager.RemoveVIDPID(0x0403, 0x6011);
            result = FTManager.RemoveVIDPID(0x0403, 0x6014);
            result = FTManager.RemoveVIDPID(0x0403, 0x6015);
#endif
            return(new FTManager());
        }
Ejemplo n.º 10
0
 private static void InitFTDI()
 {
     try
     {
         ftManager = new FTManager();
         string ver = FTManager.GetLibraryVersion();
         Debug.WriteLine(ver);
     }
     catch (Exception ex)
     {
         Debug.WriteLine(ex.Message);
     }
 }
Ejemplo n.º 11
0
        private async void ReadEEPROM()
        {
            // if (myDevice != null)
            {
                string s = FTManager.GetLibraryVersion();
                AppendConsole(s);

                /*IFT_EEPROM ee = await myDevice.EepromRead();
                 *
                 * if (myDevice.DeviceInfoNode.DeviceType == DEVICE_TYPE.FT232R)
                 * {
                 *  // Cast to the type that corresponds to the device type.
                 *  FT232R_EEPROM eeData = ee as FT232R_EEPROM;
                 *
                 *  if (eeData == null)
                 *      return;
                 *
                 *  Debug.WriteLine(@"Manufacturer: {0}\r\nSerial Number: {1}\r\nProduct Description: {2}\r\n\r\n ",
                 *      eeData.Manufacturer, eeData.SerialNumber, eeData.Product);
                 * }*/
            }
        }
Ejemplo n.º 12
0
 public void ButtonPause_Click(object sender, RoutedEventArgs e)
 {
     FTManager.Pause();
 }
Ejemplo n.º 13
0
        /// <summary>
        /// Tests the Purging of a device
        /// </summary>
        /// <param name="ftManager">The ftManager instance.</param>
        /// <param name="deviceID">The device identifier.</param>
        /// <returns>Task{Boolean}.</returns>
        public async Task <Boolean> PurgeTest(FTManager ftManager, String deviceID)
        {
            try
            {
                int errorCode = (int)ERROR_CODES.SUCCESS;

                double start = DateTime.Now.TimeOfDay.TotalSeconds;
                String s     = "\r\n\r\nStarted PurgeLoopbackTest\r\n";
                AppendLogFile(s);
                AppendConsole(s);

                Boolean res = await Task.Run <Boolean>(async() =>
                {
                    for (int i = 0; i < 100; i++)
                    {
                        byte[] dataTx = new byte[10];
                        byte[] dataRx = new byte[10];

                        // Create device list...
                        var devList = ftManager.GetDeviceList();
                        if (devList.Count == 0)
                        {
                            errorCode = (int)ERROR_CODES.NO_DEVICES_FOUND;
                        }

                        // Find device in the list again...
                        IFTDevice dev = ftManager.OpenByDeviceID(deviceID);
                        if (dev == null)
                        {
                            errorCode = (int)ERROR_CODES.FAILED_TO_OPEN;
                        }

                        await SetUARTSettings(dev);

                        // Generate some random data...
                        Random rnd = new Random();
                        for (int j = 0; j < dataTx.Length; j++)
                        {
                            dataTx[j] = (byte)rnd.Next(0, 0xff);
                        }
                        // Write then read back the data...
                        await dev.WriteAsync(dataTx, (uint)dataTx.Length);
                        dev.Purge(true, false);

                        for (int j = 0; j < dataTx.Length; j++)
                        {
                            dataTx[j] = (byte)rnd.Next(0, 0xff);
                        }
                        // Write then read back the data...
                        await dev.WriteAsync(dataTx, (uint)dataTx.Length);

                        uint count = await dev.ReadAsync(dataRx, (uint)dataTx.Length);
                        if (count < dataTx.Length)
                        {
                            errorCode = (int)ERROR_CODES.FAILED_TO_READ_ALL_DATA;
                            dev.Close();
                            return(false);
                        }

                        for (int j = 0; j < dataTx.Length; j++)
                        {
                            if (dataTx[j] != dataRx[j])
                            {
                                errorCode = (int)ERROR_CODES.DATA_INTEGRITY;
                                return(false);
                            }
                        }

                        dev.Close();
                    }

                    return(true);
                }).AsAsyncOperation();

                double finish = DateTime.Now.TimeOfDay.TotalSeconds;
                s = String.Format(
                    @"Finished PurgeLoopbackTest:
                                Result: {0}
                                ErrorCode: {1}
                                Duration: {2}secs",
                    res.ToString().ToLower(),
                    errorCode,
                    Math.Round(finish - start, 2));
                AppendLogFile(s);
                AppendConsole(s);

                return(res);
            }
            catch
            {
                return(false);
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Tests the QueueStatus property of an IFTDevice.
        /// </summary>
        /// <param name="ftManager">The ftManager instance.</param>
        /// <param name="deviceID">The device identifier.</param>
        /// <returns>Task{Boolean}.</returns>
        public async Task <Boolean> QueueStatusTest(FTManager ftManager, String deviceID)
        {
            try
            {
                String s           = "";
                double start       = 0;
                int    errorCode   = (int)ERROR_CODES.SUCCESS;
                uint   TOTAL_BYTES = 32769;
                uint   PACKET_SIZE = 1024;
                uint   iterations  = TOTAL_BYTES / PACKET_SIZE;

                Boolean res = await Task.Run <Boolean>(async() =>
                {
                    byte[] dataTx = new byte[TOTAL_BYTES];
                    byte[] dataRx = new byte[TOTAL_BYTES];

                    // Generate some random data...
                    Random rnd = new Random();
                    for (int j = 0; j < dataTx.Length; j++)
                    {
                        dataTx[j] = (byte)rnd.Next(0, 0xff);
                    }

                    // Create device list...
                    var devList = ftManager.GetDeviceList();
                    if (devList.Count == 0)
                    {
                        errorCode = (int)ERROR_CODES.NO_DEVICES_FOUND;
                    }

                    // Find device in the list again...
                    IFTDevice dev = ftManager.OpenByDeviceID(deviceID);
                    if (dev == null)
                    {
                        errorCode = (int)ERROR_CODES.FAILED_TO_OPEN;
                    }

                    await SetUARTSettings(dev);

                    start = DateTime.Now.TimeOfDay.TotalSeconds;
                    s     = "\r\n\r\nStarted QueueStatusTest\r\n";
                    AppendLogFile(s);
                    AppendConsole(s);

                    await dev.WriteAsync(dataTx, 128);
                    dev.Purge(true, false);

                    for (int j = 0; j < TOTAL_BYTES; j++)
                    {
                        dataTx[j] = (byte)j;
                    }

                    await dev.ResetAsync();

                    await dev.WriteAsync(dataTx, 10);

                    while (dev.GetQueueStatus() != 10)
                    {
                        //return false;
                    }

                    if (await dev.ReadAsync(dataRx, 10) != 10)
                    {
                        return(false);
                    }

                    for (int j = 0; j < 10; j++)
                    {
                        if (dataTx[j] != dataRx[j])
                        {
                            errorCode = (int)ERROR_CODES.DATA_INTEGRITY;
                            return(false);
                        }
                    }

                    dev.Close();

                    return(true);
                }).AsAsyncOperation();

                double finish = DateTime.Now.TimeOfDay.TotalSeconds;
                s = String.Format(
                    @"Finished QueueStatusTest:
                                Result: {0}
                                ErrorCode: {1}
                                Duration: {2}secs",
                    res.ToString().ToLower(),
                    errorCode,
                    Math.Round(finish - start, 2));
                AppendLogFile(s);
                AppendConsole(s);

                return(res);
            }
            catch
            {
                return(false);
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Loopback test that transmits 1MB of data to the device and reads it back.
        /// </summary>
        public async Task <Boolean> LoopbackTest(FTManager ftManager, String deviceID)
        {
            try
            {
                String s           = "";
                double start       = 0;
                int    errorCode   = (int)ERROR_CODES.SUCCESS;
                int    TOTAL_BYTES = 65535;
                int    PACKET_SIZE = 1024;
                int    iterations  = TOTAL_BYTES / PACKET_SIZE;

                Boolean res = await Task.Run <Boolean>(async() =>
                {
                    byte[] dataTx = new byte[TOTAL_BYTES];
                    byte[] dataRx = new byte[PACKET_SIZE];

                    // Generate some random data...
                    Random rnd = new Random();
                    for (int j = 0; j < dataTx.Length; j++)
                    {
                        dataTx[j] = (byte)rnd.Next(0, 0xff);
                    }

                    // Create device list...
                    var devList = ftManager.GetDeviceList();
                    if (devList.Count == 0)
                    {
                        errorCode = (int)ERROR_CODES.NO_DEVICES_FOUND;
                    }

                    // Find device in the list again...
                    IFTDevice dev = ftManager.OpenByDeviceID(deviceID);
                    if (dev == null)
                    {
                        errorCode = (int)ERROR_CODES.FAILED_TO_OPEN;
                    }

                    await SetUARTSettings(dev);

                    start = DateTime.Now.TimeOfDay.TotalSeconds;
                    s     = "\r\n\r\nStarted LoopbackTest\r\n";
                    AppendLogFile(s);
                    AppendConsole(s);

                    for (int i = 0; i < iterations; i++)
                    {
                        byte[] buf = new byte[PACKET_SIZE];

                        Buffer.BlockCopy(dataTx, i *PACKET_SIZE, buf, 0, PACKET_SIZE);

                        // Write then read back the data...
                        double t1 = DateTime.Now.TimeOfDay.TotalSeconds;
                        await dev.WriteAsync(buf, (uint)PACKET_SIZE);
                        double t2 = DateTime.Now.TimeOfDay.TotalSeconds;

                        double t3  = DateTime.Now.TimeOfDay.TotalSeconds;
                        uint count = await dev.ReadAsync(dataRx, (uint)PACKET_SIZE);
                        double t4  = DateTime.Now.TimeOfDay.TotalSeconds;

                        if (count < PACKET_SIZE)
                        {
                            errorCode = (int)ERROR_CODES.FAILED_TO_READ_ALL_DATA;
                            return(false);
                        }

                        double span = t4 - t3;
                        //AppendConsole(span.ToString());

                        double t5 = DateTime.Now.TimeOfDay.TotalSeconds;
                        for (int j = 0; j < PACKET_SIZE; j++)
                        {
                            if (buf[j] != dataRx[j])
                            {
                                errorCode = (int)ERROR_CODES.DATA_INTEGRITY;
                                return(false);
                            }
                        }
                        double t6 = DateTime.Now.TimeOfDay.TotalSeconds;
                    }
                    dev.Close();

                    return(true);
                }).AsAsyncOperation();

                double finish = DateTime.Now.TimeOfDay.TotalSeconds;
                s = String.Format(
                    @"Finished LoopbackTest:
                                Result: {0}
                                ErrorCode: {1}
                                Duration: {2}secs",
                    res.ToString().ToLower(),
                    errorCode,
                    Math.Round(finish - start, 2));
                AppendLogFile(s);
                AppendConsole(s);

                return(res);
            }
            catch
            {
                return(false);
            }
        }
Ejemplo n.º 16
0
 public FtdiSerialDeviceManager()
 {
     ftManager = new FTManager();
 }
Ejemplo n.º 17
0
 public FtdiSerialDeviceManager()
 {
     ftManager = new FTManager();
 }