Example #1
0
        private static void DeviceChangeNotifierDeviceAttached(string devPath)
        {
            try
            {
                UsbHidDevice exist = hidDevList.First(x => string.Compare(x.DevicePath, devPath, true) == 0);
                DeviceChangeNotifierDeviceDetached(devPath);
            }
            catch
            {
            }
            UsbHidDevice hidDev = new UsbHidDevice();

            if (!string.IsNullOrWhiteSpace(devPath)) //第一次启动扫描
            {
                hidDev._deviceInformation.DevicePathName = devPath;
            }
            if (hidDev.Connect())
            {
                //hidDev._worker.RunWorkerAsync();
                hidDevList.Add(hidDev);
                //hidDev.readDataTh.Start();
                if (OnConnected != null)
                {
                    OnConnected(hidDev);
                }
            }
        }
Example #2
0
            private static void Main()
            {
                var devices = DeviceDiscovery.FindHidDevices(new SerialStringMatcher("aimforfs.eu:RMP"));
                var device  = new UsbHidDevice(devices[0].Key);

                var command = new USB.Classes.Messaging.CommandMessage(0x20, new byte[] {
                    16,
                    0, (1 << 0) + (1 << 3) + (1 << 6) + (1 << 7) + (1 << 4),
                    1, 0x0,
                    2, 0x0,
                    3, 1 << 1,
                        4, (1 << 0) + (1 << 2) + (1 << 3) + (1 << 4) + (1 << 6) + (1 << 7),
                        5, (1 << 3) + (1 << 5),
                        6, 0x0,
                        7, (1 << 0) + (1 << 2) + (1 << 4) + (1 << 5) + (1 << 7),
                        8, (1 << 4) + (1 << 3) + (1 << 5) + (1 << 6),
                        9, (1 << 0) + (1 << 1) + (1 << 4) + (1 << 3) + (1 << 5) + (1 << 7),
                        10, (1 << 0) + (1 << 1) + (1 << 4) + (1 << 3) + (1 << 5) + (1 << 7),
                        11, (1 << 4) + (1 << 3) + (1 << 5) + (1 << 6),
                        12, (1 << 0) + (1 << 2) + (1 << 4) + (1 << 5) + (1 << 7),
                        13, (1 << 0) + (1 << 3) + (1 << 6) + (1 << 7) + (1 << 4),
                        14, (1 << 3) + (1 << 5),
                        15, (1 << 0) + (1 << 2) + (1 << 3) + (1 << 4) + (1 << 6) + (1 << 7)
                }, device.OutputReportByteLength);

                device.SendMessage(command);

                System.Diagnostics.Debug.WriteLine(devices);
            }
Example #3
0
 public void FrmMainLoad()
 {
     Device = new UsbHidDevice(0x1234, 0x0021);
     Device.OnConnected += DeviceOnConnected;
     Device.OnDisConnected += DeviceOnDisConnected;
     Device.DataReceived += DeviceDataReceived;
     Device.Connect();
 }
Example #4
0
        public CanFocusButton()
        {
            AutoManageButton = true;

            device = new UsbHidDevice(0x0483, 0x0035);

            device.OnConnected += device_OnConnected;
            device.OnDisConnected += device_OnDisConnected;
            device.DataReceived += device_DataReceived;

            device.Connect();
        }
Example #5
0
 private static void DeviceChangeNotifierDeviceDetached(string devPath)
 {
     try
     {
         UsbHidDevice exist = hidDevList.First(x => string.Compare(x.DevicePath, devPath, true) == 0);
         if (OnDisConnected != null)
         {
             OnDisConnected(exist);
         }
         exist.Dispose();
         hidDevList.Remove(exist);
     }
     catch
     {
     }
 }
 private void USBInit()
 {
     t = new Timer(100);
     t.AutoReset = true;
     t.Elapsed += T_Elapsed;
     usb = new UsbHidDevice(USB_VENDOR_ID, USB_PRODUCT_ID);
     usb.OnConnected += Usb_OnConnected;
     usb.OnDisConnected += Usb_OnDisConnected;
     usb.DataReceived += Usb_DataReceived;
     usb.Connect();
     AddUSBHandler();
 }
Example #7
0
    void Start()
    {
        if (isrunning) return;

        hMainWindow = GetActiveWindow();
        newWndProc = new WndProcDelegate(WndProc);
        newWndProcPtr = Marshal.GetFunctionPointerForDelegate(newWndProc);
        oldWndProcPtr = SetWindowLong(hMainWindow, -4, newWndProcPtr);
        device = new UsbHidDevice(0x0483, 0x5750);
        device.DataReceived += DeviceDataReceived;
        print("device.Connect: " + device.Connect());
        isrunning = true;
    }