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


C# Main.UsbSetupPacket类代码示例

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


UsbSetupPacket类属于LibUsbDotNet.Main命名空间,在下文中一共展示了UsbSetupPacket类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TurnOffLight

 public bool TurnOffLight(LightColour colour)
 {
     var modifiedColour = (short)colour * 0x100;
     var packet = new UsbSetupPacket(0x48, 0x12, (short)0x0c0a, (short)modifiedColour, (short)0x0000);
     int temp2;
     return MyUsbDevice.ControlTransfer(ref packet, new byte[0], 0, out temp2);
 }
开发者ID:perkof,项目名称:LibUsbDotNet-Delcom804002_BDriver,代码行数:7,代码来源:LightDevice.cs

示例2: analogRead

 /// <summary>
 /// Read analog voltage from a spesific channel
 /// </summary>
 /// <param name="channel">0 for RESET pin, 1 for SCK pin, 2 for internal Temperature sensor</param>
 /// <returns>Analog voltage in 10bit resoultion</returns>
 public ushort analogRead(byte channel)
 {
     byte[] buffer_ = new byte[8];
     int whatIsThis = 8;
     MySetupPacket = new UsbSetupPacket(0xC0, 15, channel, 0, 8);
     MyUsbDevice.ControlTransfer(ref MySetupPacket, buffer_, 8, out whatIsThis);
     return (ushort)((buffer_[1] <<8) + (buffer_[0]));
 }
开发者ID:beckettman,项目名称:Little-Wire,代码行数:13,代码来源:littleWire.cs

示例3: ControlTransfer

 public override bool ControlTransfer(SafeHandle InterfaceHandle,
                                      UsbSetupPacket SetupPacket,
                                      IntPtr Buffer,
                                      int BufferLength,
                                      out int LengthTransferred)
 {
     return WinUsb_ControlTransfer(InterfaceHandle, SetupPacket, Buffer, BufferLength, out LengthTransferred, IntPtr.Zero);
 }
开发者ID:CharlesVerschuur,项目名称:LibUsbDotNet,代码行数:8,代码来源:WinUsbAPI.cs

示例4: GetInitStatus

        /// <summary>
        /// Always returns 0x22 (34) so far
        /// </summary>
        /// <returns></returns>
        public ushort GetInitStatus()
        {
            UsbSetupPacket setup = new UsbSetupPacket(0xC0, 0x10, 0x0, 0x0, 0x1);
            int len = 0;

            byte[] buf = new byte[1];
            MyUsbDevice.ControlTransfer(ref setup, buf, (ushort)buf.Length, out len);

            return buf[0];
        }
开发者ID:Jerdak,项目名称:meshlab,代码行数:14,代码来源:KinectMotor.cs

示例5: SetTilt

        public void SetTilt(sbyte tiltValue)
        {
            if (!MyUsbDevice.IsOpen)
            {
                InitDevice();
            }
            ushort mappedValue = (ushort)(0xff00 | (byte)tiltValue);

            UsbSetupPacket setup = new UsbSetupPacket(0x40, 0x31, mappedValue, 0x0, 0x0);
            int len = 0;
            MyUsbDevice.ControlTransfer(ref setup, IntPtr.Zero, 0, out len);
        }
开发者ID:Jerdak,项目名称:meshlab,代码行数:12,代码来源:KinectMotor.cs

示例6: ControlTransfer

 public override bool ControlTransfer(SafeHandle interfaceHandle,
                                      UsbSetupPacket setupPacket,
                                      IntPtr buffer,
                                      int bufferLength,
                                      out int lengthTransferred)
 {
     return LibUsbDriverIO.ControlTransfer(interfaceHandle,
                                           setupPacket,
                                           buffer,
                                           bufferLength,
                                           out lengthTransferred,
                                           UsbConstants.DEFAULT_TIMEOUT);
 }
开发者ID:arvydas,项目名称:BlinkStickDotNet,代码行数:13,代码来源:LibUsbAPI.cs

示例7: GetFeature

        public unsafe override void GetFeature(byte[] buffer, int offset, int count)
        {
            Throw.If.OutOfRange(buffer, offset, count);
			
			try
			{
				UsbSetupPacket packet = new UsbSetupPacket (0x80 | 0x20, buffer[offset], (short)0x1, 0, 33);

				int transferred;

				_device.ControlTransfer (ref packet, buffer, count, out transferred);
			}
			finally
			{
			}
        }
开发者ID:arvydas,项目名称:BlinkStickDotNet,代码行数:16,代码来源:LibusbHidStream.cs

示例8: 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

示例9: SetFnKeyMode

        private static void SetFnKeyMode(FnKeyMode mode)
        {
            UsbDevice keyboard = null;

            try
            {
                keyboard = UsbDevice.OpenUsbDevice(new UsbDeviceFinder(0x046d, 0xc31f));

                if (keyboard == null)
                {
                    throw new KeyboardNotFoundException("Could not find Logitech K290 device. It's not connected or libusb-win32 is not installed.");
                }

                var setupPacket = new UsbSetupPacket(0x40, 2, 0x001a, (short)mode, 0);
                int sentBytesCount;

                if (keyboard.ControlTransfer(ref setupPacket, null, 0, out sentBytesCount) == false)
                {
                    throw new ApplicationException(
                        string.Format(
                            "Error transferring control data to the device. Code: {0}. Message: {1}.",
                            UsbDevice.LastErrorNumber,
                            UsbDevice.LastErrorString));
                }
            }
            catch
            {
                throw;
            }
            finally
            {
                if (keyboard != null)
                {
                    keyboard.Close();
                }

                UsbDevice.Exit();
            }
        }
开发者ID:GrzegorzKozub,项目名称:LogitechK290FnKeySwap,代码行数:39,代码来源:KeyboardService.cs

示例10: timer1_Tick

		private void timer1_Tick(object sender, EventArgs e)
		{
			//double t = (ti++)/1000.0;
			//plotter.AddData(2);

			if (_usbDevice != null)
			{
				s.Restart();
				UsbSetupPacket setup = new UsbSetupPacket((byte)(UsbCtrlFlags.RequestType_Vendor | UsbCtrlFlags.Recipient_Device | UsbCtrlFlags.Direction_In), (byte)OUSBRequest.ReadADCBuffer, 0, 0, 0);
				int length;
				if (!_usbDevice.ControlTransfer(ref setup, buffer, buffer.Length, out length))
					usbDisconnected();
				else if (length >= 2)
				{
					double time = (double)BitConverter.ToInt16(buffer, 0) / 250000.0;
					if (plotter.SampleTime == 0) 
						plotter.SampleTime = time;
					else
						plotter.SampleTime = (plotter.SampleTime*19 + time)/20;

					//int time = BitConverter.ToInt16(buffer, 0);
					//lblOut.Text = time.ToString();
					//plotter.AddData(time);

					for (int i = 2; i<length; i += 2)
					{
						double adc = BitConverter.ToInt16(buffer, i) * 5.0 / 1024.0;
						plotter.AddData(adc);
					}
				}

				s.Stop();
				double elapsed = s.ElapsedTicks * 1000.0 / Stopwatch.Frequency;
				lblOut.Text = plotter.SampleTime.ToString();
			}
		}
开发者ID:pouria007,项目名称:avroscope,代码行数:36,代码来源:MainForm.cs

示例11: OnControlRequestReceived

        public void OnControlRequestReceived(ControlRequestEventArgs e)
        {
            if ((e.bmRequestType == 0x80) && (e.bRequest == 0x06))
              {
            //Descriptor request, let the other event handle it
              }
              else if ((e.bmRequestType == 0x00) && (e.bRequest == 0x05))
              {
            //Let the library handle it, needs it to set the address in the Teensy
              }
              else if ((e.bmRequestType == 0x00) && (e.bRequest == 0x09))
              {
            //Let the library handle it, needs it to configure the endpoints in the Teensy
              }
              else
              {
            //Issue the request to the real device, and return whatever it did
            var setup = new UsbSetupPacket((byte)e.bmRequestType, (byte)e.bRequest,
              (short)e.wValue, (short)e.wIndex, (short)e.wLength);
            int transferred;

            if ((e.bmRequestType & 0x80) > 0)
            {
              var ret = new byte[e.wLength];
              _forwardee.ControlTransfer(ref setup, ret, ret.Length, out transferred);
              e.ReturnData = new byte[transferred];
              Array.Copy(ret, 0, e.ReturnData, 0, e.ReturnData.Length);
            }
            else
            {
              _forwardee.ControlTransfer(ref setup, e.AttachedData, e.AttachedData.Length, out transferred);
            }

            e.Ignore = false;
              }
        }
开发者ID:joshuabenuck,项目名称:USBSimulator,代码行数:36,代码来源:DeviceForwarder.cs

示例12: SendCommand

    /// <summary>
    /// Sends command to uDMX
    /// </summary>
    /// <returns><c>true</c>, if command was sent, <c>false</c> otherwise.</returns>
    /// <param name="command">Command.</param>
    /// <param name="cvalue">Cvalue.</param>
    /// <param name="cindex">Cindex.</param>
    /// <param name="buffer">Buffer.</param>
    private bool SendCommand(Command command, short cvalue, short cindex, byte[] buffer)
    {
        bool result = false;
        int transfered;

        UsbSetupPacket packet = new UsbSetupPacket ();
        // This is alegedly ignored by the uDMX, but let's play nice
        packet.RequestType = (byte)UsbRequestType.TypeVendor | (byte)UsbRequestRecipient.RecipDevice | (byte)UsbEndpointDirection.EndpointOut;
        packet.Request = (byte)command;
        packet.Value = cvalue;
        packet.Index = cindex;
        packet.Length = cvalue;

        // create empty buffer if the buffer is null
        if (buffer == null)
          buffer = new byte[0];

        // Send data and get the result
        if (_device.ControlTransfer (ref packet, buffer, buffer.Length, out transfered))
        {
          result = true;
        }

        return result;
    }
开发者ID:Matt-17,项目名称:uDMX,代码行数:33,代码来源:uDMX.cs

示例13: ReadEepromBlock

        public static Byte[] ReadEepromBlock(UInt16 address, int length)
        {
            Byte[] data = new Byte[length];

            UsbSetupPacket packet = new UsbSetupPacket((byte)UsbRequestType.TypeVendor | (byte)UsbRequestRecipient.RecipDevice | (byte)UsbEndpointDirection.EndpointIn, (byte)Request.ReadEepromBlock, (short)address, 0, (short)data.Length);
            int transfered;
            device.ControlTransfer(ref packet, data, data.Length, out transfered);

            return data;
        }
开发者ID:ejholmes,项目名称:openfocus,代码行数:10,代码来源:Bootloader.cs

示例14: Reboot

        public static void Reboot()
        {
            UsbSetupPacket packet = new UsbSetupPacket((byte)UsbRequestType.TypeVendor | (byte)UsbRequestRecipient.RecipDevice | (byte)UsbEndpointDirection.EndpointOut, (byte)Request.Reboot, 0, 0, 0);
            int transfered;
            object buffer = null;
            device.ControlTransfer(ref packet, buffer, 0, out transfered);

            Disconnect();
        }
开发者ID:ejholmes,项目名称:openfocus,代码行数:9,代码来源:Bootloader.cs

示例15: GetReport

        private static Byte[] GetReport()
        {
            int expected = 8;
            Byte[] data = new Byte[expected];
            UsbSetupPacket packet = new UsbSetupPacket((byte)UsbRequestType.TypeVendor | (byte)UsbRequestRecipient.RecipDevice | (byte)UsbEndpointDirection.EndpointIn, (byte)Request.GetReport, 0, 0, 0);
            int transfered;
            device.ControlTransfer(ref packet, data, data.Length, out transfered);

            return data;
        }
开发者ID:ejholmes,项目名称:openfocus,代码行数:10,代码来源:Bootloader.cs


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