Пример #1
0
        static void Main()
        {
            RF24 radio        = new RF24();
            byte messageCount = System.Byte.MaxValue;

            try
            {
                radio.OnDataReceived    += Radio_OnDataReceived;
                radio.OnTransmitFailed  += Radio_OnTransmitFailed;
                radio.OnTransmitSuccess += Radio_OnTransmitSuccess;

#if NETDUINO3_WIFI
                radio.Initialize("SPI2", PinNumber('A', 2), PinNumber('A', 1), PinNumber('A', 3));
#endif
                radio.Address = Encoding.UTF8.GetBytes(DeviceAddress);

                radio.Channel = 15;
                //radio.PowerLevel = PowerLevel.Max;
                //radio.PowerLevel = PowerLevel.High;
                //radio.PowerLevel = PowerLevel.Low;
                radio.PowerLevel = PowerLevel.Minimum;
                radio.DataRate   = DataRate.DR250Kbps;
                //radio.DataRate = DataRate.DR1Mbps;
                //radio.DataRate = DataRate.DR2Mbps;
                radio.IsEnabled = true;

                radio.IsAutoAcknowledge    = true;
                radio.IsDyanmicAcknowledge = false;
                radio.IsDynamicPayload     = true;

                Debug.WriteLine($"Address: {Encoding.UTF8.GetString(radio.Address, 0, radio.Address.Length)}");
                Debug.WriteLine($"PowerLevel: {radio.PowerLevel}");
                Debug.WriteLine($"IsAutoAcknowledge: {radio.IsAutoAcknowledge}");
                Debug.WriteLine($"Channel: {radio.Channel}");
                Debug.WriteLine($"DataRate: {radio.DataRate}");
                Debug.WriteLine($"IsDynamicAcknowledge: {radio.IsDyanmicAcknowledge}");
                Debug.WriteLine($"IsDynamicPayload: {radio.IsDynamicPayload}");
                Debug.WriteLine($"IsEnabled: {radio.IsEnabled}");
                Debug.WriteLine($"Frequency: {radio.Frequency}");
                Debug.WriteLine($"IsInitialized: {radio.IsInitialized}");
                Debug.WriteLine($"IsPowered: {radio.IsPowered}");

                while (true)
                {
                    string payload = $"hello {messageCount}";
                    messageCount -= 1;

                    Debug.WriteLine($"{DateTime.UtcNow:HH:mm:ss}-TX {payload.Length} byte message {payload}");
                    radio.SendTo(Encoding.UTF8.GetBytes(BaseStationAddress), Encoding.UTF8.GetBytes(payload));

                    Thread.Sleep(30000);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }