コード例 #1
0
        private SimPad getSimPadInstance(HidSharp.HidDevice device)
        {
            if (device.VendorID != vendorID)
            {
                return(null);
            }

            switch (device.ProductID)
            {
            case 0x0001:     // SimPad V2
                return(new SimPadV2(device));

            case 0x0002:     // SimPad V2Ex
                return(new SimPadV2Ex(device));

            case 0x0003:     // SimPad V2Lite
                return(new SimPadV2Lite(device));

            case 0x0004:     // SimPad Nano
                return(new SimPadNano(device));

            default:
                return(null);
            }
        }
コード例 #2
0
 public bool Send(byte[] bs)
 {
     if (stream == null)
     {
         return(false);
     }
     try
     {
         byte[] outb = new byte[atcdevice.MaxOutputReportLength];
         outb[0] = 0;//fix hiddriver
         Array.Copy(bs, 0, outb, 1, Math.Min(bs.Length, outb.Length - 1));
         stream.Write(outb);
         return(true);
     }
     catch (System.IO.IOException err)//io异常,断开
     {
         atcdevice = null;
         stream    = null;
         return(false);
     }
     catch (TimeoutException err)//超时异常,记录
     {
         writeErrorCount++;
         return(false);
     }
 }
コード例 #3
0
 public static void StartRead(Action <byte[]> onRead)
 {
     _onRead = onRead;
     System.Threading.Thread t = new System.Threading.Thread(() =>
     {
         while (_onRead != null)
         {
             if (stream != null)
             {
                 try
                 {
                     var buf = stream.Read();
                     _onRead(buf);
                 }
                 catch (System.IO.IOException err)//io异常,断开
                 {
                     atcdevice = null;
                     stream    = null;
                 }
                 catch (TimeoutException err)//超时异常,记录
                 {
                     readErrorCount++;
                 }
             }
         }
     });
     t.Start();
 }
コード例 #4
0
    public static int CheckDevice()
    {
        var devices     = loader.GetDevices(0x0483, 0x572b);
        var signerCount = devices.Count();

        if (devices.Count() == 0)//直接移除设备
        {
            atcdevice = null;
            stream    = null;
            return(0);
        }
        if (atcdevice == null)//打开设备
        {
            atcdevice = devices.First();
            stream    = atcdevice.Open();
            return(signerCount);
        }
        bool bFind = false;

        foreach (var d in devices)
        {
            if (d.DevicePath == atcdevice.DevicePath)
            {//same
                bFind = true;
            }
        }
        //找不到设备了
        if (!bFind)
        {
            atcdevice = null;
            stream    = null;
        }
        return(signerCount);
    }
コード例 #5
0
    public void Check()
    {
        var devices = loader.GetDevices(vid, pid);

        signerCount = devices.Count();
        if (devices.Count() == 0)//直接移除设备
        {
            atcdevice = null;
            stream    = null;
            return;
        }
        if (atcdevice == null)//打开设备
        {
            atcdevice = devices.First();
            stream    = atcdevice.Open();
            return;
        }
        bool bFind = false;

        foreach (var d in devices)
        {
            if (d.DevicePath == atcdevice.DevicePath)
            {//same
                bFind = true;
            }
        }
        //找不到设备了
        if (!bFind)
        {
            atcdevice = null;
            stream    = null;
        }
    }
コード例 #6
0
        public UsbBlankGamepad(HidDevice device, string header, string dumpFileName)
        {
            VendorId = (short) device.VendorID;
            ProductId = (short) device.ProductID;

            _dumper = new DumpHelper(header, dumpFileName);
        }
コード例 #7
0
 internal DeviceOld(CorsairRootDevice root, HidDevice hidDevice) : base(root, hidDevice) { }
コード例 #8
0
 internal DeviceCommanderA(CorsairRootDevice root, HidDevice hidDevice) : base(root, hidDevice) { }
コード例 #9
0
ファイル: PSDDevice.cs プロジェクト: mihver1/PSD
 public PSDDevice(HidDevice hidDevice)
 {
     _hidDevice = hidDevice;
 }
コード例 #10
0
        public override bool Open(string devicePath)
        {
            var loader = new HidDeviceLoader();

            // search for HID
            _currentHidDevice = loader.GetDevices(VendorId, ProductId).FirstOrDefault();

            if (_currentHidDevice == null)
            {
                Log.ErrorFormat("Couldn't find device with VID: {0}, PID: {1}",
                    VendorId, ProductId);
                return false;
            }

            // open HID
            if (!_currentHidDevice.TryOpen(out _currentHidStream))
            {
                Log.ErrorFormat("Couldn't open device {0}", _currentHidDevice);
                return false;
            }

            // since these devices have no MAC address, generate one
            DeviceAddress = PhysicalAddress.Parse(MacAddressGenerator.NewMacAddress);

            IsActive = true;
            Path = devicePath;

            return IsActive;
        }
コード例 #11
0
 internal void Init(HidDevice hidDevice, UsbRegistry registry)
 {
     _hidDevice = hidDevice;
     OpenDevice(registry);
 }
コード例 #12
0
    public void StartRead(Action <byte[]> onRead)
    {
        //用異步接口,不用開綫程
        byte[] buf = new byte[65];
        _onRead = onRead;
        System.Threading.Thread t = new System.Threading.Thread(() =>
        {
            while (_onRead != null)
            {
                System.Threading.Thread.Sleep(5);
                if (stream != null)
                {
                    //try
                    {
                        int read        = 0;
                        Action readlast = null;
                        readlast        = () =>
                        {
                            stream.BeginRead(buf, read, 65 - read, (a) =>
                            {
                                if (_onRead == null || stream == null)
                                {
                                    return;
                                }
                                int c = 0;
                                try
                                {
                                    c = stream.EndRead(a);
                                }
                                catch (System.IO.IOException err)//io异常,断开
                                {
                                    atcdevice = null;
                                    stream    = null;
                                    return;
                                }
                                catch (TimeoutException err)//超时异常,记录
                                {
                                    readErrorCount++;
                                }
                                read += c;
                                if (read < 65)
                                {
                                    readlast();
                                }
                                else
                                {
                                    _onRead(buf.Skip(1).ToArray());
                                    read = 0;

                                    readlast();
                                }
                            }, null);
                            while (true)
                            {
                                if (stream == null)
                                {
                                    break;
                                }
                                System.Threading.Thread.Sleep(5);
                            }
                        };


                        readlast();

                        //var buf = stream.Read();
                        //_onRead(buf);
                    }
                    //catch (System.IO.IOException err)//io异常,断开
                    //{
                    //    atcdevice = null;
                    //    stream = null;
                    //}
                    //catch (TimeoutException err)//超时异常,记录
                    //{
                    //    readErrorCount++;
                    //}
                }
            }
        });
        t.Start();
    }
コード例 #13
0
ファイル: DTSCard.cs プロジェクト: Heliflyer/helios
        /// <summary>
        /// Initializes communication with the DTS Card
        /// </summary>
        /// <returns>True if update is sucessful, false if there was a problem.</returns>
        public bool initialize()
        {
            if (_device == null) 
            {
                dispose();
            }

            HidDeviceLoader deviceLoader = new HidDeviceLoader();
            foreach (HidDevice device in deviceLoader.GetDevices(0x04d8, 0xf64e))
            {
                if (device.SerialNumber.Equals(SerialNumber))
                {
                    _device = device;
                    break;
                }
            }

            if (_device != null)
            {
                _device.TryOpen(out _stream);
            }

            return _stream != null;
        }
コード例 #14
0
 internal DeviceBootloader(CorsairRootDevice root, HidDevice hidDevice) : base(root, hidDevice) { }
コード例 #15
0
ファイル: BlinkStick.cs プロジェクト: hbre/BlinkStickDotNet
        /// <summary>
        /// Opens the device.
        /// </summary>
        /// <returns><c>true</c>, if device was opened, <c>false</c> otherwise.</returns>
        /// <param name="adevice">Pass the parameter of HidDevice to open it directly</param>
        public bool OpenDevice(HidDevice adevice)
        {
            if (adevice != null)
            {
                this.device = adevice;

                return OpenCurrentDevice();
            }

            return false;
        }
コード例 #16
0
ファイル: BlinkStick.cs プロジェクト: hbre/BlinkStickDotNet
 /// <summary>
 /// Closes the connection to the device.
 /// </summary>
 public void CloseDevice()
 {
     stream.Close();
     device = null;
     connectedToDriver = false;
 }
コード例 #17
0
 internal BaseUSBDevice(CorsairRootDevice root, HidDevice hidDevice)
     : base(root)
 {
     this.hidDevice = hidDevice;
 }
コード例 #18
0
 public bool TryGetHidDevice(out HidDevice device, int?vendorID = null, int?productID = null, int?releaseNumberBcd = null, string serialNumber = null)
 {
     device = GetHidDeviceOrNull(vendorID, productID, releaseNumberBcd, serialNumber);
     return(device != null);
 }
コード例 #19
0
 /// <exclude/>
 protected HidStream(HidDevice device)
     : base(device)
 {
     ReadTimeout  = 3000;
     WriteTimeout = 3000;
 }
コード例 #20
0
 public HidPulse(HidSharp.HidDevice device)
 {
     hid = device;
 }
コード例 #21
0
		internal void Init(HidDevice hidDevice, UsbRegistry registry)
        {
			_hidDevice = hidDevice;
			OpenDevice (registry);
        }