示例#1
0
文件: Constants.cs 项目: ckc/WinApp
        public static UsbSetupPacket CreateSetupPacket(SetupPacketPurpose purpose)
        {
            var vendorControlOutRequestType = new UsbControlRequestType
            {
                ControlTransferType = UsbControlTransferType.Vendor,
                Direction           = UsbTransferDirection.Out,
                Recipient           = UsbControlRecipient.Device
            };

            switch (purpose)
            {
            case SetupPacketPurpose.SetupDeviceForFirmwareUpdate:
                return(new UsbSetupPacket
                {
                    RequestType = vendorControlOutRequestType,
                    Request = 0xC5,
                    Value = 0,
                    Index = 0,
                    Length = 0
                });

            case SetupPacketPurpose.WriteSector:
                /// <summary>
                /// Value, Index, Length must be filled in later with information specifically about the data being transfered
                /// </summary>
                return(new UsbSetupPacket
                {
                    RequestType = vendorControlOutRequestType,
                    Request = 0xC2,
                });

            case SetupPacketPurpose.ResetDevice:
                return(new UsbSetupPacket
                {
                    RequestType = vendorControlOutRequestType,
                    Request = 0xDA,
                    Value = 0,
                    Index = 0,
                    Length = 0
                });
            }

            return(null);
        }
        public static UsbSetupPacket CreateSetupPacket(SetupPacketPurpose purpose)
        {
            var vendorControlOutRequestType = new UsbControlRequestType
                {
                    ControlTransferType = UsbControlTransferType.Vendor,
                    Direction = UsbTransferDirection.Out,
                    Recipient = UsbControlRecipient.Device
                };

            switch (purpose)
            {
                case SetupPacketPurpose.SetupDeviceForFirmwareUpdate:
                    return new UsbSetupPacket
                        {
                            RequestType = vendorControlOutRequestType,
                            Request = 0xC5,
                            Value = 0,
                            Index = 0,
                            Length = 0
                        };
                case SetupPacketPurpose.WriteSector:
                    /// <summary>
                    /// Value, Index, Length must be filled in later with information specifically about the data being transfered
                    /// </summary>
                    return new UsbSetupPacket
                        {
                            RequestType = vendorControlOutRequestType,
                            Request = 0xC2,
                        };
                case SetupPacketPurpose.ResetDevice:
                    return new UsbSetupPacket
                        {
                            RequestType = vendorControlOutRequestType,
                            Request = 0xDA,
                            Value = 0,
                            Index = 0,
                            Length = 0
                        };
            }

            return null;
        }