public void SendBytes(byte[] bytes) { if (visualizer != null) { visualizer.AddValue(bytes); } if (serialPort == null || !serialPort.IsOpen) { return; } byte[] buffer = new byte[bytes.Length]; Array.Copy(bytes, buffer, bytes.Length); serialPort.Write(buffer, 0, buffer.Length); }
private async void WriteBytes(byte[] bytes) { visualizer.AddValue(bytes); if (motorCharacteristic == null) { return; } var writer = new DataWriter(); long startTime = Environment.TickCount; Console.WriteLine(startTime + " Sending " + Utils.ByteArrayToString(bytes)); writer.WriteBytes(bytes); GattCommunicationStatus status = await motorCharacteristic.WriteValueAsync(writer.DetachBuffer()); //TODO catch Exception after disconnect long endTime = Environment.TickCount; Console.WriteLine(endTime + " Status for " + Utils.ByteArrayToString(bytes) + ": " + status + ". Time: " + (endTime - startTime) + " ms"); }