public USBDeviceList(byte DeviceMask, App_PnP_Callback fnCallBack) { Items = new ArrayList(); hDevNotifications = new ArrayList(); USBDriverGuids = new ArrayList(); EventCallBack = new App_PnP_Callback(PnP_Event_Handler); MsgWin.AppCallback = EventCallBack; AppCallBack = fnCallBack; // Get the HID GUID PInvoke.HidD_GetHidGuid(ref HidGuid); // Create list of driver GUIDs for this instance FillDriverGuids(DeviceMask); USBDevice tmpDev, tmp; int devs = 0; foreach (Guid guid in USBDriverGuids) { // tmpDev is just used for the DeviceCount functionality if (guid.Equals(CyConst.StorGuid)) { tmpDev = new CyUSBStorDevice(guid); } else if (guid.Equals(HidGuid)) { tmpDev = new CyHidDevice(HidGuid); } else { tmpDev = new CyFX2Device(guid); } // DeviceCount is IO intensive. Don't use it as for loop limit devs = tmpDev.DeviceCount; for (int d = 0; d < devs; d++) { // Create the new USBDevice objects of the correct type, based on guid if (guid.Equals(CyConst.StorGuid)) { tmp = new CyUSBStorDevice(guid); } else if (guid.Equals(HidGuid)) { tmp = new CyHidDevice(HidGuid); } else { tmp = new CyFX2Device(guid); if (tmp.Open((byte)d)) {// open handle to check device type CyUSBDevice t = tmp as CyUSBDevice; if (!t.CheckDeviceTypeFX3FX2()) {//FX3 tmp.Close(); tmp = new CyFX3Device(guid); } else { tmp.Close(); } } } if (tmp.Open((byte)d)) { Items.Add(tmp); // This creates new reference to tmp in Items tmp.RegisterForPnPEvents(MsgWin.Handle); } } if (guid.Equals(CyConst.StorGuid)) // We're not sure which drivers were identified, so setup PnP with both { RegisterForPnpEvents(MsgWin.Handle, CyConst.DiskGuid); RegisterForPnpEvents(MsgWin.Handle, CyConst.CdGuid); } else { RegisterForPnpEvents(MsgWin.Handle, guid); } } // foreach guid }
public USBDevice Add() { if (_alreadyDisposed) { throw new ObjectDisposedException(""); } USBDevice tmp, tmpDev; foreach (Guid guid in USBDriverGuids) { // tmpDev is just used for the DeviceCount functionality if (guid.Equals(CyConst.StorGuid)) { tmpDev = new CyUSBStorDevice(guid); } else if (guid.Equals(HidGuid)) { tmpDev = new CyHidDevice(guid); } else { tmpDev = new CyFX2Device(guid); } // The number of devices now connected to this GUID int connectedDevs = tmpDev.DeviceCount; tmpDev.Dispose(); // Find out how many items have this guid int listedDevs = 0; foreach (USBDevice dev in Items) { if (guid.Equals(CyConst.StorGuid) && (dev._drvGuid.Equals(CyConst.CdGuid) || dev._drvGuid.Equals(CyConst.DiskGuid))) { listedDevs++; } else if (dev._drvGuid.Equals(guid)) { listedDevs++; } } // If greater, add if (connectedDevs > listedDevs) { for (byte d = 0; d < connectedDevs; d++) { // Create the new USBDevice object of the correct type, based on guid if (guid.Equals(CyConst.StorGuid)) { tmp = new CyUSBStorDevice(guid); } else if (guid.Equals(HidGuid)) { tmp = new CyHidDevice(guid); } else { tmp = new CyFX2Device(guid); if (tmp.Open((byte)d)) {// open handle to check device type CyUSBDevice t = tmp as CyUSBDevice; if (!t.CheckDeviceTypeFX3FX2()) {//FX3 tmp.Close(); tmp = new CyFX3Device(guid); } else { tmp.Close(); } } } // If this device not already in the list if (tmp.Open(d) && (DeviceIndex(tmp) == 0xFF)) { Items.Add(tmp); tmp.RegisterForPnPEvents(MsgWin.Handle); return(tmp); } else { tmp.Dispose(); } } } } return(null); }
public USBDeviceList(byte DeviceMask, App_PnP_Callback fnCallBack) { Items = new ArrayList(); hDevNotifications = new ArrayList(); USBDriverGuids = new ArrayList(); EventCallBack = new App_PnP_Callback(PnP_Event_Handler); MsgWin.AppCallback = EventCallBack; AppCallBack = fnCallBack; // Get the HID GUID PInvoke.HidD_GetHidGuid(ref HidGuid); // Create list of driver GUIDs for this instance FillDriverGuids(DeviceMask); USBDevice tmpDev, tmp; int devs = 0; foreach (Guid guid in USBDriverGuids) { // tmpDev is just used for the DeviceCount functionality if (guid.Equals(CyConst.StorGuid)) tmpDev = new CyUSBStorDevice(guid); else if (guid.Equals(HidGuid)) tmpDev = new CyHidDevice(HidGuid); else tmpDev = new CyFX2Device(guid); // DeviceCount is IO intensive. Don't use it as for loop limit devs = tmpDev.DeviceCount; for (int d = 0; d < devs; d++) { // Create the new USBDevice objects of the correct type, based on guid if (guid.Equals(CyConst.StorGuid)) tmp = new CyUSBStorDevice(guid); else if (guid.Equals(HidGuid)) tmp = new CyHidDevice(HidGuid); else { tmp = new CyFX2Device(guid); if (tmp.Open((byte)d)) {// open handle to check device type CyUSBDevice t = tmp as CyUSBDevice; if (!t.CheckDeviceTypeFX3FX2()) {//FX3 tmp.Close(); tmp = new CyFX3Device(guid); } else tmp.Close(); } } if (tmp.Open((byte)d)) { Items.Add(tmp); // This creates new reference to tmp in Items tmp.RegisterForPnPEvents(MsgWin.Handle); } } if (guid.Equals(CyConst.StorGuid)) // We're not sure which drivers were identified, so setup PnP with both { RegisterForPnpEvents(MsgWin.Handle, CyConst.DiskGuid); RegisterForPnpEvents(MsgWin.Handle, CyConst.CdGuid); } else RegisterForPnpEvents(MsgWin.Handle, guid); } // foreach guid }
public USBDevice Add() { if (_alreadyDisposed) throw new ObjectDisposedException(""); USBDevice tmp, tmpDev; foreach (Guid guid in USBDriverGuids) { // tmpDev is just used for the DeviceCount functionality if (guid.Equals(CyConst.StorGuid)) tmpDev = new CyUSBStorDevice(guid); else if (guid.Equals(HidGuid)) tmpDev = new CyHidDevice(guid); else tmpDev = new CyFX2Device(guid); // The number of devices now connected to this GUID int connectedDevs = tmpDev.DeviceCount; tmpDev.Dispose(); // Find out how many items have this guid int listedDevs = 0; foreach (USBDevice dev in Items) if (guid.Equals(CyConst.StorGuid) && (dev._drvGuid.Equals(CyConst.CdGuid) || dev._drvGuid.Equals(CyConst.DiskGuid))) listedDevs++; else if (dev._drvGuid.Equals(guid)) listedDevs++; // If greater, add if (connectedDevs > listedDevs) { for (byte d = 0; d < connectedDevs; d++) { // Create the new USBDevice object of the correct type, based on guid if (guid.Equals(CyConst.StorGuid)) tmp = new CyUSBStorDevice(guid); else if (guid.Equals(HidGuid)) tmp = new CyHidDevice(guid); else { tmp = new CyFX2Device(guid); if (tmp.Open((byte)d)) {// open handle to check device type CyUSBDevice t = tmp as CyUSBDevice; if (!t.CheckDeviceTypeFX3FX2()) {//FX3 tmp.Close(); tmp = new CyFX3Device(guid); } else tmp.Close(); } } // If this device not already in the list if (tmp.Open(d) && (DeviceIndex(tmp) == 0xFF)) { Items.Add(tmp); tmp.RegisterForPnPEvents(MsgWin.Handle); if (connectedDevs == 1 && d == 0) return tmp; } } } } return null; }
public void DownloadUserImg(CyFX3Device Fx3, FX3_FWDWNLOAD_MEDIA_TYPE enmMediaType) { // string tmpFilter = Fr.FOpenDialog.Filter; FX3_FWDWNLOAD_ERROR_CODE enmResult = FX3_FWDWNLOAD_ERROR_CODE.FAILED; string tmpFilter = FOpenDialog.Filter; FOpenDialog.Filter = "Firmware Image files (*.img) | *.img"; if ((Fx3 != null) && (FOpenDialog.ShowDialog() == DialogResult.OK)) { if (enmMediaType == FX3_FWDWNLOAD_MEDIA_TYPE.I2CE2PROM) {// I2C EEPROM Download StatLabel.Text = "Programming of I2C EEPROM in Progress..."; Refresh(); enmResult = Fx3.DownloadFw(FOpenDialog.FileName, FX3_FWDWNLOAD_MEDIA_TYPE.I2CE2PROM); StatLabel.Text = "Programming of I2C EEPROM " + Fx3.GetFwErrorString(enmResult); Refresh(); } else {// SPI FLASH FIRMWARE DOWNLOAD StatLabel.Text = "Programming of SPI FLASH in Progress..."; Refresh(); enmResult = Fx3.DownloadFw(FOpenDialog.FileName, FX3_FWDWNLOAD_MEDIA_TYPE.SPIFLASH); //enmResult = Fx3.DownloadFw("C:\\app.img", FX3_FWDWNLOAD_MEDIA_TYPE.SPIFLASH); StatLabel.Text = "Programming of SPI FLASH " + Fx3.GetFwErrorString(enmResult); Refresh(); } } else { StatLabel.Text = "User Cancelled operation"; Refresh(); } FOpenDialog.FileName = ""; FOpenDialog.Filter = tmpFilter; }
public void DoWork() { // This method will be called when the thread is started. int timeoutCounter = 10; // 10 second time out counter Fx3 = null; while (true) { //Search for Boot Programmer System.Threading.Thread.Sleep(1000); RefreshDeviceTree(); //exit condition timeoutCounter--; if (timeoutCounter == 0) { Fr.BootProgrammerDeviceNotFound(); return; } for (int i = 0; i < fx.Count; i++) { Fx3 = fx[i] as CyFX3Device; if ((Fx3 != null) && (Fx3.ProductID == 0x4720)) { Fr.BootProgrammerDeviceFound(); break; } } if (Fx3 != null) break; // break while loop } // Download the user IMG file firmware Fr.DownloadUserImg(Fx3, MediaType); }