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); } }
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); } }
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(); }
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); }
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; } }
public UsbBlankGamepad(HidDevice device, string header, string dumpFileName) { VendorId = (short) device.VendorID; ProductId = (short) device.ProductID; _dumper = new DumpHelper(header, dumpFileName); }
internal DeviceOld(CorsairRootDevice root, HidDevice hidDevice) : base(root, hidDevice) { }
internal DeviceCommanderA(CorsairRootDevice root, HidDevice hidDevice) : base(root, hidDevice) { }
public PSDDevice(HidDevice hidDevice) { _hidDevice = hidDevice; }
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; }
internal void Init(HidDevice hidDevice, UsbRegistry registry) { _hidDevice = hidDevice; OpenDevice(registry); }
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(); }
/// <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; }
internal DeviceBootloader(CorsairRootDevice root, HidDevice hidDevice) : base(root, hidDevice) { }
/// <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; }
/// <summary> /// Closes the connection to the device. /// </summary> public void CloseDevice() { stream.Close(); device = null; connectedToDriver = false; }
internal BaseUSBDevice(CorsairRootDevice root, HidDevice hidDevice) : base(root) { this.hidDevice = hidDevice; }
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); }
/// <exclude/> protected HidStream(HidDevice device) : base(device) { ReadTimeout = 3000; WriteTimeout = 3000; }
public HidPulse(HidSharp.HidDevice device) { hid = device; }
internal void Init(HidDevice hidDevice, UsbRegistry registry) { _hidDevice = hidDevice; OpenDevice (registry); }