/// <summary> /// Sends message via mavlink protocol asynchronously /// </summary> /// <param name="message">Message to be sent</param> /// <param name="systemId">Id of a system which is sending message</param> /// <param name="componentId">Id of a component which is sending message</param> /// <param name="sequenceNumber"></param> /// <returns>Value which indicates whether operation completed successfully</returns> public bool SendMessage <TMessage>(TMessage message, byte systemId, byte componentId, byte sequenceNumber = 1) where TMessage : struct, IMessage { byte[] packetPayload = _messageFactory.CreateBytes(message); Packet packet = _packetHandler.GetPacket(systemId, componentId, sequenceNumber, message.Id, packetPayload); if (packet == null) { return(false); } try { lock (_syncRoot) _stream.Write(packet.RawBytes, 0, packet.RawBytes.Length); return(true); } catch { return(false); } }