Ejemplo n.º 1
0
        public bool intDevice()
        {
            // 可能抛出“无法访问已释放的对象”的异常
            try { loopDevice = usbDevices[0x04b4, 0x3031] as CyUSBDevice; }
            catch { loopDevice = null; }
            //PID 0x1004 is used for cardio
            //if (loopDevice == null) loopDevice = usbDevices[0x04b4, 0x1004] as CyUSBDevice;

            if (loopDevice != null)
            {
                try
                {
                    usbName             = loopDevice.FriendlyName;
                    outEndpoint         = loopDevice.EndPointOf(0x02) as CyBulkEndPoint;
                    inEndpoint          = loopDevice.EndPointOf(0x86) as CyBulkEndPoint;
                    outEndpoint.TimeOut = 500;
                    inEndpoint.TimeOut  = 1000;
                    _isUSBAvailable     = true;
                    InitializeParams();
                    PreReadAsysnchonous();
                }
                catch (Exception ex)
                {
                    return(false);
                }
                return(true);
            }
            else
            {
                _isUSBAvailable = false;
                return(false);
            }
        }
Ejemplo n.º 2
0
 void usbDevices_DeviceRemoved(object sender, EventArgs e)
 {
     MyDevice   = null;
     inEndpoint = null;
     SetDevice();
     openPort();
 }
Ejemplo n.º 3
0
 public bool ReConnect()
 {
     MyUsb = MyUsbList[0x04B4, 0x1004] as CyUSBDevice;
     if (MyUsb != null)
     {
         MyUsb.ReConnect();
         MyUsb = MyUsbList[0x04B4, 0x00F1] as CyUSBDevice;
     }
     else
     {
         MyUsb = MyUsbList[0x04B4, 0x00F1] as CyUSBDevice;
     }
     if (MyUsb != null)
     {
         MyOutPoint     = MyUsb.EndPointOf(0x02);
         MyInPoint      = MyUsb.EndPointOf(0x86);
         MyControlPoint = MyUsb.ControlEndPt;
         Reset();
         return(true);
     }
     else
     {
         return(false);
     }
 }
Ejemplo n.º 4
0
        /*Summary
         * This is the event handler for device removal. This method resets the device count and searches for the device with
         * VID-PID 04b4-1003
         */
        void usbDevices_DeviceRemoved(object sender, EventArgs e)
        {
            bRunning = false;

            if (tListen != null && tListen.IsAlive == true)
            {
                tListen.Abort();
                tListen.Join();
                tListen = null;
            }

            MyDevice = null;
            EndPoint = null;
            SetDevice(false);

            if (StartBtn.Text.Equals("Start") == false)
            {
                {
                    DevicesComboBox.Enabled   = true;
                    EndPointsComboBox.Enabled = true;
                    PpxBox.Enabled            = true;
                    QueueBox.Enabled          = true;
                    StartBtn.Text             = "Start";
                    bRunning = false;

                    t2       = DateTime.Now;
                    elapsed  = t2 - t1;
                    xferRate = (long)(XferBytes / elapsed.TotalMilliseconds);
                    xferRate = xferRate / (int)100 * (int)100;

                    StartBtn.BackColor = Color.Aquamarine;
                }
            }
        }
Ejemplo n.º 5
0
        public override bool Recover()
        {
            try
            {
                if (loopDevice != null)
                {
                    loopDevice.Dispose();
                    loopDevice = null;
                }

                if (usbDevices != null)
                {
                    usbDevices.DeviceRemoved  -= usbDevices_DeviceRemoved;
                    usbDevices.DeviceAttached -= usbDevices_DeviceAttached;
                    usbDevices.Dispose();
                    usbDevices = null;
                }
            }
            catch (System.Exception ex)
            {
            }


            inEndpoint  = null;
            outEndpoint = null;

            usbDevices = new USBDeviceList(CyConst.DEVICES_CYUSB);
            usbDevices.DeviceRemoved  += new EventHandler(usbDevices_DeviceRemoved);
            usbDevices.DeviceAttached += new EventHandler(usbDevices_DeviceAttached);
            return(intDevice());
        }
Ejemplo n.º 6
0
        private void SetDevice()
        {
            USBDevice dev = usbDevices[46084, 4099];

            if (dev != null)
            {
                cyDevice        = (CyUSBDevice)dev;
                controlEndPoint = null;
                bulkInEndPoint  = null;

                GetEndpointsOfNode(cyDevice.Tree);
                if (controlEndPoint != null)
                {
                    isReady = true;

                    name     = dev.FriendlyName;
                    version  = GetFirmwareVer();
                    revision = GetRevision();

                    DeviceReadyEventArgs args = new DeviceReadyEventArgs();
                    args.DeviceName = name;
                    args.VidPid     = new[] { dev.VendorID, dev.ProductID };
                    args.Version    = version;
                    args.Revision   = revision;

                    DeviceReady?.Invoke(this, args);
                }
            }
            else
            {
                isReady = false;
                DeviceNotReady?.Invoke(this, null);
            }
        }
Ejemplo n.º 7
0
        public static bool SendVendorRequest(CyUSBDevice usbDevice, MonoUsbDeviceHandle monoDeviceHandle, byte reqCode, byte[] data, ushort value = 0, ushort index = 0)
        {
            if (data == null)
            {
                data = new byte[0];
            }

            if (usbDevice != null)
            {
                CyControlEndPoint ctrlEpt = usbDevice.ControlEndPt;
                ctrlEpt.TimeOut   = TIMEOUT;
                ctrlEpt.Direction = CyConst.DIR_TO_DEVICE;
                ctrlEpt.ReqType   = CyConst.REQ_VENDOR;
                ctrlEpt.Target    = CyConst.TGT_DEVICE;
                ctrlEpt.ReqCode   = reqCode;
                ctrlEpt.Value     = value;
                ctrlEpt.Index     = index;

                int bytes = data.Length;
                ctrlEpt.XferData(ref data, ref bytes);
                return(bytes == data.Length);
            }
            else
            {
                short bytes       = (short)data.Length;
                byte  requestType = CyConst.DIR_TO_DEVICE + CyConst.REQ_VENDOR + CyConst.TGT_DEVICE;
                int   ret         = MonoUsbApi.ControlTransfer(monoDeviceHandle, requestType, reqCode, (short)value, (short)index, data, bytes, TIMEOUT);
                return(ret == data.Length);
            }
        }
Ejemplo n.º 8
0
 private void ConfigFX3Device(string FileName, CyUSBDevice myDevice)
 {
     if (MyDevice != null)
     {
         FX3_FWDWNLOAD_ERROR_CODE enmResult = FX3_FWDWNLOAD_ERROR_CODE.SUCCESS;
         CyFX3Device fx3 = myDevice as CyFX3Device;
         if (fx3 != null)
         {
             enmResult = fx3.DownloadFw(FileName, FX3_FWDWNLOAD_MEDIA_TYPE.RAM);
         }
         else
         {
             MessageBox.Show("Please check whether the device is FX3 device", "Device ERROR", MessageBoxButton.OK, MessageBoxImage.Error);
             return;
         }
         if (enmResult != FX3_FWDWNLOAD_ERROR_CODE.SUCCESS)
         {
             MessageBox.Show("Config error", "Device ERROR", MessageBoxButton.OK, MessageBoxImage.Error);
         }
         string report = string.Format("Program {0}\n", fx3.GetFwErrorString(enmResult));
         tbxInfo.AppendText(report);
     }
     else
     {
         MessageBox.Show("Please select the USB device", "Device ERROR", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
Ejemplo n.º 9
0
        void usbDevices_DeviceRemoved(object sender, EventArgs e)
        {
            bRunning = false;

            if (!ThreadData.IsAddingCompleted)
            {
                ThreadData.CompleteAdding();
            }

            MyDevice        = null;
            BulkInEndPoint  = null;
            BulkOutEndPoint = null;
            RefreshDeviceLists(false);
            RefreshEndPoint();
            tbxInfo.AppendText("USB Disconnect\n");
            lblUsbName.Content       = "C# USB - no device";
            lblUsbName.Foreground    = Brushes.Red;
            btnStartAcq.IsEnabled    = false;
            btnCmdSend.IsEnabled     = false;
            btnStartAcq.Content      = "Start";
            btnSetUsb.Content        = "Set";
            btnStartAcq.Background   = new SolidColorBrush(Color.FromRgb(27, 129, 62));
            cbxDeviceLists.IsEnabled = true;
            btnSetUsb.IsEnabled      = true;
            cbxInEndPoint.IsEnabled  = true;
            cbxOutEndPoint.IsEnabled = true;
            cbxPpx.IsEnabled         = true;
            cbxXferQueue.IsEnabled   = true;
        }
Ejemplo n.º 10
0
        private void InitEndInPoints(CyUSBDevice usbDevice)
        {
            int endPointCount = (int)usbDevice.EndPointCount;
            int index1        = 0;
            int index2        = 0;

            for (int index3 = 1; index3 < endPointCount; ++index3)
            {
                if (((int)usbDevice.EndPoints[index3].Address & 128) == 128)
                {
                    index1 = index3;
                }
                else
                {
                    index2 = index3;
                }
            }
            if (endPointCount == 3)
            {
                this.InEndpt  = usbDevice.USBCfgs[0].Interfaces[0].EndPoints[index1];
                this.OutEndpt = usbDevice.USBCfgs[0].Interfaces[0].EndPoints[index2];
            }
            else
            {
                this.InEndpt  = (CyUSBEndPoint)null;
                this.OutEndpt = (CyUSBEndPoint)null;
            }
        }
        static void ResetFX2FifoStatus(CyUSBDevice TE_USB_FX2_USBDevice)
        {
            if (TE_USB_FX2_USBDevice == null)
            {
                Console.WriteLine("Error,no device is selected");
                return;
            }

            //cout << endl << "Resetting all FIFOs" << endl;
            Console.WriteLine("Resetting all FIFOs");
            byte[] Command     = new byte[64];
            byte[] Reply       = new byte[64];
            int    CmdLength   = 64;
            int    ReplyLength = 64;

            uint TIMEOUT_MS = 100000;

            Command[0] = (byte)FX2_Commands.RESET_FIFO_STATUS;
            Command[1] = 0; //reset all fifos

            if (TE_USB_FX2.TE_USB_FX2.TE_USB_FX2_SendCommand(ref TE_USB_FX2_USBDevice, ref Command, ref CmdLength, ref Reply, ref ReplyLength, TIMEOUT_MS) == false)
            {
                //cout << "Error" << endl;
                Console.WriteLine("Error Send Command Reset all fifos");
            }

            Command[0] = (byte)FX2_Commands.INITALIZE; //0xA0;//comand SWITCH_MODE
            Command[1] = 1;                            //FIFO mode : is not in the documentation

            if (TE_USB_FX2.TE_USB_FX2.TE_USB_FX2_SendCommand(ref TE_USB_FX2_USBDevice, ref Command, ref CmdLength, ref Reply, ref ReplyLength, TIMEOUT_MS) == false)
            {
                //cout << "Error" << endl;
                Console.WriteLine("Error Switch Mode Fifo Mode");
            }
        }
Ejemplo n.º 12
0
        private void Form1_Load(object sender, EventArgs e)
        {
            string tmp_folder = "C:\\tmp\\AINGF_V2\\";

            try
            {
                if (!Directory.Exists(tmp_folder))
                {
                    Directory.CreateDirectory(tmp_folder);
                }
                string[] filePaths = Directory.GetFiles(tmp_folder);
                foreach (string filePath in filePaths)
                {
                    File.Delete(filePath);
                }
            }
            catch
            {
                MessageBox.Show("Temp Folder flush error.");
            }

            //Thread th1 = new Thread(new ThreadStart(prepareEX));
            //th1.Start();
            usbDevices = new USBDeviceList(CyConst.DEVICES_CYUSB);
            MyDevice   = usbDevices[0x04B4, 0x1003] as CyUSBDevice;
        }
Ejemplo n.º 13
0
        public void prepareEX()
        {
            USBDeviceList usbDevices = new USBDeviceList(CyConst.DEVICES_CYUSB);
            CyUSBDevice   MyDevice   = usbDevices[0x04B4, 0x1003] as CyUSBDevice;

            if (MyDevice != null)
            {
                MyDevice.Reset();
                Thread.Sleep(1000);
                MyDevice.ReConnect();
                Thread.Sleep(1000);
                if (MyDevice.BulkInEndPt != null)
                {
                    MyDevice.BulkInEndPt.Reset();
                }
                if (MyDevice.BulkOutEndPt != null)
                {
                    MyDevice.BulkInEndPt.TimeOut = 500;

                    for (int i = 0; i < 640 * 480 * 2 / 512; i++)
                    {
                        int    len = 512;
                        byte[] buf = new byte[len];

                        if (false == MyDevice.BulkInEndPt.XferData(ref buf, ref len, true))
                        {
                            ready = true; break;
                        }
                    }
                }
            }
            return;
        }
Ejemplo n.º 14
0
        public Fx2Device(CyUSBDevice usbDevice, MonoUsbProfile usbProfile, EDeviceType deviceType = EDeviceType.Unknown)
        {
            if (usbDevice != null)
            {
                USBDevice = usbDevice;
            }
            if (usbProfile != null)
            {
                USBProfile = usbProfile;
            }
            DeviceType = deviceType;

            if (deviceType == EDeviceType.Unknown)
            {
                Console.WriteLine($"+ {this}");
            }

            if (deviceType == EDeviceType.DAC_SA || deviceType == EDeviceType.ADC_SA)
            {
                if (usbDevice != null)
                {
                    CyBulkEndPoint outEndpoint = usbDevice.EndPointOf(0x01) as CyBulkEndPoint;
                    CyBulkEndPoint inEndpoint  = usbDevice.EndPointOf(0x81) as CyBulkEndPoint;
                    avalonPacket = new AvalonPacket(outEndpoint, inEndpoint);
                }
                else
                {
                    avalonPacket = new MonoAvalonPacket(MonoDeviceHandle);
                }
            }
        }
Ejemplo n.º 15
0
        /*Summary
         * Search the device with VID-PID 04b4-00F1 and if found, select the end point
         */
        private void SetDevice()
        {
            USBDevice dev = usbDevices[0x04B4, 0x00F1];

            if (dev != null)
            {
                MyDevice = (CyUSBDevice)dev;

                GetEndpointsOfNode(MyDevice.Tree);
                PpxBox.Text = "8"; //Set default value to 8 Packets
                if (EndPointsComboBox.Items.Count > 0)
                {
                    EndPointsComboBox.SelectedIndex = 0;
                    StartBtn.Enabled = true;
                }
                Text = MyDevice.FriendlyName;
            }
            else
            {
                StartBtn.Enabled = false;
                EndPointsComboBox.Items.Clear();
                EndPointsComboBox.Text = "";
                Text = "C# Streamer - no device";
            }
        }
Ejemplo n.º 16
0
        public static bool Initialize()
        {
            bool retVal = true;

            m_USBDevices = new USBDeviceList(CyConst.DEVICES_CYUSB);
            m_USBDevices.DeviceAttached += new EventHandler(usbDevices_DeviceAttached);
            m_USBDevices.DeviceRemoved  += new EventHandler(usbDevices_DeviceRemoved);
            // Get the first device having VendorID == 0x04B4 and ProductID == 0x8613

            for (int i = 0; i < m_USBDevices.Count; i++)
            {
                m_CyUSBDevice = m_USBDevices[i] as CyFX3Device;
                if ((m_CyUSBDevice != null) && (m_CyUSBDevice.ProductID == 0x4720))
                {
                    //Fr.BootProgrammerDeviceFound();
                    break;
                }
            }
            //m_CyUSBDevice = m_USBDevices[0x04B4, 0x00F0] as CyUSBDevice;

            if (m_CyUSBDevice != null)
            {
                Status     = m_CyUSBDevice.FriendlyName + " connected.";
                m_EndPoint = m_CyUSBDevice.EndPoints[0];
            }
            else
            {
                m_EndPoint = null;
            }

            return(retVal);
        }
Ejemplo n.º 17
0
        public bool ReadFWCommand(ref byte[] inBuffer)
        {
            bool retValue = false;

            try
            {
                int buffCnt = 512;
                m_USBDevices = new USBDeviceList(CyConst.DEVICES_CYUSB);
                FxDev        = m_USBDevices[0] as CyUSBDevice;
                bulkEpt      = FxDev.BulkOutEndPt;
                retValue     = bulkEpt.XferData(ref inBuffer, ref buffCnt, false);

                Thread.Sleep(50);

                bulkEpt = FxDev.BulkInEndPt;
                if (bulkEpt != null)
                {
                    inBuffer = new byte[512];
                    retValue = bulkEpt.XferData(ref inBuffer, ref buffCnt, false);
                }
            }
            catch (Exception ex)
            {
                retValue = false;
            }
            return(retValue);
        }
Ejemplo n.º 18
0
 public bool findDevices()
 {
     this.usbDevices = new USBDeviceList((byte)1);
     this.usbDevices = this.listDevices();
     this.device     = this.usbDevices[this.vendorId, this.productId] as CyUSBDevice;
     return(true);
 }
Ejemplo n.º 19
0
        public static byte[] ReceiveVendorResponse(CyUSBDevice usbDevice, MonoUsbDeviceHandle monoDeviceHandle, byte reqCode, int length, ushort value = 0, ushort index = 0)
        {
            if (usbDevice != null)
            {
                CyControlEndPoint ctrlEpt = usbDevice.ControlEndPt;
                ctrlEpt.TimeOut   = TIMEOUT;
                ctrlEpt.Direction = CyConst.DIR_FROM_DEVICE;
                ctrlEpt.ReqType   = CyConst.REQ_VENDOR;
                ctrlEpt.Target    = CyConst.TGT_DEVICE;
                ctrlEpt.ReqCode   = reqCode;
                ctrlEpt.Value     = value;
                ctrlEpt.Index     = index;

                int    bytes  = length;
                byte[] buffer = new byte[bytes];
                ctrlEpt.XferData(ref buffer, ref bytes);
                if (bytes == buffer.Length)
                {
                    return(buffer);
                }
            }
            else
            {
                short  bytes       = (short)length;
                byte[] data        = new byte[bytes];
                byte   requestType = CyConst.DIR_FROM_DEVICE + CyConst.REQ_VENDOR + CyConst.TGT_DEVICE;
                int    ret         = MonoUsbApi.ControlTransfer(monoDeviceHandle, requestType, reqCode, (short)value, (short)index, data, bytes, TIMEOUT);
                if (ret == data.Length)
                {
                    return(data);
                }
            }

            return(null);
        }
Ejemplo n.º 20
0
        public Form1()
        {
            InitializeComponent();

            USBDeviceList usbDevices = new USBDeviceList(CyConst.DEVICES_CYUSB);

            MyDevice = usbDevices[0] as CyUSBDevice;

            if (MyDevice != null)
            {
                CtrlEndPt = MyDevice.ControlEndPt;
            }
            else
            {
                labelCardStatus.Text = "No acquisition card was found";
                buttonStart.Enabled  = false;
            }

            resolutionCombo.SelectedIndex = 2;

            listView1.View      = View.Details;
            listView1.GridLines = true;

            listView1.Columns.Add("SN");
            listView1.Columns.Add("CH_A");
            listView1.Columns.Add("CH_B");
        }
Ejemplo n.º 21
0
        /*
         * // This one must be corrected, cause trouble
         * public static bool TE_USB_FX2_DisplayDriverInformation(ref CyUSBDevice TE_USB_FX2_USBDevice, ref USBDeviceList USBdevList, int CardNumber)
         * {
         *
         * int CardCounted = 0;   // Trenz Board
         * int DeviceNumber = 0;  // Cypress Board ( number >= TrenzBoard)
         *
         * int CypressDeviceNumber = 0;
         * int TrenzDeviceNumber = 0;
         *
         * UInt16 PID = 0x0000;
         * UInt16 VID = 0x0000;
         *
         * uint DriverVersion1 = 0;
         *
         * string DriverName1 = null;
         *
         * //Creation of a list of USB device that use the CYUSB.SYS driver
         * USBdevList = new USBDeviceList(CyConst.DEVICES_CYUSB);
         * //If exist at least an USB device that use the CYUSB.SYS driver,
         * //I search and count the number of these devices that are of Trenz Electronic
         * if (USBdevList.Count != 0)
         * {
         *  foreach (USBDevice USBdev in USBdevList)
         *  {
         *    PID = USBdev.ProductID;
         *    VID = USBdev.VendorID;
         *    //Number of Cypress Card augmented by one
         *    CypressDeviceNumber++;
         *    if ((((PID == 0x0300) && (VID == 0x0bd0)) == true))  //0x0bd0 . 0x0bd0
         *    {
         *      //Number of Trenz Card (a subcategory of Cypress Card) augmented by one
         *      //CardCount++;
         *      TrenzDeviceNumber++;
         *      Console.WriteLine("PID e VID: {0}, {1}", PID, VID);
         *      // CardNumber=TrenzDeviceNumber-1 by definition.
         *      if ((TrenzDeviceNumber - 1) == CardNumber)
         *      {
         *        //I store the DeviceNumber that identify the Trenz Card (CardNumber) requested
         *        DeviceNumber = CypressDeviceNumber - 1;
         *        Console.WriteLine("DeviceNumber: {0}", DeviceNumber);
         *      }
         *    }
         *  }
         * }
         *
         * //At this point I memorize the Cards Counted and zeroed the variable that I have used in the counting.
         * CardCounted = TrenzDeviceNumber;
         * //Console.WriteLine("CardCounted: {0}", CardCount);
         * TrenzDeviceNumber = 0;
         * //Now I search the Trenz USB Device with the Card Number (CardNo) specified
         * if (((CardNumber >= 0) && (CardNumber < CardCounted)) == true)  //CardCounted
         * {
         *  USBDevice USBdev = USBdevList[DeviceNumber];
         *  PID = USBdev.ProductID;
         *  VID = USBdev.VendorID;
         *  if ((((PID == 0x0300) && (VID == 0x0bd0)) == true))
         *  {
         *    TE_USB_FX2_USBDevice = USBdev as CyUSBDevice;
         *    Console.WriteLine("USBdev {0} ", TE_USB_FX2_USBDevice);
         *
         *    //I cast the abstract USBdev in a concrete CyUSBDevice
         *    TE_USB_FX2_USBDevice = USBdev as CyUSBDevice;
         *    DriverVersion1 = TE_USB_FX2_USBDevice.DriverVersion;
         *    Console.WriteLine("DriverVersion {0} ", DriverVersion1);
         *    DriverName1 = TE_USB_FX2_USBDevice.DriverName;
         *    Console.WriteLine("Original Name of the Driver {0} ", DriverName1);
         *
         *    return true;
         *  }
         *  else
         *  {
         *    TE_USB_FX2_USBDevice = null;
         *    return false;
         *  }
         * }
         * else
         * {
         *  TE_USB_FX2_USBDevice = null;
         *  return false;
         * }
         * }
         */


        /*
         *
         * 3.4   TE_USB_FX2_SendCommand()
         *
         * 3.4.1   Declaration
         * public static bool TE_USB_FX2_SendCommand(ref CyUSBDevice TE_USB_FX2_USBDevice, ref byte[] Command, ref int CmdLength,
         * ref byte[] Reply, ref int ReplyLength, uint Timeout)
         *
         * 3.4.2   Function Call
         * Your application program shall call this function like this:
         * TE_USB_FX2.TE_USB_FX2.TE_USB_FX2_SendCommand (ref TE_USB_FX2_USBDevice, ref Command, ref CmdLength, ref Reply,
         * ref ReplyLength, Timeout);
         *
         * 3.4.3   Description
         * This function takes an already initialized USB device (previously selected by TE_USB_FX2_Open()) and sends a command
         *(API command) to the USB FX2 microcontroller (USB FX2 API command) or to the MicroBlaze embedded processor
         *(MicroBlaze API command) through the USB FX2 microcontroller endpoint EP1 buffer.
         * This function is normally used to send 64 bytes packets to the USB endpoint EP1 (0x01).
         * This function is also able to obtain the response of the USB FX2 microcontroller or MicroBlaze embedded processor through
         * the USB FX2 microcontroller endpoint EP1 (0x81).
         * 3.4.4   Parameters
         * 1. ref CyUSBDevice TE_USB-FX2_USBDevice
         * CyUSBDevice is a type defined in CyUSB.dll. This parameter points to the module selected by TE_USB_FX2_Open().
         * This parameter is passed by reference (ref). See pages 70-93 of CyUSB.NET.pdf (Cypress CyUSB .NET DLL Programmer's Reference)
         * 2. ref byte[] Command
         * This parameter is passed by reference (ref). It is the byte array that contains the commands to send to USB FX2 microcontroller
         *(FX2_Commands) or to the MicroBlaze embedded processor (MB_Commands).
         * The byte array shall be properly initialized using instructions similar to the following ones:
         * Command[0] = (byte)FX2_Commands.I2C_WRITE;
         * Command[1] = (byte)FX2_Commands.MB_I2C_ADDRESS;
         * Command[2] = (byte)FX2_Commands.I2C_BYTES;
         * Command[3] = (byte)0;
         * Command[4] = (byte)0;
         * Command[5] = (byte)0;
         * Command[6] = (byte)Command2MB;
         * 3. ref int CmdLength
         * This parameter (passed by reference (ref)) is the length (in bytes) of the previous byte array; it is the length of the
         * packet to transmit to USB FX2 controller endpoint EP1 (0x01). It is typically initialized to 64 bytes.
         * 4. ref byte[] Reply
         * This parameter (passed by reference (ref)) is the byte array that contains the response to the command sent to the
         * USB FX2 microcontroller (FX2_Commands) or to the MicroBlaze embedded processor (MB_Commands).
         * 5. ref int ReplyLength
         * This parameter (passed by reference (ref)) is the length (in bytes) of the previous byte array; it is the length of
         * the packet to transmit to the USB FX2 microcontroller endpoint EP1 (0x81). It is typically initialized to 64 byes,
         * but normally the meaningful bytes are less. The parameter is a reference, meaning that the method can modify its value.
         * The number of bytes actually received is passed back in ReplyLength.
         * 6. uint Timeout
         * The unsigned integer value is the time in milliseconds assigned to the synchronous method XferData() of data transfer used
         * by CyUSB.dll.
         * Timeout is the time that is allowed to the function for sending/receiving the data packet passed to the function;
         * this timeout shall be large enough to allow the data/command transmission/reception. Otherwise the transmission/reception will fail. See 1.1.2 Timeout Setting.
         * 3.4.5   Return Value
         * 1. bool : logical type
         * This function returns true if it is able to send a command to EP1 and  receive a response within 2*Timeout milliseconds.
         * This function returns false otherwise.
         *
         */

        /// <summary>
        /// /////
        /// </summary>
        /// <param name="TE03xxUSBdevice"></param>
        /// <param name="Command"></param>
        /// <param name="CmdLength"></param>
        /// <param name="Reply"></param>
        /// <param name="ReplyLength"></param>
        /// <param name="Timeout"></param>
        /// <returns></returns>

        public static bool TE_USB_FX2_SendCommand(ref CyUSBDevice TE_USB_FX2_USBDevice, ref byte[] Command, ref int CmdLength,
                                                  ref byte[] Reply, ref int ReplyLength, uint Timeout)
        {
            bool bResultCommand = false;
            bool bResultReply   = false;


            //Concrete class
            CyBulkEndPoint inEndpoint1  = null;
            CyBulkEndPoint outEndpoint1 = null;

            if (TE_USB_FX2_USBDevice != null)
            {
                //CyBulkEndPoint TE03xxUSBDeviceConcrete = TE03xxUSBdevice as CyBulkEndPoint;
                //Select the endpoint of IN number 1 (EP1 INPUT)
                inEndpoint1 = TE_USB_FX2_USBDevice.EndPointOf(0x81) as CyBulkEndPoint;
                //Select the endpoint of OUT number 1 (EP1 OUTPUT)
                outEndpoint1 = TE_USB_FX2_USBDevice.EndPointOf(0x01) as CyBulkEndPoint;

                // Set the timeout
                outEndpoint1.TimeOut = Timeout;
                inEndpoint1.TimeOut  = Timeout;

                //calls the XferData function for bulk transfer(OUT) in the cyusb.dll
                bResultCommand = outEndpoint1.XferData(ref Command, ref CmdLength);
                //Console.WriteLine("bResultCommand  {0} ", bResultCommand);
                //Console.WriteLine("Command[0] {0:X2} ", Command[0]);
                //Console.WriteLine("CmdLength {0} ", CmdLength);

                //uint inUSBstatus1 = inEndpoint1.UsbdStatus;
                //Console.WriteLine("UsbdStatus {0:X8} e ", inUSBstatus1);

                //uint inUSBstatus2 = inEndpoint1.NtStatus;
                //Console.WriteLine("NtStatus {0:X8} e ", inUSBstatus2);

                if (bResultCommand == true)
                {
                    //calls the XferData function for bulk transfer(IN) in the cyusb.dll
                    bResultReply = inEndpoint1.XferData(ref Reply, ref ReplyLength);
                    //Console.WriteLine("bResultReply  {0}  ", bResultReply);
                }
                else
                {
                    return(false);
                }
                if ((bResultCommand && bResultReply) == true)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 22
0
 internal void Init(CyUSBDevice usbDevice)
 {
     this.USB3 = usbDevice.bSuperSpeed;
     this.InitEndInPoints(usbDevice);
     this.cameraBufferLength = this.InEndpt.MaxPktSize;
     this.USB3    = this.cameraBufferLength != 512;
     this.buffers = new byte[this.cameraBufferLength];
 }
Ejemplo n.º 23
0
        private void SetDevice()
        {
            MyDevice = usbDevices[M280DEF.USB_VID, M280DEF.USB_PID] as CyUSBDevice;

            if (MyDevice != null)
            {
                // USB High Speed Check

                /*
                 * if (MyDevice.bHighSpeed == false)
                 * {
                 *  MessageBox.Show("M280 supports USB2.0 only.");
                 *  MyDevice = null;
                 *  inEndpoint = null;
                 *  ep0 = null;
                 * }
                 * else
                 */
                if (inEndpoint == null)
                {
                    // Set the IN and OUT endpoints
                    inEndpoint = MyDevice.EndPointOf(0x86) as CyBulkEndPoint;
                    ep0        = MyDevice.ControlEndPt;
                    // Set time out
                    inEndpoint.TimeOut = M280DEF.TRANSFER_TIMEOUT;
                    ep0.TimeOut        = M280DEF.TRANSFER_TIMEOUT;
                    // Get Image Info
                    GetImageInfo();
                    // Initialize Camera module
                    SendCommand(M280DEF.CMD_INIT_CAMERA, 0, 0);
                    // Turn on USB connected LED
                    //ST: Comment as we move the code to service
                    //labUSBConImg.Image = global::M280_SampleApp.Properties.Resources.green3;
                    // Start Check status
                    //ST: Comment as we move the code to service
                    //this.timCheckStatus.Start();
                }
            }
            else
            {
                inEndpoint = null;
                ep0        = null;

                // Turn off USB connected LED
                //ST: Comment as we move the code to service
                //labUSBConImg.Image = global::M280_SampleApp.Properties.Resources.gray3;
                //labSysReadyImg.Image = global::M280_SampleApp.Properties.Resources.gray3;
                //labReadyImg.Image = global::M280_SampleApp.Properties.Resources.gray3;
                //labBusyImg.Image = global::M280_SampleApp.Properties.Resources.gray3;
                //labButtonImg.Image = global::M280_SampleApp.Properties.Resources.gray3;

                //// Stop checking status thread
                //this.timCheckStatus.Stop();
                this.bInitM280 = false;
                this.bSysBusy  = false;
            }
        }
Ejemplo n.º 24
0
 internal void Init(CyUSBDevice usbDevice)
 {
     this.camProperties.Init(usbDevice);
     this.camComLayer.Init(usbDevice);
     this.ReadCMOSRegisters();
     this.ReadCalibration();
     this.camComLayer.SendCalibration(ref this.camProperties.calibration);
     this.camImg = new BCamImg(2048, this.GetImageMaxHeightSize());
 }
Ejemplo n.º 25
0
        /*
         * 3.6   TE_USB_FX2_SetData()
         *
         * 3.6.1   Declaration
         * public static bool TE_USB_FX2_SetData(ref CyUSBDevice TE_USB_FX2_USBDevice, ref byte[] DataWrite, ref int DataWriteLength,
         * int PipeNo, uint Timeout, int BufferSize)
         *
         * 3.6.2   Function Call
         * Your application program shall call this function like this:
         * TE_USB_FX2.TE_USB_FX2.TE_USB_FX2_SetData(ref TE_USB_FX2_USBDevice, ref DataWrite, ref DataWriteLength, PI_EP8, Timeout,
         * BufferSize);
         *
         * 3.6.3   Description
         * This function takes an already initialized USB device (CyUSBDevice is a type defined in CyUSB.dll), selected by
         * TE_USB_FX2_Open(), and writes data to the USB FX2 microcontroller endpoint EP8 (0x08). This data is then passed to the FPGA.
         * If there is not a proper connection (not using FX22MB_REG0_START_RX) between FPGA and USB FX2 microcontroller,
         * the function can experience a strange behavior. For example, a very low throughput (9-10 Mbyte/s even if a 22-24 Mbyte/s are
         * expected) is measured or the function fails returning false. These happen because buffer EP8 (the HW buffer, not the
         * SW buffer of the driver whose size is given by BufferSize parameter) is already full (it is not properly read/emptied by the
         * FPGA) and no longer able to receive further packets.
         * 3.6.4   Data throughput expected
         * The maximum data throughput expected (with a DataWriteLength= 120*10^6) is 24 Mbyte/s (PacketSize = BufferSize =131,072)
         * but in fact this value is variable between 22-24 Mbyte/s (the mean value seems 24 Mbyte/s); so if you measure this range
         * of values, the data reception can be considered normal.
         * The data throughput is variable in two way:
         * 1. depends on which host computer is used (on some host computers this value is even higher: 29 Mbyte/s)
         * 2. vary with every function call
         * 3.6.5   DataWrite size shall not be too large
         * TE_USB_FX2_SetData() seems unable to use too large arrays or, more precisely, this fact seems variable by changing host
         * computer. To be safe, do not try to transfer in a single packet very large data (120 millions of byte); transfer the same
         * data with many packets (1,200 packets * 100,000 byte) and copy the data in a single large data array if necessary (with
         * Buffer.BlockCopy()). Buffer.BlockCopy seems not to hinder throughput too much (max 2 Mbyte/s).
         * 3.6.5.1   Reduced version (pseudo code)
         * PACKETLENGTH=100000;
         * packets=1200;
         * byte[] data = new byte[packetlen*packets];
         * byte[] buffer = new byte[packetlen];
         * for (int i = 0; i < packets; i++)
         * {
         *   Buffer.BlockCopy(data, total_cnt, buffer, 0, packetlen);
         *   TE_USB_FX2_SetData(ref TE_USB_FX2_USBDevice, ref buffer, ref   packetlen, PI_EP8,  TIMEOUT_MS,BUFFER_SIZE);
         *   total_cnt += packetlen;
         * }
         * 3.6.5.2   Expanded version (code)
         * SendFPGAcommand(ref TE_USB_FX2_USBDevice, MB_Commands.FX22MB_REG0_START_RX, TIMEOUT_MS);
         * //ElapsedTime.Start(); //StopWatch start
         * Stopwatch stopWatch = new Stopwatch();
         * stopWatch.Start();
         * for (int i = 0; i < packets; i++)
         * {
         *   packetlen = PACKETLENGTH;
         *   Buffer.BlockCopy(data, total_cnt, buffer, 0, packetlen);
         *   if (TE_USB_FX2.TE_USB_FX2.TE_USB_FX2_SetData(ref  TE_USB_FX2_USBDevice, ref buffer, ref packetlen, PI_EP8, TIMEOUT_MS,
         *   BUFFER_SIZE) == false) errors++;
         *   else total_cnt += packetlen;
         * }
         * //total_cnt += (packetlen * packets);
         * stopWatch.Stop();
         * 3.6.6   DataWrite size shall not be too small
         * The  reason is described in section 1.1.4 PacketSize.
         * PacketSize has also a strong influence on DataThroughput. If PacketSize is too small (512 byte for example) you can achieve
         * very low data throughput (2.2 Mbyte/s) even if you use a large driver buffer (driver buffer size = 131,072 byte).
         * See 6 TE_USB_FX2_CyUSB.dll:  Data Transfer Throughput Optimization.
         *
         * 3.6.7   Parameters
         * 1. ref CyUSBDevice TE_USB-FX2_USBDevice
         * This parameter is passed by reference (ref). It points to the module selected by TE_USB_FX2_Open(). See pages 70-93 of
         * CyUSB.NET.pdf (Cypress CyUSB .NET DLL Programmer's Reference)
         * 2. ref byte[] DataWrite
         * This parameter is passed by reference (ref). C# applications use directly TE_USB_FX2_CyUSB.dll based on CyUSB.dll. To avoid
         * copying back and forth large amount of data between these two DLLs, data is passed by reference and not by value.
         * This parameter points to the byte array that contains the data to be written to buffer EP8 (0x08) of USB FX2 microcontroller.
         * Data contained in EP8 are then read by the FPGA.
         * 3. ref int DataWriteLength
         * This parameter is passed by reference (ref). This parameter is the length (in bytes) of the previous byte array;
         * it is the length of the packet read from FX2 USB endpoint EP6 (0x86). Normally it is PacketLength.
         * 4. int PipeNumber
         * This parameter is the value that identify the endpoint used for the data transfer. It is called PipeNumber because it
         * identifies the buffer (pipe) used by the USB FX2 microcontroller.
         * 5. uint Timeout.
         * The unsigned integer value is the time in milliseconds assigned to the synchronous method XferData() of data transfer used by
         * CyUSB.dll.
         * Timeout is the time that is allowed to the function for sending/receiving the data packet passed to the function; this
         * timeout shall be large enough to allow the data/command transmission/reception. Otherwise the transmission/reception will
         * fail. See 1.1.2 Timeout Setting.
         * 6. int BufferSize
         * The integer value is the dimension (in bytes) of the driver buffer (SW) used in data transmission of a single endpoint
         * (EP8 0x08 in this case); the total buffer size is the sum of all BufferSize of every endpoint used.
         * The BufferSize has a strong influence on DataThroughput. If  BufferSize is too small, DataThroughput can be 1/3-1/2 of
         * the maximum value (from a maximum value of 24 Mbyte/s for write transactions to an actual value of 14 Mbyte/s).
         * If BufferSize has a large value (a roomy buffer), the program shall be able to cope with the non-deterministic behavior of
         * C# without losing packets.
         *
         * 3.6.8   Return Value
         * 1. bool: logical type
         * This function returns true if it is able to write data to buffer EP8 within Timeout milliseconds.
         * This function returns false otherwise.
         *
         */

        public static bool TE_USB_FX2_SetData(ref CyUSBDevice TE_USB_FX2_USBDevice, ref byte[] DataWrite, ref int DataWriteLength, int PipeNo, uint Timeout, int BufferSize)
        //public static bool TE_USB_FX2_SetData(ref CyBulkEndPoint outEndpointPipeNo, ref byte[] DataWrite, ref int DataWriteLength)
        {
            bool bResultDataRead = false;
            byte PipeNoHex       = 0x00;

            CyBulkEndPoint outEndpointPipeNo = null;

            //Shortest and more portable way to select the Address using the PipeNumber
            if (PipeNo == 8)
            {
                PipeNoHex = 0x08;
            }
            else
            {
                PipeNoHex = 0x00;
            }

            if ((TE_USB_FX2_USBDevice != null) && (PipeNoHex == 0x08))
            {
                outEndpointPipeNo         = TE_USB_FX2_USBDevice.EndPointOf(PipeNoHex) as CyBulkEndPoint;
                outEndpointPipeNo.TimeOut = Timeout;

                //int MaxPacketSize= outEndpointPipeNo.MaxPktSize;
                //Console.WriteLine("MaxPacketSize {0} ", MaxPacketSize);

                //int XferSize1 = outEndpointPipeNo.XferSize;
                //Console.WriteLine("XferSize {0} ", XferSize1);

                //outEndpointPipeNo.XferMode = XMODE.DIRECT;

                outEndpointPipeNo.XferSize = BufferSize;// 131072;

                //calls the XferData function for bulk transfer(IN) in the cyusb.dll
                bResultDataRead = outEndpointPipeNo.XferData(ref DataWrite, ref DataWriteLength);
                //Console.WriteLine("bResultDataRead {0} ", bResultDataRead);

                //uint inUSBstatus1 = outEndpointPipeNo.UsbdStatus;
                //Console.WriteLine("UsbdStatus {0:X8} e ", inUSBstatus1);

                //uint inUSBstatus2 = outEndpointPipeNo.NtStatus;
                //Console.WriteLine("NtStatus {0:X8} e ", inUSBstatus2);

                if (bResultDataRead == true)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 26
0
        public void GetDevice()
        {
            if (DeviceAttached == true)
            {
                myDevice    = usbDevices[0x04b4, 0x00F1] as CyUSBDevice;           // check for device with VID/PID of 0x04B4/0x1002
                myFX3Device = usbDevices[0x04B4, 0x00F3] as CyFX3Device;


                if ((myFX3Device != null) && (myDevice == null))                                           // If myDevice exists
                {
                    button1.Enabled = true;
                    button2.Enabled = false;
                    button3.Enabled = false;

                    StatLabel1.Text = "NEXT STEP: Use Download Firmware button to load image into FX3";
                    rtConsole.AppendText("EZ-USB FX3 Bootloader Device connected\n");
                }
                else if ((myDevice != null) && (myFX3Device == null))              // If myDevice exists
                {
                    BulkOutEndPt    = myDevice.EndPointOf(0x02) as CyBulkEndPoint; //Assign EP2 as BulkOutEP and EP6 as BulkInEP
                    button3.Enabled = true;
                    button1.Enabled = false;

                    button2.Enabled = false;
                    rtConsole.AppendText("FX3 - Xilinx Slave Serial Programmer detected\n");
                    StatLabel1.Text = "NEXT STEP: Use Select Bitstream button to select the .bin file for FPGA ";
                }
                else if ((firmwaredownloaded) && (myDevice != null))
                {
                    button1.Enabled = false;
                    rtConsole.AppendText("NO FX3 - Xilinx Slave Serial Programmer detected\n");
                    StatLabel1.Text = "NEXT STEP: Reset the FX3 board and Download the right image into FX3";
                }
                else
                {
                    button1.Enabled = false;
                    button2.Enabled = false;
                    button3.Enabled = false;



                    rtConsole.AppendText("No EZ-USB  FX3 device is connected\n");
                    StatLabel1.Text = "NEXT STEP: Connect EZ-USB FX3 board to PC using an USB cable";
                    DeviceAttached  = false;
                }
            }

            if (DeviceAttached == false)
            {
                DisableApp();                                                          // there is either no device attached or the attached device is not a FX2
            }
            else
            {
                EnableApp();                                                           // the attached device is a FX2LP with our VID/PID
            }
        }
Ejemplo n.º 27
0
 public DDSUSBChip(CyUSBDevice CyUSBDevice)
 {
     cyUSBDevice = CyUSBDevice;
     // Switch to interface 1  which provides several Endpoints
     cyUSBDevice.AltIntfc = 1;
     // Define Endpoints
     EP1OUT = cyUSBDevice.EndPointOf(0x01);
     EP1IN  = cyUSBDevice.EndPointOf(0x81);
     EP2OUT = cyUSBDevice.EndPointOf(0x02);
 }
        public static bool SendFPGAcommand(ref CyUSBDevice TE_USB_FX2_USBDevice, MB_Commands Command, uint Timeout)
        {
            if (TE_USB_FX2_USBDevice == null)
            {
                Console.WriteLine("Error,no device is selected");
                return(false);
            }


            bool bResultCommand_FX22MB = false;

            byte[] cmd_FX22MB_REG0          = new byte[64];
            byte[] reply_FX22MB_REG0        = new byte[64];
            int    cmd_length_FX22MB_REG0   = 64;
            int    reply_length_FX22MB_REG0 = 64;

            //Command layout:
            //0xAD - Command type I2C write
            //0x3F - Address (I2C address of Microblaze)
            //0x0C - I2C_BYTES
            //0x00 - FX22MB_REG0_NOP
            //0x00 - FX22MB_REG0_NOP
            //0x00 - FX22MB_REG0_NOP
            //0x?? - Command

            //0x AD 3F 0C 00 00 00 ??
            cmd_FX22MB_REG0[0] = (byte)FX2_Commands.I2C_WRITE;
            cmd_FX22MB_REG0[1] = (byte)FX2_Parameters.MB_I2C_ADDRESS;
            cmd_FX22MB_REG0[2] = (byte)FX2_Parameters.I2C_BYTES;
            cmd_FX22MB_REG0[3] = (byte)MB_Commands.FX22MB_REG0_NOP;
            cmd_FX22MB_REG0[4] = (byte)MB_Commands.FX22MB_REG0_NOP;
            cmd_FX22MB_REG0[5] = (byte)MB_Commands.FX22MB_REG0_NOP;
            cmd_FX22MB_REG0[6] = (byte)Command;

            bResultCommand_FX22MB = TE_USB_FX2.TE_USB_FX2.TE_USB_FX2_SendCommand(ref TE_USB_FX2_USBDevice, ref cmd_FX22MB_REG0, ref cmd_length_FX22MB_REG0, ref cmd_FX22MB_REG0, ref reply_length_FX22MB_REG0, Timeout);

            //bResultCommand_FX22MB_REG0_START = inEndpointCmd.XferData(ref cmd_FX22MB_REG0_START, ref cmd_length_FX22MB_REG0_START);

            //Console.WriteLine("bResultCommand_FX22MB_REG0_START {0}", bResultCommand_FX22MB_REG0_START);

            //bResultReply_FX22MB_REG0_START = outEndpointCmd.XferData(ref reply_FX22MB_REG0_START, ref reply_length_FX22MB_REG0_START);
            //END

            //Console.WriteLine("bResultReply_FX22MB_REG0_START {0}", bResultReply_FX22MB_REG0_START);

            if (bResultCommand_FX22MB)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 29
0
        /*Summary
         * Search the device with VID-PID 04b4-00F1 and if found, select the end point
         */
        private void SetDevice(bool bPreserveSelectedDevice)
        {
            int nCurSelection = 0;

            if (DevicesComboBox.Items.Count > 0)
            {
                nCurSelection = DevicesComboBox.SelectedIndex;
                DevicesComboBox.Items.Clear();
            }
            int nDeviceList = usbDevices.Count;

            for (int nCount = 0; nCount < nDeviceList; nCount++)
            {
                USBDevice fxDevice = usbDevices[nCount];
                String    strmsg;
                strmsg = "(0x" + fxDevice.VendorID.ToString("X4") + " - 0x" + fxDevice.ProductID.ToString("X4") + ") " + fxDevice.FriendlyName;
                DevicesComboBox.Items.Add(strmsg);
            }

            if (DevicesComboBox.Items.Count > 0)
            {
                DevicesComboBox.SelectedIndex = ((bPreserveSelectedDevice == true) ? nCurSelection : 0);
            }

            USBDevice dev = usbDevices[DevicesComboBox.SelectedIndex];

            if (dev != null)
            {
                MyDevice = (CyUSBDevice)dev;

                GetEndpointsOfNode(MyDevice.Tree);
                PpxBox.Text   = "16"; //Set default value to 8 Packets
                QueueBox.Text = "8";
                if (EndPointsComboBox.Items.Count > 0)
                {
                    EndPointsComboBox.SelectedIndex = 0;
                    StartBtn.Enabled = true;
                }
                else
                {
                    StartBtn.Enabled = false;
                }

                Text = MyDevice.FriendlyName;
            }
            else
            {
                StartBtn.Enabled = false;
                EndPointsComboBox.Items.Clear();
                EndPointsComboBox.Text = "";
                Text = "C# Streamer - no device";
            }
        }
Ejemplo n.º 30
0
 private void usbDevices_DeviceRemoved(object sender, EventArgs e)
 {
     // release usb device
     _isUSBAvailable = false;
     if (loopDevice != null)
     {
         loopDevice.Dispose();
     }
     loopDevice = null;
     //             intDevice();
     OnDeviceRemoved();
 }