当前位置: 首页>>代码示例>>C#>>正文


C# UsbDevice.ControlTransfer方法代码示例

本文整理汇总了C#中LibUsbDotNet.UsbDevice.ControlTransfer方法的典型用法代码示例。如果您正苦于以下问题:C# UsbDevice.ControlTransfer方法的具体用法?C# UsbDevice.ControlTransfer怎么用?C# UsbDevice.ControlTransfer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LibUsbDotNet.UsbDevice的用法示例。


在下文中一共展示了UsbDevice.ControlTransfer方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: checkProtocol

        public static Boolean checkProtocol(UsbDevice device)
        {
            Boolean r = false;

            string message = "";
            short messageLength = 2;

            UsbSetupPacket setupPacket = new UsbSetupPacket();
            setupPacket.RequestType = (byte)((byte)UsbConstants.USB_DIR_IN | (byte) UsbConstants.USB_TYPE_VENDOR);
            setupPacket.Request = (byte)ACCESSORY_GET_PROTOCOL;
            setupPacket.Value = 0;
            setupPacket.Index = 0;
            setupPacket.Length = 0;

            int resultTransferred;

            r = device.ControlTransfer(ref setupPacket, message, messageLength, out resultTransferred);

            return r;
        }
开发者ID:clover,项目名称:remote-pay-windows,代码行数:20,代码来源:MiniInitializer.cs

示例2: Bench_SetTestType

        /// <summary>
        /// Sends the control request to set the test mode
        /// </summary>
        private static int Bench_SetTestType(UsbDevice dev, BENCHMARK_DEVICE_TEST_TYPE testType, int intf)
        {
            int transferred;
            byte[] dataBuffer = new byte[1];
            UsbSetupPacket setTestTypePacket =
                new UsbSetupPacket((byte) (UsbCtrlFlags.Direction_In | UsbCtrlFlags.Recipient_Device | UsbCtrlFlags.RequestType_Vendor),
                                   (byte)BENCHMARK_DEVICE_COMMANDS.SET_TEST,
                                   (short) testType,
                                   (short) intf,
                                   1);

            bool success = dev.ControlTransfer(ref setTestTypePacket, dataBuffer, dataBuffer.Length, out transferred);
            if (!success) return -1;

            return transferred;
        }
开发者ID:siegelpeter,项目名称:UAV-NET,代码行数:19,代码来源:BenchmarkConsole.cs

示例3: GetTestType

        public static bool GetTestType(UsbDevice usbTestDevice, out UsbTestType usbTestType, byte interfaceID)
        {
            if (ReferenceEquals(usbTestDevice, null))
                throw new UsbTestDeviceException("UsbTestDevice must be set before invoking this member!");

            int lengthTransferred;
            byte[] buf = new byte[1];

            UsbSetupPacket cmd = UsbCmdGetTestType;
            cmd.Index = interfaceID;

            bool bSuccess = usbTestDevice.ControlTransfer(ref cmd, buf, buf.Length, out lengthTransferred);

            if (bSuccess && lengthTransferred == 1)
            {
                usbTestType = (UsbTestType) buf[0];
                return true;
            }
            usbTestType = UsbTestType.Invalid;
            return false;
        }
开发者ID:CoreCompat,项目名称:LibUsbDotNet,代码行数:21,代码来源:PicUsbTestDevice.cs

示例4: WriteEEDATA

        public static bool WriteEEDATA(UsbDevice usbTestDevice, byte address, byte value)
        {
            if (ReferenceEquals(usbTestDevice, null))
                throw new UsbTestDeviceException("UsbTestDevice must be set before invoking this member!");

            int lengthTransferred;
            byte[] buf = new byte[1];

            UsbSetupPacket cmd = UsbCmdReadEEDATA;
            cmd.Value = address;
            cmd.Index = value;
            bool bSuccess = usbTestDevice.ControlTransfer(ref cmd, buf, buf.Length, out lengthTransferred);

            return bSuccess && lengthTransferred == 1;
        }
开发者ID:CoreCompat,项目名称:LibUsbDotNet,代码行数:15,代码来源:PicUsbTestDevice.cs

示例5: SetTestType

        public static bool SetTestType(UsbDevice usbTestDevice, UsbTestType usbTestType, bool bCheck, byte interfaceID)
        {
            if (ReferenceEquals(usbTestDevice, null))
                throw new UsbTestDeviceException("UsbTestDevice must be set before invoking this member!");

            if (bCheck)
            {
                UsbTestType bCurrentTestType;
                if (GetTestType(usbTestDevice, out bCurrentTestType, interfaceID))
                {
                    if (bCurrentTestType == usbTestType) return true;
                }
                else
                    return false;
            }
            int lengthTransferred;
            byte[] buf = new byte[1];

            UsbSetupPacket cmd = UsbCmdSetTestType;
            cmd.Value = (short) usbTestType;
            cmd.Index = interfaceID;

            bool bSuccess = usbTestDevice.ControlTransfer(ref cmd, buf, buf.Length, out lengthTransferred);

            return bSuccess && lengthTransferred == 1;
        }
开发者ID:CoreCompat,项目名称:LibUsbDotNet,代码行数:26,代码来源:PicUsbTestDevice.cs

示例6: sendControlMessage

        public static Boolean sendControlMessage(UsbDevice device, byte requestCode, short index, string message)
        {
            Boolean r = false;

            short messageLength = 0;

            if (message != null)
            {
                messageLength = (short)(message.Length);
            }

            UsbSetupPacket setupPacket = new UsbSetupPacket();
            setupPacket.RequestType = (byte)((byte)UsbConstants.USB_DIR_OUT | (byte)UsbConstants.USB_TYPE_VENDOR);

            setupPacket.Request = requestCode; // byte
            setupPacket.Value = 0;
            setupPacket.Index = index; // short
            setupPacket.Length = messageLength; // short

            int resultTransferred;
            Console.WriteLine("RequestType:" + setupPacket.RequestType);
            Console.WriteLine("setupPacket.Request:" + setupPacket.Request);
            Console.WriteLine("setupPacket.Value:" + setupPacket.Value);
            Console.WriteLine("setupPacket.Index:" + setupPacket.Index);
            Console.WriteLine("setupPacket.Length:" + setupPacket.Length);

            Console.WriteLine("message:" + message);

            byte[] messageBytes = null;
            if (null != message)
            {
                messageBytes = Encoding.UTF8.GetBytes(message);
            }

            r = device.ControlTransfer(ref setupPacket, messageBytes, messageLength, out resultTransferred);

            return r;
        }
开发者ID:clover,项目名称:remote-pay-windows,代码行数:38,代码来源:MiniInitializer.cs

示例7: Main

        static void Main(string[] args)
        {
            ErrorCode errorCode = ErrorCode.None;

            try
            {
                UsbRegDeviceList regList = UsbDevice.AllDevices.FindAll(MyUsbFinder);
                MyUsbDevice = UsbDevice.OpenUsbDevice(MyUsbFinder);

                // If the device is open and ready
                if (MyUsbDevice == null) throw new Exception("Device Not Found.");

                IUsbDevice wholeUsbDevice = MyUsbDevice as IUsbDevice;
                if (!ReferenceEquals(wholeUsbDevice, null))
                {
                    // This is a "whole" USB device. Before it can be used,
                    // the desired configuration and interface must be selected.

                    // Select config #1
                    wholeUsbDevice.SetConfiguration(1);

                    // Claim interface #0.
                    wholeUsbDevice.ClaimInterface(0);
                }

                UsbSetupPacket packet = new UsbSetupPacket(
                    (byte)(UsbCtrlFlags.Direction_In | UsbCtrlFlags.Recipient_Device | UsbCtrlFlags.RequestType_Vendor),
                    (byte)0x12,
                    (short)0xc8,
                    (0x02 * 0x100) + 0x0a,
                    0);
                var buffer = new byte[] { 0x65, 0x0C, 0x02, 0xFF, 0x00, 0x00, 0x00, 0x00 };

                UsbInterfaceInfo usbInterfaceInfo = null;
                UsbEndpointInfo usbEndpointInfo = null;
                byte recipient = (byte)UsbRequestType.TypeVendor;
                var rubyPacket = new UsbSetupPacket(recipient, 0x0A, (byte)0x0c, 0x04, 0x01);

               // UsbEndpointBase.LookupEndpointInfo(MyUsbDevice.Configs[0], MyUsbDevice.ActiveEndpoints[0].EndpointInfo,
                 //                                  out usbInterfaceInfo, out usbEndpointInfo);
                int temp3;
                var RubyTransfer = MyUsbDevice.ControlTransfer(ref rubyPacket, null, 0, out temp3);
                // 0x21, 0x09, 0x0635, 0x000, "\x65\x0C#{data}\xFF\x00\x00\x00\x00", 0

                //int temp1;
                //var result1 = MyUsbDevice.ControlTransfer(ref packet, new byte[2], 8, out temp1);

                //packet = new UsbSetupPacket((byte)UsbRequestType.TypeVendor, (byte)0x12, (short)0x0C0A, (short)0x0200, 0x000);
                //int temp2;
                //var result2 = MyUsbDevice.ControlTransfer(ref packet, null, 0, out temp2);

                Console.WriteLine(string.Format("Result 1 : {0} - Length: {1}", RubyTransfer, temp3));
                //Console.WriteLine(string.Format("Result 2 : {0}", result2));

                //usb_control_msg(led->udev,
                //      usb_sndctrlpipe(led->udev, 0),
                //      0x12,
                //      0xc8,
                //      (0x02 * 0x100) + 0x0a,
                //      (0x00 * 0x100) + color,
                //      buffer,
                //      8,
                //      2 * HZ);

                // Then turn the LED on
                //Packet.Recipient = 8;
                //Packet.DeviceModel = 18;
                //Packet.Length = 0;
                //Packet.MajorCmd = 10;
                //Packet.MinorCmd = 12;
                ////switch (Color)
                ////{
                ////    case GREENLED: Packet.DataLSB = 1; break;
                ////    case REDLED: Packet.DataLSB = 2; break;
                ////    case BLUELED: Packet.DataLSB = 4; break;
                ////}
                //Packet.DataLSB = 4; // blue
                //Packet.DataMSB = 0;

            } catch(Exception e)
            {
                Console.WriteLine(e.Message);
            } finally
            {
                if (MyUsbDevice != null)
                {
                    if(endpointReader != null)
                        endpointReader.Abort();
                    if (MyUsbDevice.IsOpen)
                    {
                        // If this is a "whole" usb device (libusb-win32, linux libusb-1.0)
                        // it exposes an IUsbDevice interface. If not (WinUSB) the
                        // 'wholeUsbDevice' variable will be null indicating this is
                        // an interface of a device; it does not require or support
                        // configuration and interface selection.
                        IUsbDevice wholeUsbDevice = MyUsbDevice as IUsbDevice;
                        if (!ReferenceEquals(wholeUsbDevice, null))
                        {
                            // Release interface #0.
                            wholeUsbDevice.ReleaseInterface(0);
//.........这里部分代码省略.........
开发者ID:cprieto,项目名称:usblamp,代码行数:101,代码来源:Program.cs


注:本文中的LibUsbDotNet.UsbDevice.ControlTransfer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。