public void Initialize() { GpioController gpioController = GpioController.GetDefault(); GpioPin powerPin = gpioController.InitGpioPin(4, GpioPinDriveMode.Output, GpioSharingMode.Exclusive); //4 GpioPin cePin = gpioController.InitGpioPin(22, GpioPinDriveMode.Output, GpioSharingMode.Exclusive); //22 GpioPin irqPin = gpioController.InitGpioPin(25, GpioPinDriveMode.InputPullUp, GpioSharingMode.Exclusive); //25 powerPin.Write(GpioPinValue.Low); cePin.Write(GpioPinValue.Low); irqPin.Write(GpioPinValue.High); DeviceInformationCollection devicesInfo = DeviceInformation.FindAllAsync(SpiDevice.GetDeviceSelector("SPI0")).GetAwaiter().GetResult(); SpiDevice spiDevice = SpiDevice.FromIdAsync(devicesInfo[0].Id, new SpiConnectionSettings(0)).GetAwaiter().GetResult(); ICommandProcessor commandProcessor = new CommandProcessor(spiDevice); ILoggerFactoryAdapter loggerFactoryAdapter = new DebugOutLoggerFactoryAdapter(LogLevel.All, true, true, true, "MM/dd/yyyy hh:mm:ss fffff"); _radio = new Radio(commandProcessor, loggerFactoryAdapter, powerPin, cePin, irqPin); _sendReceiveRole = new SenderReceiverRole(); _sendReceiveRole.AttachRadio(_radio); _sendReceiveRole.DataArrived += DataArrived;; _sendReceiveRole.SendAddress = SendAddress; _sendReceiveRole.ReceiveAddress = ReceiveAddress; _sendReceiveRole.Start(); ThreadPoolTimer.CreatePeriodicTimer(Handler, TimeSpan.FromSeconds(5)); WaitForData(); }
public void SenderReceiverTest() { SenderReceiverRole senderReceiver = new SenderReceiverRole(); senderReceiver.AttachRadio(_radio); senderReceiver.DataArrived += DataArrived;; senderReceiver.SendAddress = _sendAddress; senderReceiver.ReceiveAddress = _receiveAddress; senderReceiver.Start(); int count = 0; while (true) { string content = "Payload, Count=" + (count++); lock (_syncRoot) { Debug.WriteLine(senderReceiver.Send(Encoding.UTF8.GetBytes(content).ReverseBytes(), 5000) ? "Data sent success." : "Failed to send data. " + (senderReceiver.MaxRetries ? "MaxRetries" : "Timeout")); } Task.Delay(1000).Wait(); } }