private void MyUSBReader_DataReceived(object sender, LibUsbDotNet.Main.EndpointDataEventArgs e) { Int32 i; if (e.Count > 0) { lBytesReceived += e.Count; if (RXDataCount + e.Count < RXFIFOSIZE) { for (i = 0; i < e.Count; i++) { RXFIFO[RXWritePos] = e.Buffer[i]; RXWritePos = (RXWritePos + 1) % RXFIFOSIZE; } } else { throw new Exception("RX FIFO overflow"); } if (DataReceived != null) { DataReceived(this, new EventArgs()); } } }
private void _isoReader_DataReceived(object sender, EndpointDataEventArgs e) { Logger.WriteLine("Incoming isochronous data: " + BitConverter.ToString(e.Buffer, 0, e.Count)); }
private static void endpointReader_DataReceived(object sender, EndpointDataEventArgs e) { Console.WriteLine(e.Buffer); }
private void OnDataReceived(object sender, EndpointDataEventArgs e) { }
//private byte[] _oldData = null; private void DataReader_DataReceived(object sender, EndpointDataEventArgs e) { var buffer = new byte[e.Count]; Array.Copy(e.Buffer, 0, buffer, 0, buffer.Length); UsbEndpointReader reader = sender as UsbEndpointReader; if (reader != null) { //Find the slot this belongs to int? index = null; foreach (var slot in _slots) { if (slot.Value.DataReader == reader) { index = slot.Key; break; } } if (index.HasValue) { //Console.WriteLine(String.Format("Index {0}, Data: {1}", index.Value, BitConverter.ToString(buffer))); if (buffer[0] == 0x08) { //This is a status packet bool headsetConnected = ((buffer[1] & 0x40) > 0); bool deviceConnected = ((buffer[1] & 0x80) > 0); bool? wasHeadsetConnected = _slots[index.Value].IsHeadsetConnected; _slots[index.Value].IsHeadsetConnected = headsetConnected; if (headsetConnected && !wasHeadsetConnected.GetValueOrDefault()) { //Console.WriteLine("Headset connected"); if (HeadsetConnected != null) HeadsetConnected(this, new DeviceEventArgs(index.Value)); } else if (!headsetConnected && wasHeadsetConnected.GetValueOrDefault()) { //Console.WriteLine("Headset disconnected"); if (HeadsetDisconnected != null) HeadsetDisconnected(this, new DeviceEventArgs(index.Value)); } bool? wasDeviceConnected = _slots[index.Value].IsDeviceConnected; if (!deviceConnected) _slots[index.Value].IsDeviceConnected = false; if (!deviceConnected && wasDeviceConnected.GetValueOrDefault()) { //Console.WriteLine("Device disconnected"); if (DeviceDisconnected != null) DeviceDisconnected(this, new DeviceEventArgs(index.Value)); } if (!deviceConnected) _slots[index.Value].DeviceInformation = null; else { //Device is connected -- set the LED status appropriately this.SetLEDStatus(index.Value, (byte)(0x01 + index.Value)); } } else if (buffer[0] == 0x00 && buffer[1] == 0x0F && buffer[2] == 0x00 && buffer[3] == 0xF0) { byte[] serial = new byte[7]; Array.Copy(buffer, 0x07, serial, 0, serial.Length); int subType = buffer[0x19]; _slots[index.Value].DeviceInformation = new DeviceInformation(serial, subType); if (!_slots[index.Value].IsDeviceConnected.GetValueOrDefault()) { _slots[index.Value].IsDeviceConnected = true; //Console.WriteLine("Device connected"); //Go ahead and enable chatpad events, just in case this.WriteData(index.Value, new byte[] { 0x00, 0x00, 0x0C, 0x1B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }); if (DeviceConnected != null) DeviceConnected(this, new DeviceEventArgs(index.Value)); } } else if (buffer[0] == 0x00 && buffer[2] == 0x00 && buffer[3] == 0xF0) { //This is event data switch (buffer[1]) { case 0x00: { //Unknown event data, comes in after every button press, always zeroes //Eating it for now until we know better break; } case 0x01: { //Regular device data /* if (_oldData == null) _oldData = buffer; bool isSameData = true; if (_oldData.Length == buffer.Length) { for (int i = 0; i < buffer.Length; i++) { if (_oldData[i] != buffer[i]) { isSameData = false; break; } } } else isSameData = false; _oldData = buffer; if (!isSameData) Console.WriteLine("Device data: " + BitConverter.ToString(buffer)); */ if (EventDataReceived != null) EventDataReceived(this, new DataReceivedEventArgs(index.Value, buffer)); break; } case 0x02: { //Wireless chatpad data //Console.WriteLine("Chatpad data: " + BitConverter.ToString(buffer)); if (EventDataReceived != null) EventDataReceived(this, new DataReceivedEventArgs(index.Value, buffer)); break; } default: { //Console.WriteLine("Unknown data: " + BitConverter.ToString(buffer)); if (UnknownDataReceived != null) UnknownDataReceived(this, new DataReceivedEventArgs(index.Value, buffer)); break; } } } } } }
private void mEp_DataReceived(object sender, EndpointDataEventArgs e) { Invoke(new OnDataReceivedDelegate(OnDataReceived), new object[] {sender, e}); }
// private int[] adcVals; // public int[] AdcVals { get { return adcVals; } } public Packet(EndpointDataEventArgs e) : this(e.Buffer) { }
protected static void read_usb(object sender, EndpointDataEventArgs e) { Debug.Assert(e != null && e.Buffer != null); caLibUsbAdapter.read_lock.WaitOne(); if(e.Count > 0) { // add to queue; NB: incomming buffer is fixed-sizem so .ForEach() // cannot be used for(int i = 0;i < e.Count; i++) { thisptr.usb_queue.Enqueue(e.Buffer[i]); } if(thisptr.boot_mode) { caLibUsbAdapter.read_event.Set(); } else { thisptr.process_usb(); } } caLibUsbAdapter.read_lock.ReleaseMutex(); }
public void reader_DataReceived(object sender, EndpointDataEventArgs e) { if (run) { var data = e.Buffer; var input1 = ControllerState.deserialize(getFastInput1(ref data)); if (gcn1ok) { JoystickHelper.setJoystick(ref gcn1, input1, 1, gcn1DZ); } } else { reader.DataReceivedEnabled = false; if (GCNAdapter != null) { if (GCNAdapter.IsOpen) { if (!ReferenceEquals(wholeGCNAdapter, null)) { wholeGCNAdapter.ReleaseInterface(0); } GCNAdapter.Close(); } GCNAdapter = null; UsbDevice.Exit(); DriverLog(null, new Logging.LogEventArgs("Closing driver thread...")); } DriverLog(null, new Logging.LogEventArgs("Driver thread has been stopped.")); } }
void trinket_DataReceived(object sender, EndpointDataEventArgs e) { try { // we got data but the port was never opened? if (port == null) { if (lastPortName != null) // hmm, we have a name of the port, try opening it { port = new SerialPort(lastPortName); port.Open(); port.ReadTimeout = 200; port.ReceivedBytesThreshold = 1; port.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived); } } } catch (Exception ex) { notifyIcon.ShowBalloonTip(1000, "Trinket Fake USB Serial", "Serial Port Opening Error: " + ex.Message, ToolTipIcon.Error); } if (port != null && port.IsOpen == true) { try { // we have a port that is usable, send the data port.Write(e.Buffer, 0, e.Count); bytesProcessed += e.Count; } catch (Exception ex) { notifyIcon.ShowBalloonTip(1000, "Trinket Fake USB Serial", "Serial Port Sending Error: " + ex.Message, ToolTipIcon.Error); } } }
private void DeviceForwarder_DataReceived(object sender, EndpointDataEventArgs e) { //Send it out to the host UsbEndpointReader reader = sender as UsbEndpointReader; if (reader != null) _device.WriteOutgoingData(reader.EpNum & 0x7F, e.Buffer, 0, e.Count); }
public void processDataPacket(object sender, EndpointDataEventArgs e) { if (e.Buffer[0] == 0x08) { // This is a status packet, determine if the controller is connected bool controllerConnected = ((e.Buffer[1] & 0x80) > 0); if (!controllerConnected) { // If the controller is not connected but used to be, report the error if (controllerAttached) { parentWindow.Invoke(new logCallback(parentWindow.logMessage), "Xbox 360 Wireless Controller " + controllerNumber + " Disconnected."); // Clean up the Mouse Mode thread killMouseMode(); // Clean up the Keep-Alive thread killKeepAlive(); // Clean up the Button Combo thread killButtonCombo(); // Refresh the form due to a disconnection parentWindow.Invoke(new controllerDisconnectCallback(parentWindow.controllerDisconnected), controllerNumber); } controllerAttached = false; } else { // Flag that the controller has connected controllerAttached = true; // Set the LED for the controller number switch (controllerNumber) { case 1: sendData(controllerCommands["SetControllerNum1"]); break; case 2: sendData(controllerCommands["SetControllerNum2"]); break; case 3: sendData(controllerCommands["SetControllerNum3"]); break; case 4: sendData(controllerCommands["SetControllerNum4"]); break; default: parentWindow.Invoke(new logCallback(parentWindow.logMessage), "ERROR: Unknown Controller Number."); break; } // Create and start the Keep-Alive thread threadKeepAlive = new System.Threading.Thread(new System.Threading.ThreadStart(tickKeepAlive)); threadKeepAlive.IsBackground = true; threadKeepAlive.Start(); // Create and start the Special Button thread threadButtonCombo = new System.Threading.Thread(new System.Threading.ThreadStart(tickButtonCombo)); threadButtonCombo.IsBackground = true; threadButtonCombo.Start(); // If Mouse Mode, create and start the Mouse Mode thread if (mouseModeFlag) startMouseMode(); // Refresh the form due to a connection parentWindow.Invoke(new controllerConnectCallback(parentWindow.controllerConnected), controllerNumber); // Reports the Controller is Connected parentWindow.Invoke(new logCallback(parentWindow.logMessage), "Xbox 360 Wireless Controller " + controllerNumber + " Connected."); } } else if (e.Buffer[0] == 0x00 && e.Buffer[2] == 0x00 && e.Buffer[3] == 0xF0) { if (controllerAttached) { switch (e.Buffer[1]) { case 0x01: // This is Gamepad data ProcessGamepadData(e.Buffer); break; case 0x02: // This is Chatpad data ProcessChatpadData(e.Buffer); break; default: // Unknown Data, do nothing with it break; } } } }
private void OnDataReceived_LoopTest(object sender, EndpointDataEventArgs e) { if (mBenchMarkParameters.Verify) { for (int i = 0; i < e.Count; i++) { if (mbInLoopTestError) { if (e.Buffer[i] == 0) { mLoopTestOffset = 0; mbInLoopTestError = false; } else continue; } if (mLoopTestOffset >= loopTestBytes.Length) { mLoopTestOffset = 0; mLoopTestCompletedPackets++; } if (e.Buffer[i] == loopTestBytes[mLoopTestOffset]) mLoopTestOffset++; else { mbInLoopTestError = true; if (mLoopTestCompletedPackets > 0) { mEndPointStopWatch.PacketErrorCount++; SetStatus(string.Format("Data validation mismatch at position:{0}/{1}.", i, loopTestBytes.Length), true); } break; } } if (mLoopTestCompletedPackets == 0) return; } if (!mEndPointStopWatch.IsStarted) { mEndPointStopWatch.DiffWithNow(); return; } UpdateDataRate(e.Count); }
private void OnDataReceived(object sender, EndpointDataEventArgs e) { if (mUsbTestType == UsbTestType.Loop) { OnDataReceived_LoopTest(sender, e); } else { for (int i = 0; i < e.Count; i++) { if (mbInLoopTestError) { if (e.Buffer[i] == 0) { mReadTestPID = e.Buffer[i + 1]; mbInLoopTestError = false; } else continue; } if (e.Buffer[i] == 0) { mLoopTestCompletedPackets++; if (e.Buffer[i + 1] == mReadTestPID) { i++; mReadTestPID++; bValidatePosEP1 = 2; } else { mbInLoopTestError = true; if (mLoopTestCompletedPackets > 1) { mEndPointStopWatch.PacketErrorCount++; SetStatus(string.Format("Data validation mismatch at position:{0}/{1}.", i, loopTestBytes.Length), true); } break; } } else if (e.Buffer[i] == bValidatePosEP1) { bValidatePosEP1++; } } if (mLoopTestCompletedPackets < 2) return; if (!mEndPointStopWatch.IsStarted) { mEndPointStopWatch.DiffWithNow(); return; } UpdateDataRate(e.Count); } }
private void _reader_DataReceived(object sender, EndpointDataEventArgs e) { char cmd = (char)e.Buffer[2]; switch (cmd) { case 'E': { Logger.WriteLine("Raw: Received error/busy response: " + BitConverter.ToString(e.Buffer, 0, e.Count), Logger.LoggingLevel.VeryVerbose); //Need to find the first (oldest) message matching this command and mark it as ready to send //HACK: This really should use a sequence ID or something, but this works well enough lock (_messages) { for (int i = 0; i < _messages.Count; i++) { if (_messages[i].Data[2] == e.Buffer[4]) { _messages[i].Status = MessageStatus.ReadyToSend; break; } } } break; } case 'A': { Logger.WriteLine("Raw: Received acknowledgement response: " + BitConverter.ToString(e.Buffer, 0, e.Count), Logger.LoggingLevel.VeryVerbose); //Need to find the first (oldest) message matching this command and delete it //HACK: This really should use a sequence ID or something, but this works well enough // There's also the potential for this to fill up all available memory...don't care for now... lock (_messages) { for (int i = 0; i < _messages.Count; i++) { if (_messages[i].Data[2] == e.Buffer[3]) { _messages.RemoveAt(i); break; } } } break; } case 'U': { Logger.WriteLine("Raw: Received control request: " + BitConverter.ToString(e.Buffer, 0, e.Count), Logger.LoggingLevel.Verbose); //Received control request int bmRequestType = e.Buffer[3]; int bRequest = e.Buffer[4]; int wValue = e.Buffer[5] | (e.Buffer[6] << 8); int wIndex = e.Buffer[7] | (e.Buffer[8] << 8); int wLength = e.Buffer[9] | (e.Buffer[10] << 8); var attachedData = new byte[wLength]; Array.Copy(e.Buffer, 11, attachedData, 0, wLength); var arg = new ControlRequestEventArgs(bmRequestType, bRequest, wValue, wIndex, wLength, attachedData); _currentDevice.OnControlRequestReceived(arg); if (arg.CanIgnore && arg.Ignore) { _Write(new byte[] { (byte)'U', 0x00 }); } else if (arg.Stall) { _Write(new byte[] { (byte)'U', 0x02 }); } else { var ret = new byte[2 + (arg.ReturnData != null ? arg.ReturnData.Length : 0)]; ret[0] = (byte)'U'; ret[1] = 0x01; if (arg.ReturnData != null) Array.Copy(arg.ReturnData, 0, ret, 2, arg.ReturnData.Length); _Write(ret); } break; } case 'F': { //If e.Buffer[3] is non-zero, USB is connected, otherwise disconnected. Apparently. Logger.WriteLine("Raw: Received event: " + BitConverter.ToString(e.Buffer, 0, e.Count), Logger.LoggingLevel.Verbose); break; } case 'D': { Logger.WriteLine("Raw: Received descriptor request: " + BitConverter.ToString(e.Buffer, 0, e.Count), Logger.LoggingLevel.Verbose); //Received descriptor request int wValue = e.Buffer[3] | (e.Buffer[4] << 8); int wIndex = e.Buffer[5] | (e.Buffer[6] << 8); var arg = new DescriptorRequestedEventArgs(wValue, wIndex); _currentDevice.OnDescriptorRequested(arg); //HACK: We tacked on the endpoint configuration stuff to the device descriptor, // so if that's what we're returning, generate and tack it on here byte[] ret; if (((wValue >> 8) & 0xFF) == 0x01) { ret = new byte[1 + arg.DescriptorData.Length + 1 + (_currentDevice.Endpoints.Count * 4)]; ret[0] = (byte)'D'; Array.Copy(arg.DescriptorData, 0, ret, 1, arg.DescriptorData.Length); ret[1 + arg.DescriptorData.Length] = (byte)_currentDevice.Endpoints.Count; for (int i = 0; i < _currentDevice.Endpoints.Count; i++) { ret[1 + arg.DescriptorData.Length + 1 + (i * 4) + 0] = (byte)(_currentDevice.Endpoints[i].Endpoint | (byte)_currentDevice.Endpoints[i].Direction); ret[1 + arg.DescriptorData.Length + 1 + (i * 4) + 1] = (byte)_currentDevice.Endpoints[i].Type; ret[1 + arg.DescriptorData.Length + 1 + (i * 4) + 2] = (byte)(_currentDevice.Endpoints[i].MaximumPacketSize & 0xFF); ret[1 + arg.DescriptorData.Length + 1 + (i * 4) + 3] = (byte)((_currentDevice.Endpoints[i].MaximumPacketSize >> 8) & 0xFF); } } else { ret = new byte[1 + (arg.DescriptorData != null ? arg.DescriptorData.Length : 0)]; ret[0] = (byte)'D'; if (arg.DescriptorData != null) Array.Copy(arg.DescriptorData, 0, ret, 1, arg.DescriptorData.Length); } _Write(ret); break; } case 'I': { Logger.WriteLine("Raw: Received incoming data: " + BitConverter.ToString(e.Buffer, 0, e.Count), Logger.LoggingLevel.Verbose); //Incoming endpoint data received int count = (e.Buffer[0] | (e.Buffer[1] << 8)); if (count > 0) { var data = new byte[count - 2]; Array.Copy(e.Buffer, 4, data, 0, data.Length); _currentDevice.OnIncomingDataReceived(new IncomingDataEventArgs(e.Buffer[3], data)); } break; } default: { Logger.WriteLine("Raw: Received unknown data: " + BitConverter.ToString(e.Buffer, 0, e.Count), Logger.LoggingLevel.Verbose); break; } } }
private void mEp_DataReceived(object sender, EndpointDataEventArgs e) { byte[] buffer = (byte[])e.Buffer.Clone(); // so we dont process duplicates // DataLogger.Instance.LogLine(buffer[30]); if (this.IsDisposed) // stop everything { // This prevents the process from waiting for the processing thread to get done pktHandler.bcWorkQueue.CompleteAdding(); } else { // So we can keep on receiveing USB Packets as fast as possible without being blocked by UI thread pktHandler.bcWorkQueue.Add(buffer); } }
private static void RecievedDataHandler(object sender, EndpointDataEventArgs e) { LastDataEventDate = DateTime.Now; char resp = (char)e.Buffer[0]; int bufSize = (int)((char)e.Buffer[1]); }
private void mEp_DataReceived(object sender, EndpointDataEventArgs e) { OnDataReceived(sender, e); }
void reader_DataReceived(object sender, EndpointDataEventArgs e) { StringBuilder updateLog = new StringBuilder(); //Lots of Magic Numbers Below //index 26 seems to have an incrementing 00-0F, but once I send an event I get a constant 128??? why? oh well ignore it //TODO: Guess Less if (e.Buffer[1] == 2 && e.Buffer[3] == 240 && e.Buffer[24] == 240 && e.Buffer[25] == 4 && (e.Buffer[26] <= 15 || e.Buffer[26]==128)) { //Do nothing, these are normal keep alive responses, I think :) chatPadEventsFlowing = true; } else if (e.Buffer[1] == 2 && e.Buffer[3] == 240 && e.Buffer[24] == 0 && e.Buffer[25] == 0 && (e.Buffer[26] <= 15 || e.Buffer[26] == 128)) { //Do nothing, these are normal keep alive responses, I think :) chatPadEventsFlowing = true; } else if (e.Buffer[1] == 0 && e.Buffer[3] == 240 && e.Buffer[24] == 240 && e.Buffer[25] == 3 && (e.Buffer[26] <= 15 || e.Buffer[26] == 128)) { //Do nothing, these are normal keep alive responses, I think :) //chatPadEventsFlowing = true; } else if (e.Buffer[1] == 0 && e.Buffer[3] == 240 && e.Buffer[24] == 0 && e.Buffer[25] == 0 && (e.Buffer[26] <= 15 || e.Buffer[26] == 128)) { //Do nothing, these are normal keep alive responses, I think :) //chatPadEventsFlowing = true; } else if (e.Buffer[1] == 2 && e.Buffer[3] == 240 && e.Buffer[24] == 0 && e.Buffer[25] == 3 && (e.Buffer[26] <= 15 || e.Buffer[26] == 128)) { //Do nothing, these are normal keep alive responses, I think :) chatPadEventsFlowing = true; } else if (e.Buffer[1] == 0 && e.Buffer[3] == 240 && e.Buffer[24] == 0 && e.Buffer[25] == 4 && (e.Buffer[26] <= 15 || e.Buffer[26] == 128)) { //Do nothing, these are normal keep alive responses, I think :) //chatPadEventsFlowing = true; } else if (e.Buffer[1] == 2 && e.Buffer[3] == 240 && e.Buffer[24] == 240 && e.Buffer[25] == 3 && (e.Buffer[26] <= 15 || e.Buffer[26] == 128)) { //Do nothing, these are normal keep alive responses, I think :) //Wish I knew what I was doing instead of guessing chatPadEventsFlowing = false; //Call these false? something is wrong here } else { if (e.Buffer[1] == 1) //Joystick Data { OutputValidation.OutputMappingForJoyStick(e.Buffer, jController, controllerIndex,deadZone); controllerEventsFlowing = true; } else if (e.Buffer[1] == 2) { if (lastProcessedResponse.AddMilliseconds(120) <= DateTime.Now)// || previousResponse == null)//Make this magic number a config, lower = better response, but more likely to get repeating values { OutputValidation.OutputMappingForChatPad(e.Buffer, cController, controllerIndex,this); lastProcessedResponse = DateTime.Now; chatPadEventsFlowing = true; } } updateLog.Append("Response - "); for (int i = 0; i < 48; i++) { updateLog.Append(e.Buffer[i].ToString()); updateLog.Append(" "); } //SetLog(updateLog.ToString()); ThreadStart startLog = delegate() { Dispatcher.Invoke(DispatcherPriority.Normal, new Action<string>(SetLog), updateLog.ToString()); }; new Thread(startLog).Start(); } }
void HandleDataReceived (object sender, EndpointDataEventArgs e) { lock (readBuffer) { long currentPosition = readBuffer.Position; readBuffer.Position = readBuffer.Length; readBuffer.Write (e.Buffer, 0, e.Count); readBuffer.Position = currentPosition; } }
private static void OnRxEndPointData(object sender, EndpointDataEventArgs e) { LastDataEventDate = DateTime.Now; Console.Write(Encoding.Default.GetString(e.Buffer, 0, e.Count)); }
private void OnDataReceived(object sender, EndpointDataEventArgs e) { if (chkLogToFile.Checked && mLogFileStream != null) { if (ckShowAsHex.Checked) { // get the bytes as a hex string StringBuilder sb = GetHexString(e.Buffer, 0, e.Count); // get the hexstring as bytes and write to log file Byte[] data = Encoding.UTF8.GetBytes(sb.ToString()); mLogFileStream.Write(data, 0, data.Length); } else mLogFileStream.Write(e.Buffer, 0, e.Count); } else { showBytes(e.Buffer, e.Count); } }
private void hci_DataReceived(object sender, EndpointDataEventArgs e) { switch ((HCIEvent)e.Buffer[0]) { case HCIEvent.InquiryComplete: { lock (_completedCommands) { _completedCommands.Add(new Opcode(OpcodeGroupField.LinkControl, OpcodeCommandField.Inquiry)); } break; } case HCIEvent.InquiryResult: { var opcode = new Opcode(OpcodeGroupField.LinkControl, OpcodeCommandField.Inquiry); if (!_commandData.ContainsKey(opcode)) _commandData.Add(opcode, new List<InquiryResult>()); var list = _commandData[opcode] as List<InquiryResult>; int responses = Convert.ToInt32(e.Buffer[2]); int offset = 3; for (int i = 0; i < responses; i++) { list.Add(new InquiryResult(Utilities.GetLEULong(e.Buffer, offset + 0, 6), e.Buffer[offset + 6], e.Buffer[offset + 7], e.Buffer[offset + 8], (uint)Utilities.GetLEULong(e.Buffer, offset + 9, 3), (ushort)Utilities.GetLEULong(e.Buffer, offset + 12, 2))); offset += 14; } break; } case HCIEvent.ConnectionComplete: { Logger.WriteLine("Connection Complete, Status: " + e.Buffer[2].ToString("X2")); ushort connectionHandle = (ushort)(e.Buffer[3] | (e.Buffer[4] << 8)); ulong bdAddr = Utilities.GetLEULong(e.Buffer, 5, 6); //Raise event out if (ConnectionComplete != null) ConnectionComplete(this, new HCIEventEventArgs(e.Buffer, e.Count)); break; } case HCIEvent.DisconnectionComplete: { Logger.WriteLine("Disconnection Complete, Status: " + e.Buffer[2].ToString("X2")); break; } case HCIEvent.ConnectionRequest: { var bdAddr = Utilities.GetLEULong(e.Buffer, 2, 6); var deviceClass = Utilities.GetLEULong(e.Buffer, 8, 3); byte linkType = e.Buffer[11]; Logger.WriteLine(String.Format("Connection Request Received, BD_ADDR {0}, class {1}, link type {2}", bdAddr.ToString("X12"), deviceClass.ToString("X6"), linkType.ToString("X2"))); //Accept this request (or do whatever with it) if (ConnectionRequestReceived != null) ConnectionRequestReceived(this, new HCIEventEventArgs(e.Buffer, e.Count)); break; } case HCIEvent.RemoteNameRequestComplete: { var opcode = new Opcode(OpcodeGroupField.LinkControl, OpcodeCommandField.RemoteNameRequest); if (!_commandData.ContainsKey(opcode)) _commandData.Add(opcode, ASCIIEncoding.ASCII.GetString(e.Buffer, 9, 248).Trim(new char[] {'\0'} )); lock (_completedCommands) { _completedCommands.Add(opcode); } break; } case HCIEvent.QoSSetupComplete: { Logger.WriteLine("QoS Setup Complete"); break; } case HCIEvent.Complete: { var command = new Opcode(e.Buffer, 3); lock (_completedCommands) { _completedCommands.Add(command); } break; } case HCIEvent.Status: { var command = new Opcode(e.Buffer, 4); break; } case HCIEvent.PINCodeRequestEvent: { var bdAddr = Utilities.GetLEULong(e.Buffer, 2, 6); //Send the reply SendPINCodeReply(bdAddr, String.Empty); break; } default: { //Uh? Logger.WriteLine("Unknown HCI event: " + e.Buffer[0].ToString("X2")); break; } } }
private void HeadsetReader_DataReceived(object sender, EndpointDataEventArgs e) { var buffer = new byte[e.Count]; Array.Copy(e.Buffer, 0, buffer, 0, buffer.Length); UsbEndpointReader reader = sender as UsbEndpointReader; if (reader != null) { //Find the slot this belongs to int? index = null; foreach (var slot in _slots) { if (slot.Value.DataReader == reader) { index = slot.Key; break; } } if (index.HasValue) { if (HeadsetDataReceived != null) HeadsetDataReceived(this, new DataReceivedEventArgs(index.Value, buffer)); } } }
private void reader_DataReceived(object sender, EndpointDataEventArgs e) { Logger.WriteLine("Incoming: " + BitConverter.ToString(e.Buffer, 0, e.Count)); lock (_writer) { Logger.LogData('O', e.Buffer, 0, e.Count); } if (IncomingDataReceived != null) IncomingDataReceived(this, new HCIEventEventArgs(e.Buffer, e.Count)); }
private void USB_DataReceived(object sender, EndpointDataEventArgs e) { Int16 valueTemp = e.Buffer[0]; double value = ((double)valueTemp / 613) * 3.6; if (indexSignalData > (dataBuffer - 1)) { for (int i = 0; i < (dataBuffer - 1); i++) { SignalData[i] = SignalData[i + 1]; } SignalData[(dataBuffer - 1)] = value; } else { SignalData[indexSignalData] = value; indexSignalData++; } //OnDataChange(this, new OSequenceDataUpdateEventArgs(signalData)); }
private static void ReaderOnDataReceived(object sender, EndpointDataEventArgs endpointDataEventArgs) { Console.WriteLine("Data received on ep01."); Console.WriteLine(endpointDataEventArgs.Buffer); }