Esempio n. 1
0
        private async Task RequestPortProperties(PortInfo port)
        {
            lock (lockObject)
            {
                SentMessages += 2;
            }

            await _protocol.SendMessageAsync(new PortInformationRequestMessage()
            {
                HubId = _hubId, PortId = port.PortId, InformationType = PortInformationType.ModeInfo,
            });

            await _protocol.SendMessageAsync(new PortInformationRequestMessage()
            {
                HubId = _hubId, PortId = port.PortId, InformationType = PortInformationType.PossibleModeCombinations,
            });
        }
Esempio n. 2
0
    public static async Task <TResultMessage> SendMessageReceiveResultAsync <TResultMessage>(this ILegoWirelessProtocol self, LegoWirelessMessage message, Func <TResultMessage, bool> filter = default)
    {
        var awaitable = self.UpstreamMessages
                        .OfType <TResultMessage>()
                        .Where(resultMessage => filter is null || filter(resultMessage))
                        .FirstAsync()
                        .GetAwaiter(); // make sure the subscription is present at the moment the message is sent.

        await self.SendMessageAsync(message);

        var result = await awaitable;

        return(result);
    }