private void Device_InputReportReceived(HidDevice sender, HidInputReportReceivedEventArgs args) { var data = args.Report.Data.ToArray(); var report = data[0]; if (report == 2 /* Scanned data */) { byte length = data[1]; int symbology = (data[2] << 16) | (data[3] << 8) | data[4]; byte continuation = data[63]; //var barcodeData = new byte[length]; //Array.Copy(data, 5, barcodeData, 0, length); //var sData = Encoding.ASCII.GetString(barcodeData); //Console.WriteLine($"Symbology: \t{symbology:x6}\r\nData:\t\t{sData}\r\n"); Buffer.Write(data, 5, length); if (continuation == 0) { var sData = Encoding.ASCII.GetString(Buffer.ToArray()); Console.WriteLine($"Symbology: \t{symbology:x6}\r\nData:\t\t{sData}\r\n"); Buffer.SetLength(0); } } var sb = new StringBuilder(); for (int i = 0; i < 54; i++) { sb.Append(i.ToString("00")); sb.Append(" "); } sb.AppendLine(); foreach (var d in data) { sb.Append(d.ToString("x2")); sb.Append(" "); } sb.AppendLine(); foreach (var d in data) { sb.Append(" "); char l = (char)d; if (char.IsLetterOrDigit(l)) { sb.Append(l); } else { sb.Append("."); } sb.Append(" "); } sb.AppendLine(); Console.WriteLine(sb.ToString()); }
private void inputReportReceived(Windows.Devices.HumanInterfaceDevice.HidDevice sender, HidInputReportReceivedEventArgs args) { QinetiQ.WindowsIOT.HidDevices.GameController.GameControllerValues Output = new QinetiQ.WindowsIOT.HidDevices.GameController.GameControllerValues(); long leftStickX = args.Report.GetNumericControl(0x01, 0x30).Value; long leftStickY = args.Report.GetNumericControl(0x01, 0x31).Value; Output.LeftStick.SetPosition(leftStickX, leftStickY); Output.Rudder = args.Report.GetNumericControl(0x01, 0x32).Value; long rightStickX = args.Report.GetNumericControl(0x01, 0x33).Value; long rightStickY = args.Report.GetNumericControl(0x01, 0x34).Value; Output.RightStick.SetPosition(rightStickX, rightStickY); Output.DPadDirection = (Directions)args.Report.GetNumericControl(0x01, 0x39).Value; Output.ButtonAPressed = args.Report.GetBooleanControl(0x09, 0x01).IsActive; Output.ButtonBPressed = args.Report.GetBooleanControl(0x09, 0x02).IsActive; Output.ButtonXPressed = args.Report.GetBooleanControl(0x09, 0x03).IsActive; Output.ButtonYPressed = args.Report.GetBooleanControl(0x09, 0x04).IsActive; Output.ButtonLBPressed = args.Report.GetBooleanControl(0x09, 0x05).IsActive; Output.ButtonRBPressed = args.Report.GetBooleanControl(0x09, 0x06).IsActive; Output.ButtonBackPressed = args.Report.GetBooleanControl(0x09, 0x07).IsActive; Output.ButtonStartPressed = args.Report.GetBooleanControl(0x09, 0x08).IsActive; Output.ButtonLeftStickPressed = args.Report.GetBooleanControl(0x09, 0x09).IsActive; Output.ButtonRightStickPressed = args.Report.GetBooleanControl(0x09, 0x0A).IsActive; InputReceived(this, Output); }
private void GetHidReport(HidInputReportReceivedEventArgs args) { // For now there is only one data type HidInputReport rpt = args.Report; IBuffer buff = rpt.Data; DataReader dr = DataReader.FromBuffer(buff); byte[] bytes = new byte[rpt.Data.Length]; dr.ReadBytes(bytes); Motus_1_RawDataPacket packet = new Motus_1_RawDataPacket(); try { // Have to remove a bonus byte on the payload byte[] parsed = new byte[bytes.Length - 1]; for (int i = 0; i < parsed.Length; i++) { parsed[i] = bytes[i + 1]; } packet.Serialize(parsed); byte[] stream = new byte[packet.ExpectedLen + DataPacket.NumOverHeadBytes]; packet.SerializeToStream(stream, 0); SetData(stream); } catch (ArgumentException e0) { LogMessage(e0.Message + e0.StackTrace); } catch (IndexOutOfRangeException e1) { LogMessage(e1.Message + e1.StackTrace); } }
void OnGazeReportReceived(HidDevice sender, HidInputReportReceivedEventArgs args) { var report = args.Report; Debug.Assert(report.Id == HID_USAGE_TRACKING_DATA); HidNumericControl num; num = report.GetNumericControl(HID_USAGE_PAGE_EYE_HEAD_TRACKER, HID_USAGE_TIMESTAMP); var timestamp = (int)num.Value; // TODO This needs to be pulled from the proper collection num = report.GetNumericControl(HID_USAGE_PAGE_EYE_HEAD_TRACKER, HID_USAGE_POSITION_X); var x = num.Value; num = report.GetNumericControl(HID_USAGE_PAGE_EYE_HEAD_TRACKER, HID_USAGE_POSITION_Y); var y = num.Value; var gazeData = new GazeData { Timestamp = timestamp, X = x, Y = y }; var ignored = Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { HandleGazeData(gazeData); }); }
/// <summary> /// This callback only increments the total number of events received and prints it /// /// This method is called whenever the device's state changes and sends a report. Since all input reports share the same event in /// HidDevice, the app needs to get the HidInputReport from eventArgs.Report and compare report ids and usages with the desired /// report. /// </summary> /// <param name="sender">HidDevice that the event is being raised from</param> /// <param name="eventArgs">Contains the HidInputReport that caused the event to raise</param> private async void OnInputReportEvent(HidDevice sender, HidInputReportReceivedEventArgs eventArgs) { // If we navigated away from this page, we don't need to process this event // This also prevents output from spilling into another page if (!navigatedAway) { numInputReportEventsReceived++; // The data from the InputReport HidInputReport inputReport = eventArgs.Report; IBuffer buffer = inputReport.Data; totalNumberBytesReceived += buffer.Length; // Create a DispatchedHandler for the because we are interracting with the UI directly and the // thread that this function is running on may not be the UI thread; if a non-UI thread modifies // the UI, an exception is thrown await rootPage.Dispatcher.RunAsync( CoreDispatcherPriority.Normal, new DispatchedHandler(() => { // If we navigated away from this page, do not print anything. The dispatch may be handled after // we move to a different page. if (!navigatedAway) { rootPage.NotifyUser( "Total number of input report events received: " + numInputReportEventsReceived.ToString() + "\nTotal number of bytes received: " + totalNumberBytesReceived.ToString(), NotifyType.StatusMessage); } })); } }
private void Device_InputReportReceived(HidDevice sender, HidInputReportReceivedEventArgs args) { HidInputReport report = args.Report; IBuffer buffer = report.Data; int ms = DateTime.Now.Subtract(now).Milliseconds; Debug.WriteLine("RX - {0} bytes received in {1}ms.", buffer.Length, ms); Debug.WriteLine(BitConverter.ToString(report.Data.ToArray())); }
/// <summary> /// Handler for processing/filtering input from the controller /// </summary> /// <param name="sender">HidDevice handle to the controller</param> /// <param name="args">InputReport received from the controller</param> private void inputReportReceived(HidDevice sender, HidInputReportReceivedEventArgs args) { int dPad = (int)args.Report.GetNumericControl(0x01, 0x39).Value; ControllerDpadDirection dpadDirection = (ControllerDpadDirection)dPad; // see http://sviluppomobile.blogspot.com/2013/11/hid-communication-for-windows-81-store.html // Adjust X/Y so (0,0) is neutral position // sticks - left and right: int _leftStickX = (int)(args.Report.GetNumericControl(0x01, 0x30).Value); int _leftStickY = (int)(args.Report.GetNumericControl(0x01, 0x31).Value); int _rightStickX = (int)(args.Report.GetNumericControl(0x01, 0x33).Value); int _rightStickY = (int)(args.Report.GetNumericControl(0x01, 0x34).Value); // triggers - left and right: int _LT = (int)Math.Max(0, args.Report.GetNumericControl(0x01, 0x32).Value - 32768); int _RT = (int)Math.Max(0, (-1) * (args.Report.GetNumericControl(0x01, 0x32).Value - 32768)); JoystickRawState jss = new JoystickRawState() { X = _leftStickX, Y = _leftStickY, Z = 0, XR = _rightStickX, YR = _rightStickY, LT = _LT, RT = _RT, DpadDirection = dpadDirection }; /* * Buttons Boolean ID's mapped to 0-9 array * A (button1) - 5 * B (button2) - 6 * X (button3) - 7 * Y (button4) - 8 * LB (Left Bumper, button5) - 9 * RB (Right Bumper, button6) - 10 * Back (button7) - 11 * Start (button8) - 12 * LStick - 13 * RStick - 14 */ foreach (var btn in args.Report.ActivatedBooleanControls) { // both press and release button event processed here: jss.Buttons[btn.Id - 5] = btn.IsActive; } // only invoke event if there was a change: if (!jss.Equals(jssLast)) { jssLast = jss; //Debug.WriteLine("--------- HID: Joystick event"); JoystickDataChanged?.Invoke(this, new JoystickEventArgs(jss)); } }
/// <summary> /// Handler for processing/filtering input from the controller /// </summary> /// <param name="sender">HidDevice handle to the controller</param> /// <param name="args">InputReport received from the controller</param> private void inputReportReceived(HidDevice sender, HidInputReportReceivedEventArgs args) { int dPad = (int)args.Report.GetNumericControl(0x01, 0x39).Value; ControllerDpadDirection dpadDirection = (ControllerDpadDirection)dPad; // see http://sviluppomobile.blogspot.com/2013/11/hid-communication-for-windows-81-store.html // Adjust X/Y so (0,0) is neutral position // sticks - left and right: int _leftStickX = (int)(args.Report.GetNumericControl(0x01, 0x30).Value); int _leftStickY = (int)(args.Report.GetNumericControl(0x01, 0x31).Value); int _rightStickX = (int)(args.Report.GetNumericControl(0x01, 0x33).Value); int _rightStickY = (int)(args.Report.GetNumericControl(0x01, 0x34).Value); // triggers - left and right: int _LT = (int)Math.Max(0, args.Report.GetNumericControl(0x01, 0x32).Value - 32768); int _RT = (int)Math.Max(0, (-1) * (args.Report.GetNumericControl(0x01, 0x32).Value - 32768)); JoystickRawState jss = new JoystickRawState() { X = _leftStickX, Y = _leftStickY, Z = 0, XR = _rightStickX, YR = _rightStickY, LT = _LT, RT = _RT, DpadDirection = dpadDirection }; /* * Buttons Boolean ID's mapped to 0-9 array * A (button1) - 5 * B (button2) - 6 * X (button3) - 7 * Y (button4) - 8 * LB (Left Bumper, button5) - 9 * RB (Right Bumper, button6) - 10 * Back (button7) - 11 * Start (button8) - 12 * LStick - 13 * RStick - 14 */ foreach (var btn in args.Report.ActivatedBooleanControls) { // both press and release button event processed here: jss.Buttons[btn.Id - 5] = btn.IsActive; } // only invoke event if there was a change: if (!jss.Equals(jssLast)) { jssLast = jss; //Debug.WriteLine("--------- HID: Joystick event"); JoystickDataChanged?.Invoke(this, new JoystickEventArgs(jss)); } }
void HandleInputReportRecieved(HidDevice sender, HidInputReportReceivedEventArgs args) { try { _currentPressureValue = args.Report.GetNumericControl(0x01, 0x30).Value; } catch { return; } }
private static byte[] InputReportToBytes(HidInputReportReceivedEventArgs args) { byte[] bytes; using (var stream = args.Report.Data.AsStream()) { bytes = new byte[args.Report.Data.Length]; stream.Read(bytes, 0, (int)args.Report.Data.Length); } return(bytes); }
private void ConnectedDevice_InputReportReceived(hidDevice sender, HidInputReportReceivedEventArgs args) { Logger.LogDebug("Received Hid report Id: {id}", args?.Report?.Id); using var stream = args.Report.Data.AsStream(); var bytes = new byte[args.Report.Data.Length]; var bytesRead = (uint)stream.Read(bytes, 0, (int)args.Report.Data.Length); DataReceiver.DataReceived(new TransferResult(bytes, bytesRead)); }
private void Device_InputReportReceived(HidDevice sender, HidInputReportReceivedEventArgs args) { var data = args.Report.Data.ToArray(); var reportID = data[0]; switch (reportID) { case 2: Device_Input_2(data); break; } }
private void CurrentDevice_InputReportReceived(HidDevice sender, HidInputReportReceivedEventArgs args) { HidInputReport report = args.Report; try { processReport(report); }catch (Exception e) { #if DEBUG System.Diagnostics.Debug.WriteLine(e.Message); #endif } }
void DeviceOnInputReportReceived(HidDevice sender, HidInputReportReceivedEventArgs args) { lock (inputReportLock) { if (inputReportSource != null) { inputReportSource.TrySetResult(args.Report); } else { inputReportQueue.Enqueue(args.Report); } } }
void DeviceOnInputReportReceived(HidDevice sender, HidInputReportReceivedEventArgs args) { lock (inputReportLock) { if (inputReportSource != null) { inputReportSource.SetResult(args.Report); } else { inputReportQueue.Enqueue(args.Report); } } }
private async void OnGeneralInterruptEvent(HidDevice sender, HidInputReportReceivedEventArgs eventArgs) { // Retrieve the sensor data HidInputReport inputReport = eventArgs.Report; IBuffer buffer = inputReport.Data; DataReader dr = DataReader.FromBuffer(buffer); byte[] BufferIn = new byte[inputReport.Data.Length]; dr.ReadBytes(BufferIn); // Wait for when UI is ready to be updated await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { { // Channel1 byte[] vIn = new byte[] { BufferIn[1], BufferIn[2], BufferIn[3], BufferIn[4] }; long result = BitConverter.ToInt32(vIn, 0); Channel1.Text = Convert.ToString(result); // Channel2 vIn = new byte[] { BufferIn[5], BufferIn[6], BufferIn[7], BufferIn[8] }; result = BitConverter.ToInt32(vIn, 0); Channel2.Text = Convert.ToString(result); // Channel3 vIn = new byte[] { BufferIn[9], BufferIn[10], BufferIn[11], BufferIn[12] }; result = BitConverter.ToInt32(vIn, 0); Channel3.Text = Convert.ToString(result); // Channel4 vIn = new byte[] { BufferIn[13], BufferIn[14], BufferIn[15], BufferIn[16] }; result = BitConverter.ToInt32(vIn, 0); Channel4.Text = Convert.ToString(result); // Channel5 vIn = new byte[] { BufferIn[17], BufferIn[18], BufferIn[19], BufferIn[20] }; result = BitConverter.ToInt32(vIn, 0); Channel5.Text = Convert.ToString(result); // Channel6 vIn = new byte[] { BufferIn[21], BufferIn[22], BufferIn[23], BufferIn[24] }; result = BitConverter.ToInt32(vIn, 0); Channel6.Text = Convert.ToString(result); } }); }
private void USBInterruptTransferHandler(HidDevice sender, HidInputReportReceivedEventArgs args) { GetHidReport(args); //if (Logger.IsLoggingRawData()) //{ // lock (_lock) // { // DataPacket p = _dataQueue.Get(); // _dataQueue.Add(p); // Motus_1_RawDataPacket packet = new Motus_1_RawDataPacket(p); // Logger.LogRawData(packet.ToString()); // } //} }
private void OnHidDeviceInputReportReceived(HidDevice sender, HidInputReportReceivedEventArgs args) { byte[] data = args.Report.Data.ToArray(); short size = (short)(data[1] | data[2] << 8); if (size == 0) { return; } byte[] receivedData = new byte[size]; Array.Copy(data, 3, receivedData, 0, size); RaiseDataReceived(receivedData); }
private byte[] InputReportToBytes(HidInputReportReceivedEventArgs args) { byte[] bytes; using (var stream = args.Report.Data.AsStream()) { bytes = new byte[args.Report.Data.Length]; stream.Read(bytes, 0, (int)args.Report.Data.Length); } if (DataHasExtraByte) { bytes = RemoveFirstByte(bytes); } return(bytes); }
/// <summary> /// Handler for processing/filtering input from the controller /// </summary> /// <param name="sender">HidDevice handle to the controller</param> /// <param name="args">InputReport received from the controller</param> private void inputReportReceived(HidDevice sender, HidInputReportReceivedEventArgs args) { int dPad = (int)args.Report.GetNumericControl(0x01, 0x39).Value; ControllerVector newVector = new ControllerVector() { Direction = (ControllerDirection)dPad, Magnitude = 10000 }; // DPad has priority over thumb stick, only bother with thumb stick // values if DPad is not providing a value. if (newVector.Direction == ControllerDirection.None) { // If direction is None, magnitude should be 0 newVector.Magnitude = 0; // Adjust X/Y so (0,0) is neutral position double stickX = args.Report.GetNumericControl(0x01, 0x30).Value - 32768; double stickY = args.Report.GetNumericControl(0x01, 0x31).Value - 32768; int stickMagnitude = (int)getMagnitude(stickX, stickY); // Only process if the stick is outside the dead zone if (stickMagnitude > 0) { newVector.Direction = coordinatesToDirection(stickX, stickY); newVector.Magnitude = stickMagnitude; if (MaxMagnitude[newVector.Direction] < newVector.Magnitude) { MaxMagnitude[newVector.Direction] = newVector.Magnitude; } } } // Only fire an event if the vector changed if (!this.DirectionVector.Equals(newVector)) { if (null != this.DirectionChanged) { this.DirectionVector = newVector; this.DirectionChanged(this.DirectionVector); } } }
private void _HidDevice_InputReportReceived(HidDevice sender, HidInputReportReceivedEventArgs args) { if (!_IsReading) { lock (_Chunks) { var bytes = InputReportToBytes(args); _Chunks.Add(bytes); } } else { var bytes = InputReportToBytes(args); _IsReading = false; _TaskCompletionSource.SetResult(bytes); } }
private void HidDeviceInputReportReceived(HidDevice sender, HidInputReportReceivedEventArgs args) { byte[] data = args.Report.Data.ToArray(); short size = (short)(data[1] | data[2] << 8); if (size == 0) { return; } byte[] report = new byte[size]; Array.Copy(data, 3, report, 0, size); if (ReportReceived != null) { ReportReceived(this, new ReportReceivedEventArgs { Report = report }); } }
private void Device_InputReportReceived(HidDevice sender, HidInputReportReceivedEventArgs args) { // Retrieve the sensor data HidInputReport inputReport = args.Report; IBuffer buffer = inputReport.Data; DataReader dr = DataReader.FromBuffer(buffer); byte[] bytes = new byte[inputReport.Data.Length]; dr.ReadBytes(bytes); if (bytes.Length <= 0) { return; } lock (this) { // Clear the control states OnUpdate(); // Report button controls foreach (var button in args.Report.ActivatedBooleanControls) { ReportControl((int)button.Id, 1f); } // Report numeric controls int[] specialControls = GetNumericControls(gamepadType); for (int i = 0; i < specialControls.Length; ++i) { HidNumericControl ctrl = args.Report.GetNumericControl(1, (ushort)specialControls[i]); if (ctrl != null) { ReportControl(specialControls[i], ctrl.Value); } } } }
private void _HidDevice_InputReportReceived(HidDevice sender, HidInputReportReceivedEventArgs args) { HandleDataReceived(InputReportToBytes(args)); }
/// <summary> /// This callback only increments the total number of events received and prints it /// /// This method is called whenever the device's state changes and sends a report. Since all input reports share the same event in /// HidDevice, the app needs to get the HidInputReport from eventArgs.Report and compare report ids and usages with the desired /// report. /// </summary> /// <param name="sender">HidDevice that the event is being raised from</param> /// <param name="eventArgs">Contains the HidInputReport that caused the event to raise</param> private async void OnInputReportEvent(HidDevice sender, HidInputReportReceivedEventArgs eventArgs) { // If we navigated away from this page, we don't need to process this event // This also prevents output from spilling into another page if (!navigatedAway) { numInputReportEventsReceived++; // The data from the InputReport HidInputReport inputReport = eventArgs.Report; IBuffer buffer = inputReport.Data; totalNumberBytesReceived += buffer.Length; // Create a DispatchedHandler for the because we are interracting with the UI directly and the // thread that this function is running on may not be the UI thread; if a non-UI thread modifies // the UI, an exception is thrown await rootPage.Dispatcher.RunAsync( CoreDispatcherPriority.Normal, new DispatchedHandler(() => { // If we navigated away from this page, do not print anything. The dispatch may be handled after // we move to a different page. if (!navigatedAway) { rootPage.NotifyUser( "Total number of input report events received: " + numInputReportEventsReceived.ToString() + "\nTotal number of bytes received: " + totalNumberBytesReceived.ToString(), NotifyType.StatusMessage); } })); } }
internal async void OnInputReportEvent(HidDevice sender, HidInputReportReceivedEventArgs args) { if (_devState == DevState.Detected || _devState == DevState.IOError) { // drop all packet until reset has been sent return; } try { byte[] bb = args.Report.Data.ToArray(); long ofs = 1; //skip first byte that is not part of the packet List <YPktStreamHead> streams = new List <YPktStreamHead>(); while (ofs < bb.Length) { YPktStreamHead s = YPktStreamHead.imm_Decode(ofs, bb); if (s == null) { break; } //Debug.WriteLine(s.ToString()); streams.Add(s); ofs += s.Len + 2; } YPktStreamHead streamHead = streams[0]; switch (_devState) { case DevState.ResetSend: if (streamHead.PktType != YUSBPkt.YPKT_CONF || streamHead.StreamType != YUSBPkt.USB_CONF_RESET) { return; } byte low = streamHead.imm_GetByte(0); uint hig = streamHead.imm_GetByte(1); uint devapi = (hig << 8) + low; _devVersion = devapi; if (imm_CheckVersionCompatibility(devapi) < 0) { return; } await Start(_pktAckDelay); break; case DevState.StartSend: if (streamHead.PktType != YUSBPkt.YPKT_CONF || streamHead.StreamType != YUSBPkt.USB_CONF_START) { return; } if (_devVersion >= YUSBPkt.YPKT_USB_VERSION_BCD) { _pktAckDelay = streamHead.imm_GetByte(1); } else { _pktAckDelay = 0; } _lastpktno = streamHead.PktNumber; _devState = DevState.StartReceived; break; case DevState.StreamReadyReceived: case DevState.StartReceived: if (_devState == DevState.StreamReadyReceived || _devState == DevState.StartReceived) { if (_pktAckDelay > 0 && _lastpktno == streamHead.PktNumber) { //late retry : drop it since we already have the packet. return; } uint expectedPktNo = (_lastpktno + 1) & 7; if (streamHead.PktNumber != expectedPktNo) { String message = "Missing packet (look of pkt " + expectedPktNo + " but get " + streamHead.PktNumber + ")"; _yctx._Log(message + "\n"); _yctx._Log("Set YAPI.RESEND_MISSING_PKT on YAPI.InitAPI()\n"); _devState = DevState.IOError; _watcher.imm_removeUsableDevice(this); return; } _lastpktno = streamHead.PktNumber; await streamHandler(streams); await checkMetaUTC(); } break; default: return; } } catch (YAPI_Exception ex) { _yctx._Log(ex.Message + "\n"); _yctx._Log("Set YAPI.RESEND_MISSING_PKT on YAPI.InitAPI()\n"); _devState = DevState.IOError; _watcher.imm_removeUsableDevice(this); if (_currentTask != null) { _currentTask.SetException(ex); } } }
/// <summary> /// InputEvents received automatically from the wiiremote. /// Conventionally starts with 0xA1 followed by the ID byte and then the specifics. /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void InputEvent(HidDevice sender, HidInputReportReceivedEventArgs args) { ParseInput(args.Report.Data); }
private void DeviceHandle_InputReportReceived(HidDevice sender, HidInputReportReceivedEventArgs args) { int dPad = (int)args.Report.GetNumericControl(0x01, 0x39).Value; }
private void DeviceHandle_InputReportReceived1(HidDevice sender, HidInputReportReceivedEventArgs args) { int dPad = (int)args.Report.GetNumericControl(0x01, 0x39).Value; Debug.WriteLine("dpad: {0}", dPad); }
private void _device_InputReportReceived(HidDevice sender, HidInputReportReceivedEventArgs args) { OnDataReceived(args.Report.Data.ToArray()); }
/// <summary> /// Handler for processing/filtering input from the controller /// </summary> /// <param name="sender">HidDevice handle to the controller</param> /// <param name="args">InputReport received from the controller</param> private void inputReportReceived(HidDevice sender, HidInputReportReceivedEventArgs args) { int dPad = (int)args.Report.GetNumericControl(0x01, 0x39).Value; ControllerVector newVector = new ControllerVector() { Direction = (ControllerDirection)dPad, Magnitude = 10000 }; // DPad has priority over thumb stick, only bother with thumb stick // values if DPad is not providing a value. if (newVector.Direction == ControllerDirection.None) { // If direction is None, magnitude should be 0 newVector.Magnitude = 0; // Adjust X/Y so (0,0) is neutral position double stickX = args.Report.GetNumericControl(0x01, 0x30).Value - 32768; double stickY = args.Report.GetNumericControl(0x01, 0x31).Value - 32768; int stickMagnitude = (int)getMagnitude(stickX, stickY); // Only process if the stick is outside the dead zone if (stickMagnitude > 0) { newVector.Direction = coordinatesToDirection(stickX, stickY); newVector.Magnitude = stickMagnitude; if (MaxMagnitude[newVector.Direction] < newVector.Magnitude) { MaxMagnitude[newVector.Direction] = newVector.Magnitude; } } } // Only fire an event if the vector changed if (!this.DirectionVector.Equals(newVector)) { if (null != this.DirectionChanged) { this.DirectionVector = newVector; this.DirectionChanged(this.DirectionVector); } } }
private static void InputReportReceived(HidDevice sender, HidInputReportReceivedEventArgs args) { var dPad = (int)args.Report.GetNumericControl(0x01, 0x39).Value; var lstickX = args.Report.GetNumericControl(0x01, 0x30).Value - 32768; var lstickY = args.Report.GetNumericControl(0x01, 0x31).Value - 32768; var rstickX = args.Report.GetNumericControl(0x01, 0x33).Value - 32768; var rstickY = args.Report.GetNumericControl(0x01, 0x34).Value - 32768; var lt = (int)Math.Max(0, args.Report.GetNumericControl(0x01, 0x32).Value - 32768); var rt = (int)Math.Max(0, -1 * (args.Report.GetNumericControl(0x01, 0x32).Value - 32768)); foreach (var btn in args.Report.ActivatedBooleanControls) //StartAsync = 7, Back = 6 { var id = (int)(btn.Id - 5); if (id < 4) { FunctionButtonChanged?.Invoke(id); } else if (id >= 4 && id < 6) { BumperButtonChanged?.Invoke(id); } else { FunctionButtonChanged?.Invoke(id); } } if (_leftTrigger != lt) { LeftTriggerChanged?.Invoke(lt); _leftTrigger = lt; } if (_rightTrigger != rt) { RightTriggerChanged?.Invoke(rt); _rightTrigger = rt; } var lStickMagnitude = GetMagnitude(lstickX, lstickY); var rStickMagnitude = GetMagnitude(rstickX, rstickY); var vector = new ControllerVector { Direction = CoordinatesToDirection(lstickX, lstickY), Magnitude = lStickMagnitude }; if (!_leftStickDirectionVector.Equals(vector) && LeftDirectionChanged != null) { _leftStickDirectionVector = vector; LeftDirectionChanged(_leftStickDirectionVector); } vector = new ControllerVector { Direction = CoordinatesToDirection(rstickX, rstickY), Magnitude = rStickMagnitude }; if (!_rightStickDirectionVector.Equals(vector) && RightDirectionChanged != null) { _rightStickDirectionVector = vector; RightDirectionChanged(_rightStickDirectionVector); } vector = new ControllerVector { Direction = (ControllerDirection)dPad, Magnitude = 10000 }; if (_dpadDirectionVector.Equals(vector) || DpadDirectionChanged == null) { return; } _dpadDirectionVector = vector; DpadDirectionChanged(vector); }
private void DeviceHandle_InputReportReceived(HidDevice sender, HidInputReportReceivedEventArgs args) { int dPad = (int)args.Report.GetNumericControl(0x01, 0x39).Value; }
private void HidDeviceInputReportReceived(HidDevice sender, HidInputReportReceivedEventArgs args) { byte[] data = args.Report.Data.ToArray(); short size = (short)(data[1] | data[2] << 8); if (size == 0) return; byte[] report = new byte[size]; Array.Copy(data, 3, report, 0, size); if (ReportReceived != null) ReportReceived(this, new ReportReceivedEventArgs { Report = report }); }
private void DeviceInputReportReceived(HidDevice sender, HidInputReportReceivedEventArgs e) { bool isAButtonDown = false; bool isBButtonDown = false; bool isXButtonDown = false; bool isYButtonDown = false; bool isBackButtonDown = false; bool isStartButtonDown = false; bool isLeftBumperButtonDown = false; bool isRightBumperButtonDown = false; bool isLeftThumbstickButtonDown = false; bool isRightThumbstickButtonDown = false; foreach (HidBooleanControl control in e.Report.ActivatedBooleanControls) { if (!Enum.IsDefined(typeof(Xbox360ControllerButtonUsage), control.UsageId)) { continue; } var usage = (Xbox360ControllerButtonUsage)control.UsageId; switch (usage) { case Xbox360ControllerButtonUsage.A: isAButtonDown = control.IsActive; break; case Xbox360ControllerButtonUsage.B: isBButtonDown = control.IsActive; break; case Xbox360ControllerButtonUsage.X: isXButtonDown = control.IsActive; break; case Xbox360ControllerButtonUsage.Y: isYButtonDown = control.IsActive; break; case Xbox360ControllerButtonUsage.Back: isBackButtonDown = control.IsActive; break; case Xbox360ControllerButtonUsage.Start: isStartButtonDown = control.IsActive; break; case Xbox360ControllerButtonUsage.LeftBumper: isLeftBumperButtonDown = control.IsActive; break; case Xbox360ControllerButtonUsage.RightBumper: isRightBumperButtonDown = control.IsActive; break; case Xbox360ControllerButtonUsage.LeftThumbstick: isLeftThumbstickButtonDown = control.IsActive; break; case Xbox360ControllerButtonUsage.RightThumbstick: isRightThumbstickButtonDown = control.IsActive; break; } } const ushort usagePageGeneric = 0x01 /*Generic*/; long leftThumbstickHorizontal = e.Report.GetNumericControl(usagePageGeneric, (ushort)Xbox360ControllerGenericUsage.X).Value; long leftThumbstickVertical = e.Report.GetNumericControl(usagePageGeneric, (ushort)Xbox360ControllerGenericUsage.Y).Value; long trigger = e.Report.GetNumericControl(usagePageGeneric, (ushort)Xbox360ControllerGenericUsage.Z).Value; long rightThumbstickHorizontal = e.Report.GetNumericControl(usagePageGeneric, (ushort)Xbox360ControllerGenericUsage.RX).Value; long rightThumbstickVertical = e.Report.GetNumericControl(usagePageGeneric, (ushort)Xbox360ControllerGenericUsage.RY).Value; long hatSwitch = e.Report.GetNumericControl(usagePageGeneric, (ushort)Xbox360ControllerGenericUsage.HatSwitch).Value; bool isUpButtonDown = hatSwitch == 1 || hatSwitch == 2 || hatSwitch == 8; bool isRightButtonDown = hatSwitch == 2 || hatSwitch == 3 || hatSwitch == 4; bool isDownButtonDown = hatSwitch == 4 || hatSwitch == 5 || hatSwitch == 6; bool isLeftButtonDown = hatSwitch == 6 || hatSwitch == 7 || hatSwitch == 8; var data = new Xbox360ControllerInputData( isAButtonDown, isBButtonDown, isXButtonDown, isYButtonDown, isLeftBumperButtonDown, isRightBumperButtonDown, isBackButtonDown, isStartButtonDown, isLeftThumbstickButtonDown, isRightThumbstickButtonDown, leftThumbstickHorizontal, leftThumbstickVertical, trigger, rightThumbstickHorizontal, rightThumbstickVertical, isUpButtonDown, isRightButtonDown, isDownButtonDown, isLeftButtonDown); OnInputChanged(data); if (_previousData == null) { _previousData = data; return; } if (_previousData == null || isAButtonDown != _previousData.IsAButtonDown) { if (isAButtonDown) { OnButtonDown(Xbox360ControllerButton.A); OnButtonPressed(Xbox360ControllerButton.A); _aButtonPressedSource = new CancellationTokenSource(); RepeatButtonPressed(Xbox360ControllerButton.A, _repeatDelayMilliseconds, _repeatRateMilliseconds, _aButtonPressedSource.Token); } else if (_previousData != null) { _aButtonPressedSource.Cancel(); OnButtonUp(Xbox360ControllerButton.A); } } if (_previousData == null || isBButtonDown != _previousData.IsBButtonDown) { if (isBButtonDown) { OnButtonDown(Xbox360ControllerButton.B); OnButtonPressed(Xbox360ControllerButton.B); _bButtonPressedSource = new CancellationTokenSource(); RepeatButtonPressed(Xbox360ControllerButton.B, _repeatDelayMilliseconds, _repeatRateMilliseconds, _bButtonPressedSource.Token); } else if (_previousData != null) { _bButtonPressedSource.Cancel(); OnButtonUp(Xbox360ControllerButton.B); } } if (_previousData == null || isXButtonDown != _previousData.IsXButtonDown) { if (isXButtonDown) { OnButtonDown(Xbox360ControllerButton.X); OnButtonPressed(Xbox360ControllerButton.X); _xButtonPressedSource = new CancellationTokenSource(); RepeatButtonPressed(Xbox360ControllerButton.X, _repeatDelayMilliseconds, _repeatRateMilliseconds, _xButtonPressedSource.Token); } else if (_previousData != null) { _xButtonPressedSource.Cancel(); OnButtonUp(Xbox360ControllerButton.X); } } if (_previousData == null || isYButtonDown != _previousData.IsYButtonDown) { if (isYButtonDown) { OnButtonDown(Xbox360ControllerButton.Y); OnButtonPressed(Xbox360ControllerButton.Y); _yButtonPressedSource = new CancellationTokenSource(); RepeatButtonPressed(Xbox360ControllerButton.Y, _repeatDelayMilliseconds, _repeatRateMilliseconds, _yButtonPressedSource.Token); } else if (_previousData != null) { _yButtonPressedSource.Cancel(); OnButtonUp(Xbox360ControllerButton.Y); } } if (_previousData == null || isLeftBumperButtonDown != _previousData.IsLeftBumperButtonDown) { if (isLeftBumperButtonDown) { OnButtonDown(Xbox360ControllerButton.LeftBumber); OnButtonPressed(Xbox360ControllerButton.LeftBumber); _leftBumperButtonPressedSource = new CancellationTokenSource(); RepeatButtonPressed(Xbox360ControllerButton.LeftBumber, _repeatDelayMilliseconds, _repeatRateMilliseconds, _leftBumperButtonPressedSource.Token); } else if (_previousData != null) { _leftBumperButtonPressedSource.Cancel(); OnButtonUp(Xbox360ControllerButton.LeftBumber); } } if (_previousData == null || isRightBumperButtonDown != _previousData.IsRightBumperButtonDown) { if (isRightBumperButtonDown) { OnButtonDown(Xbox360ControllerButton.RightBumber); OnButtonPressed(Xbox360ControllerButton.RightBumber); _rightBumperButtonPressedSource = new CancellationTokenSource(); RepeatButtonPressed(Xbox360ControllerButton.RightBumber, _repeatDelayMilliseconds, _repeatRateMilliseconds, _rightBumperButtonPressedSource.Token); } else if (_previousData != null) { _rightBumperButtonPressedSource.Cancel(); OnButtonUp(Xbox360ControllerButton.RightBumber); } } if (_previousData == null || isBackButtonDown != _previousData.IsBackButtonDown) { if (isBackButtonDown) { OnButtonDown(Xbox360ControllerButton.Back); OnButtonPressed(Xbox360ControllerButton.Back); _backButtonPressedSource = new CancellationTokenSource(); RepeatButtonPressed(Xbox360ControllerButton.Back, _repeatDelayMilliseconds, _repeatRateMilliseconds, _backButtonPressedSource.Token); } else if (_previousData != null) { _backButtonPressedSource.Cancel(); OnButtonUp(Xbox360ControllerButton.Back); } } if (_previousData == null || isStartButtonDown != _previousData.IsStartButtonDown) { if (isStartButtonDown) { OnButtonDown(Xbox360ControllerButton.Start); OnButtonPressed(Xbox360ControllerButton.Start); _startButtonPressedSource = new CancellationTokenSource(); RepeatButtonPressed(Xbox360ControllerButton.Start, _repeatDelayMilliseconds, _repeatRateMilliseconds, _startButtonPressedSource.Token); } else if (_previousData != null) { _startButtonPressedSource.Cancel(); OnButtonUp(Xbox360ControllerButton.Start); } } if (_previousData == null || isLeftThumbstickButtonDown != _previousData.IsLeftThumbstickButtonDown) { if (isLeftThumbstickButtonDown) { OnButtonDown(Xbox360ControllerButton.LeftThumbstick); OnButtonPressed(Xbox360ControllerButton.LeftThumbstick); _leftThumbstickButtonPressedSource = new CancellationTokenSource(); RepeatButtonPressed(Xbox360ControllerButton.LeftThumbstick, _repeatDelayMilliseconds, _repeatRateMilliseconds, _leftThumbstickButtonPressedSource.Token); } else if (_previousData != null) { _leftThumbstickButtonPressedSource.Cancel(); OnButtonUp(Xbox360ControllerButton.LeftThumbstick); } } if (_previousData == null || isRightThumbstickButtonDown != _previousData.IsRightThumbstickButtonDown) { if (isRightThumbstickButtonDown) { OnButtonDown(Xbox360ControllerButton.RightThumbstick); OnButtonPressed(Xbox360ControllerButton.RightThumbstick); _rightThumbstickButtonPressedSource = new CancellationTokenSource(); RepeatButtonPressed(Xbox360ControllerButton.RightThumbstick, _repeatDelayMilliseconds, _repeatRateMilliseconds, _rightThumbstickButtonPressedSource.Token); } else if (_previousData != null) { _rightThumbstickButtonPressedSource.Cancel(); OnButtonUp(Xbox360ControllerButton.RightThumbstick); } } if (_previousData == null || isUpButtonDown != _previousData.IsUpButtonDown) { if (isUpButtonDown) { OnButtonDown(Xbox360ControllerButton.Up); OnButtonPressed(Xbox360ControllerButton.Up); _upButtonPressedSource = new CancellationTokenSource(); RepeatButtonPressed(Xbox360ControllerButton.Up, _repeatDelayMilliseconds, _repeatRateMilliseconds, _upButtonPressedSource.Token); } else if (_previousData != null) { _upButtonPressedSource.Cancel(); OnButtonUp(Xbox360ControllerButton.Up); } } if (_previousData == null || isRightButtonDown != _previousData.IsRightButtonDown) { if (isRightButtonDown) { OnButtonDown(Xbox360ControllerButton.Right); OnButtonPressed(Xbox360ControllerButton.Right); _rightButtonPressedSource = new CancellationTokenSource(); RepeatButtonPressed(Xbox360ControllerButton.Right, _repeatDelayMilliseconds, _repeatRateMilliseconds, _rightButtonPressedSource.Token); } else if (_previousData != null) { _rightButtonPressedSource.Cancel(); OnButtonUp(Xbox360ControllerButton.Right); } } if (_previousData == null || isDownButtonDown != _previousData.IsDownButtonDown) { if (isDownButtonDown) { OnButtonDown(Xbox360ControllerButton.Down); OnButtonPressed(Xbox360ControllerButton.Down); _downButtonPressedSource = new CancellationTokenSource(); RepeatButtonPressed(Xbox360ControllerButton.Down, _repeatDelayMilliseconds, _repeatRateMilliseconds, _downButtonPressedSource.Token); } else if (_previousData != null) { _downButtonPressedSource.Cancel(); OnButtonUp(Xbox360ControllerButton.Down); } } if (_previousData == null || isLeftButtonDown != _previousData.IsLeftButtonDown) { if (isLeftButtonDown) { OnButtonDown(Xbox360ControllerButton.Left); OnButtonPressed(Xbox360ControllerButton.Left); _leftButtonPressedSource = new CancellationTokenSource(); RepeatButtonPressed(Xbox360ControllerButton.Left, _repeatDelayMilliseconds, _repeatRateMilliseconds, _leftButtonPressedSource.Token); } else if (_previousData != null) { _leftButtonPressedSource.Cancel(); OnButtonUp(Xbox360ControllerButton.Left); } } if (_previousData != null) { if (leftThumbstickHorizontal != _previousData.LeftThumbstickHorizontal || leftThumbstickVertical != _previousData.LeftThumbstickVertical) { OnThumbstickChanged(Xbox360ControllerThumbstick.Left, leftThumbstickHorizontal, leftThumbstickVertical); } if (rightThumbstickHorizontal != _previousData.RightThumbstickHorizontal || rightThumbstickVertical != _previousData.RightThumbstickVertical) { OnThumbstickChanged(Xbox360ControllerThumbstick.Right, rightThumbstickHorizontal, rightThumbstickVertical); } if (trigger != _previousData.Trigger) { OnTriggerChanged(trigger); } } _previousData = data; }
private void DeviceHandle_InputReportReceived1(HidDevice sender, HidInputReportReceivedEventArgs args) { int dPad = (int)args.Report.GetNumericControl(0x01, 0x39).Value; Debug.WriteLine("dpad: {0}", dPad); }
private static void InputReportReceived(HidDevice sender, HidInputReportReceivedEventArgs args) { var dPad = (int)args.Report.GetNumericControl(0x01, 0x39).Value; var lstickX = args.Report.GetNumericControl(0x01, 0x30).Value - 32768; var lstickY = args.Report.GetNumericControl(0x01, 0x31).Value - 32768; var rstickX = args.Report.GetNumericControl(0x01, 0x33).Value - 32768; var rstickY = args.Report.GetNumericControl(0x01, 0x34).Value - 32768; var lt = (int)Math.Max(0, args.Report.GetNumericControl(0x01, 0x32).Value - 32768); var rt = (int)Math.Max(0, -1 * (args.Report.GetNumericControl(0x01, 0x32).Value - 32768)); foreach (var btn in args.Report.ActivatedBooleanControls) //StartAsync = 7, Back = 6 { var id = (int)(btn.Id - 5); if (id < 4) FunctionButtonChanged?.Invoke(id); else if (id >= 4 && id < 6) BumperButtonChanged?.Invoke(id); else FunctionButtonChanged?.Invoke(id); } if (_leftTrigger != lt) { LeftTriggerChanged?.Invoke(lt); _leftTrigger = lt; } if (_rightTrigger != rt) { RightTriggerChanged?.Invoke(rt); _rightTrigger = rt; } var lStickMagnitude = GetMagnitude(lstickX, lstickY); var rStickMagnitude = GetMagnitude(rstickX, rstickY); var vector = new ControllerVector { Direction = CoordinatesToDirection(lstickX, lstickY), Magnitude = lStickMagnitude }; if (!_leftStickDirectionVector.Equals(vector) && LeftDirectionChanged != null) { _leftStickDirectionVector = vector; LeftDirectionChanged(_leftStickDirectionVector); } vector = new ControllerVector { Direction = CoordinatesToDirection(rstickX, rstickY), Magnitude = rStickMagnitude }; if (!_rightStickDirectionVector.Equals(vector) && RightDirectionChanged != null) { _rightStickDirectionVector = vector; RightDirectionChanged(_rightStickDirectionVector); } vector = new ControllerVector { Direction = (ControllerDirection)dPad, Magnitude = 10000 }; if (_dpadDirectionVector.Equals(vector) || DpadDirectionChanged == null) return; _dpadDirectionVector = vector; DpadDirectionChanged(vector); }
void HandleInputReportRecieved(HidDevice sender, HidInputReportReceivedEventArgs args) => _currentReading = args.Report.ToGamepadReading();
private void _device_InputReportReceived(HidDevice sender, HidInputReportReceivedEventArgs args) { DataReceived?.Invoke(this, args.Report.Data.ToArray()); }
private static void inputReportReceived(HidDevice sender, HidInputReportReceivedEventArgs args) { //button int[] _buttons = new int[10] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; foreach (var btn in args.Report.ActivatedBooleanControls) { _buttons[btn.Id - 5] = 1; } if (_buttons[0] == 1) { if (Button_A_Pressed != null) { Button_A_Pressed(); } } if (_buttons[1] == 1) { if (Button_B_Pressed != null) { Button_B_Pressed(); } } if (_buttons[2] == 1) { if (Button_X_Pressed != null) { Button_X_Pressed(); } } if (_buttons[3] == 1) { if (Button_Y_Pressed != null) { Button_Y_Pressed(); } } if (_buttons[4] == 1) { if (Button_LB_Pressed != null) { Button_LB_Pressed(); } } if (_buttons[5] == 1) { if (Button_RB_Pressed != null) { Button_RB_Pressed(); } } if (_buttons[6] == 1) { if (Button_Back_Pressed != null) { Button_Back_Pressed(); } } if (_buttons[7] == 1) { if (Button_Start_Pressed != null) { Button_Start_Pressed(); } } long Button_LT = Math.Max(0, args.Report.GetNumericControl(0x01, 0x32).Value - 32768); long Button_RT = Math.Max(0, (-1) * (args.Report.GetNumericControl(0x01, 0x32).Value - 32768)); //stick double stickX = args.Report.GetNumericControl(0x01, 0x30).Value - 32768; double stickY = args.Report.GetNumericControl(0x01, 0x31).Value - 32768; double RStickX = args.Report.GetNumericControl(0x01, 0x33).Value - 32768; double RStickY = args.Report.GetNumericControl(0x01, 0x34).Value - 32768; stickX = getMagnitude(stickX); stickY = getMagnitude(stickY); RStickX = getMagnitude(RStickX); RStickY = getMagnitude(RStickY); if ((stickX == 0) && (stickY == 0)) { MoveDir = ControllerDirection.None; } if (stickY < 0) { MoveDir = ControllerDirection.Up; } if (stickY > 0) { MoveDir = ControllerDirection.Down; } if (stickX < 0) { MoveDir = ControllerDirection.Left; } if (stickX > 0) { MoveDir = ControllerDirection.Right; } if ((RStickX == 0) && (RStickY == 0)) { RMoveDir = ControllerDirection.None; } if (RStickY < 0) { RMoveDir = ControllerDirection.Up; } if (RStickY > 0) { RMoveDir = ControllerDirection.Down; } if (RStickX < 0) { RMoveDir = ControllerDirection.Left; } if (RStickX > 0) { RMoveDir = ControllerDirection.Right; } FristMoveDir = MoveDir; RFristMoveDir = RMoveDir; if (FristMoveDir != LastMoveDir) { if (FristMoveDir == ControllerDirection.None) { if (Leftstick_Stop != null) { Leftstick_Stop(); } } if (FristMoveDir == ControllerDirection.Up) { if (Leftstick_Up != null) { Leftstick_Up(); } } if (FristMoveDir == ControllerDirection.Down) { if (Leftstick_Down != null) { Leftstick_Down(); } } if (FristMoveDir == ControllerDirection.Left) { if (Leftstick_Left != null) { Leftstick_Left(); } } if (FristMoveDir == ControllerDirection.Right) { if (Leftstick_Right != null) { Leftstick_Right(); } } LastMoveDir = FristMoveDir; } if (RFristMoveDir != RLastMoveDir) { if (RFristMoveDir == ControllerDirection.None) { if (Rightstick_Stop != null) { Rightstick_Stop(); } } if (RFristMoveDir == ControllerDirection.Up) { if (Rightstick_Up != null) { Rightstick_Up(); } } if (RFristMoveDir == ControllerDirection.Down) { if (Rightstick_Down != null) { Rightstick_Down(); } } if (RFristMoveDir == ControllerDirection.Left) { if (Rightstick_Left != null) { Rightstick_Left(); } } if (RFristMoveDir == ControllerDirection.Right) { if (Rightstick_Right != null) { Rightstick_Right(); } } RLastMoveDir = RFristMoveDir; } }
private void ConnectedScope_InputReportReceived(HidDevice sender, HidInputReportReceivedEventArgs args) { if (args.Report.Data.Length != NumSamplesPerPacket + PacketOverheadBytes) { Debug.WriteLine("Expected {0} bytes input report, received {1} bytes", NumSamplesPerPacket + PacketOverheadBytes, args.Report.Data.Length); return; } var bytes = new byte[args.Report.Data.Length]; DataReader dr = DataReader.FromBuffer(args.Report.Data); dr.ReadBytes(bytes); if (bytes[1] != NextPacketExpected) { Debug.WriteLine("Expect packet {0}, received packet {1}. Discarding trace.", NextPacketExpected, bytes[1]); CurrentTrace = null; NextPacketExpected = 0; return; } if (NextPacketExpected == 0) { Debug.WriteLine("Packet 0 received, allocating buffer"); CurrentTrace = new byte[NumPacketsPerTrace * NumSamplesPerPacket]; } Array.Copy(bytes, PacketOverheadBytes, CurrentTrace, NextPacketExpected * NumSamplesPerPacket, NumSamplesPerPacket); NextPacketExpected++; if (NextPacketExpected == NumPacketsPerTrace) { Debug.WriteLine("Got full trace"); if (TraceReceived != null) { TraceReceived(CurrentTrace); } CurrentTrace = null; NextPacketExpected = 0; } }