Esempio n. 1
0
            /// <summary>return a list of the down stream ports</summary>
            /// <returns>List of downstream ports</returns>
            internal IEnumerable <UsbPort> GetPorts()
            {
                List <UsbPort> portList = new List <UsbPort>();

                // Open a handle to the Hub device
                IntPtr h = CreateFile(HubDevicePath, GENERIC_WRITE, FILE_SHARE_WRITE, IntPtr.Zero, OPEN_EXISTING, 0,
                                      IntPtr.Zero);

                if (h == INVALID_HANDLE_VALUE)
                {
                    return(new ReadOnlyCollection <UsbPort>(portList));
                }

                int    nBytes            = Marshal.SizeOf(typeof(UsbNodeConnectionInformationEx));
                IntPtr ptrNodeConnection = Marshal.AllocHGlobal(nBytes);

                // loop thru all of the ports on the hub
                // BTW: Ports are numbered starting at 1
                for (int i = 1; i <= HubPortCount; i++)
                {
                    var nodeConnection = new UsbNodeConnectionInformationEx
                    {
                        ConnectionIndex = i
                    };

                    Marshal.StructureToPtr(nodeConnection, ptrNodeConnection, true);

                    if (!DeviceIoControl(h, IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX, ptrNodeConnection, nBytes,
                                         ptrNodeConnection, nBytes, out _, IntPtr.Zero))
                    {
                        continue;
                    }

                    nodeConnection =
                        (UsbNodeConnectionInformationEx)Marshal.PtrToStructure(ptrNodeConnection,
                                                                               typeof(UsbNodeConnectionInformationEx));

                    // load up the USBPort class
                    var port = new UsbPort
                    {
                        PortPortNumber        = i,
                        PortHubDevicePath     = HubDevicePath,
                        PortStatus            = ((UsbConnectionStatus)nodeConnection.ConnectionStatus).ToString(),
                        PortSpeed             = ((UsbDeviceSpeed)nodeConnection.Speed).ToString(),
                        PortIsDeviceConnected =
                            nodeConnection.ConnectionStatus == (int)UsbConnectionStatus.DeviceConnected,
                        PortIsHub            = Convert.ToBoolean(nodeConnection.DeviceIsHub),
                        PortDeviceDescriptor = nodeConnection.DeviceDescriptor
                    };

                    // add it to the list
                    portList.Add(port);
                }

                Marshal.FreeHGlobal(ptrNodeConnection);
                CloseHandle(h);

                // convert it into a Collection
                return(new ReadOnlyCollection <UsbPort>(portList));
            }
Esempio n. 2
0
        public static void Main()
        {
            sid  = new MOS6581(Pins.GPIO_PIN_D10, Pins.GPIO_PIN_D9);
            _usb = new UsbPort("COM4", 250000, _ProcessPacket);
            //Timer usbstatusreport = new Timer(new TimerCallback(_usb.SendPacket), null, 1000, 700);

            sid.reset();
            sid.volume(15);               // set volume to the maximum, 15.

            sid.setMode(0, SID_TRIANGLE); //set voice 0 to a ramp waveform
            sid.setADEnvelope(0, 0, 0);   //Set voice 0's Attack and Decay envelope
            sid.setSREnvelope(0, 15, 0);  //Set voice 0's Sustain and Release envelope

            sid.setFrequency(0, A[4]);

            sid.setVoice(0, true); //Set voice 0 to 'on'.
            //  sid.setVoice(2, true);
            //  sid.setVoice(3, true);

            while (true)
            {
                Thread.Sleep(900);
                _usb.SendPacket();
            }
        }
Esempio n. 3
0
        public static IEnumerable <UsbTreeItem> TextPort(int depth, UsbPort port)
        {
            var device = port.GetDevice(null);

            yield return(new UsbTreeItem {
                Depth = depth, Value = $"D-{device?.Manufacturer} ({device?.Address})"
            });
        }
        private void VerifyUSB30()
        {
            LogHelper.Log("VerifyUSB30:");
            string query = string.Format("select PNPDeviceID from Win32_DiskDrive where InterfaceType='USB' and index='{0}'", CurrentPhysicalDiskIndex);

            ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
            string pnpDeviceID = string.Empty;

            foreach (ManagementObject mo in searcher.Get())
            {
                pnpDeviceID = mo["PNPDeviceID"].ToString();
            }

            if (string.IsNullOrEmpty(pnpDeviceID))
            {
                throw new SystemVerificationException(SystemVerificationErrorCode.UsbDeviceNotFound, "Could not find usb pnp device id");
            }

            pnpDeviceID = pnpDeviceID.Substring(pnpDeviceID.LastIndexOf("\\") + 1, pnpDeviceID.Length - pnpDeviceID.LastIndexOf("\\") - 3);
            LogHelper.Log("VerifyUSB30: PNPDeviceID: {0}", pnpDeviceID);

            USBDevice usbDevice = GetCurrentUSBDevice(pnpDeviceID);

            if (usbDevice == null)
            {
                LogHelper.Log("VerifyUSB30: Could not find USB device. This might be fine, so, continuing...");
                return;
            }

            LogHelper.Log("VerifyUSB30: Found the USB device: {0}", usbDevice);

            List <UsbHub> hubs = GetAvailableUSBPorts();

            UsbPort connectedPort = null;

            bool availableUsb30Ports = false;

            foreach (UsbHub hub in hubs)
            {
                foreach (UsbPort port in hub.Ports)
                {
                    availableUsb30Ports |= port.IsUSB30;
                    if (!string.IsNullOrEmpty(port.DriverKeyName) && port.DriverKeyName.Equals(usbDevice.DriverKeyName))
                    {
                        connectedPort = port;
                    }
                }
            }

            if (connectedPort == null)
            {
                throw new SystemVerificationException(SystemVerificationErrorCode.UsbPortNotFound, "Could not find the usb port");
            }

            if (connectedPort.IsUSB30)
            {
                //The USB device is connected to a USB3.0 Port
                //Returning means the method is terminated succesfully
                return;
            }
            else
            {
                if (availableUsb30Ports)
                {
                    throw new SystemVerificationException(SystemVerificationErrorCode.NotUSB30Port, "The USB is not inserted into a USB3.0 port");
                }
                else
                {
                    throw new SystemVerificationException(SystemVerificationErrorCode.NoUSBPortsFound, "The machine doesn't have USB3.0 Ports");
                }
            }
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            Console.WriteLine("START RUNNING ADAPTER.");
            Console.WriteLine("To use american socket press 1");
            Console.WriteLine("To use bicicle dinamo press 2");
            Console.WriteLine("To use car battery press 3");
            Console.WriteLine("To use solar battery press 4");
            Console.WriteLine("To use turbine generator press 5");
            Console.WriteLine("To use usb port press 6");

            char adapter = Console.ReadKey().KeyChar;

            switch (adapter)
            {
            case '1':
                Console.WriteLine("App: Launched american socket.");
                AmericanSocket        amerSocket        = new AmericanSocket();
                AmericanSocketAdapter amerSocketAdapter = new AmericanSocketAdapter(amerSocket);
                _ = new LapTop(amerSocketAdapter.OutputVoltage);
                break;

            case '2':
                Console.WriteLine("App: Launched bicicle dinamo.");
                BicicleDinamo  bicicleDinamo        = new BicicleDinamo();
                UsbPortAdapter bicicleDinamoAdapter = new UsbPortAdapter(bicicleDinamo);
                _ = new LapTop(bicicleDinamoAdapter.OutputVoltage);
                break;

            case '3':
                Console.WriteLine("App: Launched car battery.");
                CarBattery        carBattery        = new CarBattery();
                CarBatteryAdapter carBatteryAdapter = new CarBatteryAdapter(carBattery);
                _ = new LapTop(carBatteryAdapter.OutputVoltage);
                break;

            case '4':
                Console.WriteLine("App: Launched solar battery.");
                SolarBattery        solarBattery        = new SolarBattery();
                SolarBatteryAdapter solarBatteryAdapter = new SolarBatteryAdapter(solarBattery);
                _ = new LapTop(solarBatteryAdapter.OutputVoltage);
                break;

            case '5':
                Console.WriteLine("App: Launched turbine generator.");
                TurbineGenerator        turbineGenerator        = new TurbineGenerator();
                TurbineGeneratorAdapter turbineGeneratorAdapter = new TurbineGeneratorAdapter(turbineGenerator);
                _ = new LapTop(turbineGeneratorAdapter.OutputVoltage);
                break;

            case '6':
                Console.WriteLine("App: Launched usb port.");
                UsbPort        usbSource      = new UsbPort();
                UsbPortAdapter usbPortAdapter = new UsbPortAdapter(usbSource);
                _ = new LapTop(usbPortAdapter.OutputVoltage);
                break;

            default:
                Console.WriteLine("Something went wrong. Please try again.");
                Main(new string[0]);
                break;
            }

            Console.WriteLine("END RUNNING ADAPTER.");
            Console.ReadKey();
        }