public void Send(TXPacket p) { UsbSetupPacket sup = new UsbSetupPacket(0x40, 0x10, 0, 0, (short)(p.Payload.Length + 6)); byte[] buffer = new byte[p.Payload.Length + 6]; buffer[0] = (byte)p.Payload.Length; if (p.AutoAcknowledge) { buffer[0] |= 1 << 6; } p.Address.CopyTo(buffer, 1); p.Payload.CopyTo(buffer, 6); int len; dev.ControlTransfer(ref sup, buffer, buffer.Length, out len); if (len != buffer.Length) { throw new Exception($"{len} bytes transferred instead of {buffer.Length}"); } }
private void buttonSend_Click(object sender, RoutedEventArgs e) { TXPacket p = new TXPacket(); p.Payload = new byte[comboBoxSendCount.SelectedIndex + 1]; for (int i = 0; i < comboBoxSendCount.SelectedIndex + 1; i++) { p.Payload[i] = txBuffer[i].Value; } for (int i = 0; i < 5; i++) { p.Address[i] = txAddr[i].Value; } p.AutoAcknowledge = checkBoxAutoAcknowledge.IsChecked.Value; try { radio.Send(p); } catch (Exception ex) { Disconnect(); MessageBox.Show("Error sending Packet:\n" + ex.Message); } }