Exemplo n.º 1
0
        private async Task SetupCommunication()
        {
            serialDevice = await SerialCommunicationHelper.GetFirstDeviceAvailable();

            SerialCommunicationHelper.SetDefaultConfiguration(serialDevice);
            new Task(CommunicationListener).Start();
        }
        private async Task SendCommand(CommandId commandId)
        {
            if (serialDevice != null)
            {
                byte[] command = null;

                switch (commandId)
                {
                case CommandId.BlinkingFrequency:
                    command = CommandHelper.PrepareSetFrequencyCommand(hzBlinkingFrequency);
                    break;

                case CommandId.BlinkingStatus:
                    command = CommandHelper.PrepareBlinkingStatusCommand(isLedBlinking);
                    break;
                }

                await SerialCommunicationHelper.WriteBytes(serialDevice, command);

                DiagnosticInfo.Display(diagnosticData, "Data written: " + CommandHelper.CommandToString(command));
            }
            else
            {
                DiagnosticInfo.Display(diagnosticData, "No active connection");
            }
        }
        private async Task GetDeviceList()
        {
            var serialDevices = await SerialCommunicationHelper.FindSerialDevices();

            foreach (var deviceInformation in serialDevices)
            {
                devicesList.Add(deviceInformation);
            }
        }
        private async Task SetupConnection()
        {
            //CLose any previous connections before associating the new one
            CloseConnection();
            serialDevice = await SerialDevice.FromIdAsync(serialDeviceId);

            if (serialDevice != null)
            {
                //Configure connection
                SerialCommunicationHelper.SetDefaultConfiguration(serialDevice);
            }
        }
        private async Task SetupConnection()
        {
            // 새로운 연결을 시도하기 전에 이전 연결을 모두 닫는다
            CloseConnection();

            serialDevice = await SerialDevice.FromIdAsync(serialDeviceId);

            if (serialDevice != null)
            {
                // 연결 구성
                SerialCommunicationHelper.SetDefaultConfiguration(serialDevice);
            }
        }
        private async Task InitializeDevice()
        {
            if (serialDevice == null)
            {
                serialDevice = await SerialCommunicationHelper.GetFirstDeviceAvailable();

                SerialCommunicationHelper.SetDefaultConfiguration(serialDevice);

                if (serialDevice != null)
                {
                    dataWriter = new DataWriter(serialDevice.OutputStream);
                    dataReader = new DataReader(serialDevice.InputStream);
                }
            }
        }
        private async void ButtonSendColor_Click(object sender, RoutedEventArgs e)
        {
            if (streamSocket != null)
            {
                var commandData = CommandHelper.PrepareLedColorCommand(senseHatColor.Brush.Color);

                await SerialCommunicationHelper.WriteBytes(streamSocket.OutputStream, commandData);

                DiagnosticInfo.Display(diagnosticData, CommandHelper.CommandToString(commandData));
            }
            else
            {
                DiagnosticInfo.Display(diagnosticData, "No active connection");
            }
        }
Exemplo n.º 8
0
        private async void CommunicationListener()
        {
            while (true)
            {
                var commandReceived = await SerialCommunicationHelper.ReadBytes(serialDevice);

                try
                {
                    ParseCommand(commandReceived);
                }
                catch (Exception ex)
                {
                    DiagnosticInfo.Display(null, ex.Message);
                }
            }
        }
        private async void CommunicationListener()
        {
            const int msSleepTime = 50;

            while (true)
            {
                var commandReceived = await SerialCommunicationHelper.ReadBytes(streamSocket.InputStream);

                try
                {
                    if (commandReceived.Length > 0)
                    {
                        ParseCommand(commandReceived);
                    }
                }
                catch (Exception ex)
                {
                    DiagnosticInfo.Display(null, ex.Message);
                }

                Task.Delay(msSleepTime).Wait();
            }
        }