コード例 #1
0
        private void MonoSetDevice()
        {
            // convert MonoUsbProfileList to List<>
            List <MonoUsbProfile> usbProfiles = new List <MonoUsbProfile>();

            foreach (MonoUsbProfile usbProfile in profileList)
            {
                usbProfiles.Add(usbProfile);
            }

            // DeviceRemoved
            foreach (var fx2Device in fx2Devices.ToArray())
            {
                if (!usbProfiles.Contains(fx2Device.USBProfile))
                {
                    fx2Device.Dispose();
                    fx2Devices.Remove(fx2Device);
                }
            }

            // DeviceAttached
            foreach (MonoUsbProfile usbProfile in profileList)
            {
                if (usbProfile.DeviceDescriptor.VendorID == 0x04b4 && usbProfile.DeviceDescriptor.ProductID == 0x1004)
                {
                    if (fx2Devices.Count(p => p.USBProfile == usbProfile) == 0)
                    {
                        byte[] response;
                        using (var monoDeviceHandle = usbProfile.OpenDeviceHandle())
                        {
                            response = Fx2Device.ReceiveVendorResponse(null, monoDeviceHandle, (byte)Fx2Device.EVendorRequests.DeviceType, 1);
                        }
                        if (response == null)
                        {
                            fx2Devices.Add(new Fx2Device(null, usbProfile));
                        }
                        else
                        {
                            Fx2Device.EDeviceType deviceType = (Fx2Device.EDeviceType)response[0];
                            switch (deviceType)
                            {
                            case Fx2Device.EDeviceType.DAC:
                            case Fx2Device.EDeviceType.DAC_C:
                            case Fx2Device.EDeviceType.DAC_SA: fx2Devices.Add(new DACDevice(null, usbProfile, deviceType)); break;

                            case Fx2Device.EDeviceType.ADC:
                            case Fx2Device.EDeviceType.ADC_C: fx2Devices.Add(new ADCDevice(null, usbProfile, deviceType)); break;

                            case Fx2Device.EDeviceType.ADC_SA: fx2Devices.Add(new BorIPDevice(null, usbProfile, deviceType)); break;

                            default: fx2Devices.Add(new Fx2Device(null, usbProfile)); break;
                            }
                        }
                    }
                }
            }
        }
コード例 #2
0
        private void SetDevice()
        {
            // convert USBDeviceList to List<>
            List <CyUSBDevice> usbDevices = new List <CyUSBDevice>();

            foreach (CyUSBDevice usbDevice in usbDeviceList)
            {
                usbDevices.Add(usbDevice);
            }

            // DeviceRemoved
            foreach (var fx2Device in fx2Devices.ToArray())
            {
                if (!usbDevices.Contains(fx2Device.USBDevice))
                {
                    fx2Device.Dispose();
                    fx2Devices.Remove(fx2Device);
                }
            }

            // DeviceAttached
            foreach (CyUSBDevice usbDevice in usbDeviceList)
            {
                if (usbDevice.VendorID == 0x04b4 && usbDevice.ProductID == 0x1004)
                {
                    if (fx2Devices.Count(p => p.USBDevice == usbDevice) == 0)
                    {
                        byte[] response = Fx2Device.ReceiveVendorResponse(usbDevice, null, (byte)Fx2Device.EVendorRequests.DeviceType, 1);
                        if (response == null)
                        {
                            fx2Devices.Add(new Fx2Device(usbDevice, null));
                        }
                        else
                        {
                            Fx2Device.EDeviceType deviceType = (Fx2Device.EDeviceType)response[0];
                            switch (deviceType)
                            {
                            case Fx2Device.EDeviceType.DAC:
                            case Fx2Device.EDeviceType.DAC_C:
                            case Fx2Device.EDeviceType.DAC_SA: fx2Devices.Add(new DACDevice(usbDevice, null, deviceType)); break;

                            case Fx2Device.EDeviceType.ADC:
                            case Fx2Device.EDeviceType.ADC_C: fx2Devices.Add(new ADCDevice(usbDevice, null, deviceType)); break;

                            case Fx2Device.EDeviceType.ADC_SA: fx2Devices.Add(new BorIPDevice(usbDevice, null, deviceType)); break;

                            default: fx2Devices.Add(new Fx2Device(usbDevice, null)); break;
                            }
                        }
                    }
                }
            }
        }