private void SendAttachEvent() { try { GnpPacket packet = GnProtocol.GnpCommands.GnpDeviceAttachEvent; packet.DestinationAddress = targetGnpAddress; gnProtocolHandler.SendGnProtocolPacket(packet); } catch (Exception) { //Logger.Write($"SendAttachEvent Error: {ex.Message} {ex.StackTrace}"); } }
internal TelephonyDevice(IUsbHidDevice usbDevice) { this.usbDevice = usbDevice; deviceLockObject = new object(); eventLockObject = new object(); try { lock (deviceLockObject) { /* */ // Select the top-level collection to use topLevelCollection = usbDevice.TopLevelCollections.FirstOrDefault(x => x.MainUsagePage == UsagePages.USAGE_PAGE_GN_PROTOCOL); if (topLevelCollection == null) { throw new ArgumentException("The HID device has no telephony support"); } buttonTopLevelCollection = usbDevice.TopLevelCollections.FirstOrDefault(x => x.MainUsagePage == UsagePages.USAGE_PAGE_BUTTON); if (buttonTopLevelCollection == null) { throw new ArgumentException("The HID device has no Button support"); } /* */ gnProtocolHandler = new GnProtocolOverUsbHid.GnProtocolOverUsbHid(usbDevice); buttonTopLevelCollection.Open(); // Add device event listeners topLevelCollection.ButtonInputReceived += OnButtonInputReceived; buttonTopLevelCollection.ButtonInputReceived += OnButtonInputReceived; if (usbDevice.HasGnProtocolSupport) { // Send a GNP_DEVICE_ATTACH_EVENT GN protocol event to the device in order to subscribe to // GN protocol events from the device. SendAttachEvent(); } #region Define custom buttons 1 and 2 - not 0 GNP_CONFIG_BUTTON_FUNCTION 0x27 // if (ContainsValidPid(usbDevice.ProductId)) { var gnpPacket = new GnpPacket { DestinationAddress = targetGnpAddress, Type = GnpPacket.PacketType.Write, Command = GnpCommands.CONFIG, Data = new byte[] { 0x27, 0x01, 0x00, 0x00 } }; gnProtocolHandler.SendGnProtocolPacket(gnpPacket); gnpPacket = new GnpPacket { DestinationAddress = targetGnpAddress, Type = GnpPacket.PacketType.Write, Command = GnpCommands.CONFIG, Data = new byte[] { 0x27, 0x01, 0x01, 0x00 } }; gnProtocolHandler.SendGnProtocolPacket(gnpPacket); gnpPacket = new GnpPacket { DestinationAddress = targetGnpAddress, Type = GnpPacket.PacketType.Write, Command = GnpCommands.CONFIG, Data = new byte[] { 0x27, 0x01, 0x02, 0x0D } }; gnProtocolHandler.SendGnProtocolPacket(gnpPacket); /* * var gnpPacket = new GnpPacket * { * DestinationAddress = targetGnpAddress, * Type = GnpPacket.PacketType.Write, * Command = GnpCommands.CONFIG, * Data = new byte[] { 0x27, 0x02, 0x01, 0x00 } * }; * gnProtocolHandler.SendGnProtocolPacket(gnpPacket); * * gnpPacket = new GnpPacket * { * DestinationAddress = targetGnpAddress, * Type = GnpPacket.PacketType.Write, * Command = GnpCommands.CONFIG, * Data = new byte[] { 0x27, 0x02, 0x00, 0x00 } * }; * gnProtocolHandler.SendGnProtocolPacket(gnpPacket); * * gnpPacket = new GnpPacket * { * DestinationAddress = targetGnpAddress, * Type = GnpPacket.PacketType.Write, * Command = GnpCommands.CONFIG, * Data = new byte[] { 0x27, 0x02, 0x02, 0x0E } * }; * gnProtocolHandler.SendGnProtocolPacket(gnpPacket); */ } #endregion } } catch (Exception) { // Ignore exceptions //Logger.Write($"Error on the Device init: {e.Message} {e.StackTrace}"); // this.Dispose(); } }