• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Main.UsbSetupPacket类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: Main

        /**
         * Finds all controllers, connects them to their own sockets, and sends input over those sockets.
         */
        public static void Main(string[] args)
        {
            ErrorCode ec = ErrorCode.None;
            controllers = getControllers();
            try
            {
                for (int i = 0; i < controllers.Length; i++)
                {
                    if (controllers[i] == null) break;
                    UsbDevice controller = controllers[i]; // already opened
                    IUsbDevice device = controller as IUsbDevice;
                    device.SetConfiguration(1);
                    device.ClaimInterface(0);

                    // setup this controller's socket
                    IPAddress ip = Dns.GetHostEntry("localhost").AddressList[1]; // won't always be list[1]
                    IPEndPoint ipe = new IPEndPoint(ip, ports[i]);
                    Socket s = new Socket(ipe.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
                    s.Connect(ipe);
                    sockets[i] = s;
                    Console.WriteLine("Socket " + i + " connected?: " + s.Connected);
                }

                while (true)
                {
                    for (int i = 0; i < controllers.Length; i++)
                    {
                        if (controllers[i] == null) break;
                        byte[] status_packet = new byte[49];
                        int len = 0;
                        UsbSetupPacket setup = new UsbSetupPacket(0xa1, 0x01, 0x0101, 0, 0x31); // magic values
                        controllers[i].ControlTransfer(ref setup, status_packet, 49, out len);

                        // send to UI
                        byte[] rearranged = rearrangeStatus(status_packet);
                        sockets[i].Send(rearranged, 12, 0);
                    }

                    Thread.Sleep(50);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine();
                Console.WriteLine((ec != ErrorCode.None ? ec + ":" : String.Empty) + ex.Message);
            }
            finally // cleanup
            {
                for(int i = 0; i < controllers.Length; i++){
                    if (controllers[i] != null)
                    {
                        UsbDevice controller = controllers[i];
                        if (controller != null && controller.IsOpen)
                        {
                            IUsbDevice device = controller as IUsbDevice;
                            device.ReleaseInterface(0);
                            controller.Close();
                        }
                    }
                }
                UsbDevice.Exit();
                Console.ReadKey();
            }
        }
开发者ID:RocHCI,项目名称:legion-gaming,代码行数:67,代码来源:Program.cs


示例17: GetConfiguration

        /// <summary>
        /// Gets the USB devices active configuration value. 
        /// </summary>
        /// <param name="config">The active configuration value. A zero value means the device is not configured and a non-zero value indicates the device is configured.</param>
        /// <returns>True on success.</returns>
        public virtual bool GetConfiguration(out byte config)
        {
            config = 0;
            byte[] buf = new byte[1];
            int uTransferLength;

            UsbSetupPacket setupPkt = new UsbSetupPacket();
            setupPkt.RequestType = (byte) UsbEndpointDirection.EndpointIn | (byte) UsbRequestType.TypeStandard |
                                   (byte) UsbRequestRecipient.RecipDevice;
            setupPkt.Request = (byte) UsbStandardRequest.GetConfiguration;
            setupPkt.Value = 0;
            setupPkt.Index = 0;
            setupPkt.Length = 1;

            bool bSuccess = ControlTransfer(ref setupPkt, buf, buf.Length, out uTransferLength);
            if (bSuccess && uTransferLength == 1)
            {
                config = buf[0];
                mCurrentConfigValue = config;
                return true;
            }
            UsbError.Error(ErrorCode.Win32Error, Marshal.GetLastWin32Error(), "GetConfiguration", this);
            return false;
        }
开发者ID:CharlesVerschuur,项目名称:LibUsbDotNet,代码行数:29,代码来源:UsbDevice.cs


示例18: ControlTransfer

        /// <summary>
        /// Transmits control data over a default control endpoint.
        /// </summary>
        /// <param name="setupPacket">An 8-byte setup packet which contains parameters for the control request. 
        /// See section 9.3 USB Device Requests of the Universal Serial Bus Specification Revision 2.0 for more information. </param>
        /// <param name="buffer">Data to be sent/received from the device.</param>
        /// <param name="bufferLength">Length of the buffer param.</param>
        /// <param name="lengthTransferred">Number of bytes sent or received (depends on the direction of the control transfer).</param>
        /// <returns>True on success.</returns>
        public virtual bool ControlTransfer(ref UsbSetupPacket setupPacket, object buffer, int bufferLength, out int lengthTransferred)
        {
            PinnedHandle pinned = new PinnedHandle(buffer);
            bool bSuccess = ControlTransfer(ref setupPacket, pinned.Handle, bufferLength, out lengthTransferred);
            pinned.Dispose();

            return bSuccess;
        }
开发者ID:CharlesVerschuur,项目名称:LibUsbDotNet,代码行数:17,代码来源:UsbDevice.cs


示例19: WriteFlashBlock

 public static void WriteFlashBlock(UInt16 address, Byte[] data)
 {
     UsbSetupPacket packet = new UsbSetupPacket((byte)UsbRequestType.TypeVendor | (byte)UsbRequestRecipient.RecipDevice | (byte)UsbEndpointDirection.EndpointOut, (byte)Request.WriteFlashBlock, (short)address, 0, (short)data.Length);
     int transfered;
     device.ControlTransfer(ref packet, data, data.Length, out transfered);
     if (transfered != data.Length)
         throw new CommunicationException("Error sending data to device");
 }
开发者ID:ejholmes,项目名称:openfocus,代码行数:8,代码来源:Bootloader.cs


示例20: softPWM_write

 /// <summary>
 /// Updates the values of softPWM modules
 /// </summary>
 /// <param name="ch1">Value of channel 1 - pin4</param>
 /// <param name="ch2">Value of channel 2 - pin1</param>
 /// <param name="ch3">Value of channel 3 - pin2</param>
 public void softPWM_write(byte ch1, byte ch2, byte ch3)
 {
     byte[] buffer_ = new byte[8];
     int whatIsThis = 8;
     MySetupPacket = new UsbSetupPacket(0xC0, 48, (short)((ch2 << 8) | ch1), ch3, 8);
     lwStatus = MyUsbDevice.ControlTransfer(ref MySetupPacket, buffer_, 8, out whatIsThis);
 }
开发者ID:ZmK,项目名称:Little-Wire,代码行数:13,代码来源:littleWire.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# LibZano.Frame类代码示例发布时间:2022-05-26
下一篇:
C# LibUsbDotNet.UsbDevice类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap