[英]Using IS_Nrf24L01 nuget package for Windows 10 IoT Core
May I know how to use this nuget package "IS_nRF24l01p" . 我可以知道如何使用这个nuget包“IS_nRF24l01p”。 I have figured out the command and variable to be declared so that the device can use the NRF24L01p module.
我已经找到要声明的命令和变量,以便设备可以使用NRF24L01p模块。 But as a beginner in coding, I dont really familiar with the syntax and so on.
但作为编码的初学者,我真的不熟悉语法等等。 I just want to do a simple "Hello World".
我只想做一个简单的“Hello World”。 But I am stuck at the initialization step.
但我陷入了初始化步骤。 I follow some tutorial from this website https://technoblogiot.wordpress.com/2016/12/27/raspberry-pi-et-le-controller-driver/ But it is in Vb.
我按照这个网站的一些教程https://technoblogiot.wordpress.com/2016/12/27/raspberry-pi-et-le-controller-driver/但是它在Vb中。 But I have to code in C#.
但我必须用C#编写代码。 Can anyone teach me on how to do the step like this?
任何人都可以教我如何做这样的步骤? Declare the settings for nrf24L01.
声明nrf24L01的设置。 Thanks in advance.
提前致谢。
The command and variable in Vb Vb中的命令和变量
Namespace IS_nRF24L01p Public Class nRF24L01P Implements IDisposable 命名空间IS_nRF24L01p公共类nRF24L01P实现IDisposable
Public NordicChipEnablePin As GpioPin
Public NordicSPI As SpiDevice
Public Sub New(SPI As SpiConnectionSettings, Speed As Integer, ChipEnablePin As Integer, InterruptPin As Integer)
Public Overridable Property timer_SPI As DispatcherTimer
Public Overridable Property NordicInterruptPin As GpioPin
'
' Summary:
' Occurs when data is successfully transmitted.
'
' Parameters:
' sender:
'
' e:
Public Event OnTransmitSuccess As OnTransmitSuccessEventHandler
'
' Summary:
' Occurs when data is received.
'
' Parameters:
' sender:
'
' e:
Public Event OnTransmitFailed As OnTransmitFailedEventHandler
'
' Summary:
' Occurs when data is received with bad payload.
'
' Parameters:
' sender:
'
' e:
Public Event OnDataReceiveFailed As OnDataReceiveFailedEventHandler
'
' Summary:
' Occurs when data is received.
'
' Parameters:
' sender:
'
' e:
Public Event OnDataReceived As OnDataReceivedEventHandler
Public Sub SetChipEnable(value As Boolean)
Public Sub Dispose() Implements IDisposable.Dispose
Public Sub FlushRXFIFO()
Public Sub WritePayload(data() As Byte)
Public Sub WriteRegister(register As Common.Registers, data() As Byte)
Public Sub SetRegisterBit(ByRef registerByte As Byte, value As Boolean, index As Integer)
Protected Overridable Sub Dispose(disposing As Boolean)
Public Function ReadRXFIFOWidth() As Byte
Public Function FlushTXFIFO() As Byte()
Public Function ReadRegister(register As Common.Registers, Optional size As Byte = 1) As Byte()
Public Function ReadFIFO(width As Byte) As Byte()
Public Class DataReceiveFailedEventArgs
Inherits EventArgs
Public DataPipe As Byte
Public Status As Byte
Public Sub New(DataPipe As Byte, Status As Byte)
End Class
Public Class DataReceivedEventArgs
Inherits EventArgs
Public DataPipe As Byte
Public Payload As Byte()
Public Sub New(DataPipe As Byte, Payload() As Byte)
End Class
Public Class DataTransmitFailedEventArgs
Inherits EventArgs
Public Status As Byte
Public Sub New(Status As Byte)
End Class
Public Delegate Sub OnDataReceivedEventHandler(sender As Object, e As DataReceivedEventArgs)
Public Delegate Sub OnDataReceiveFailedEventHandler(sender As Object, e As DataReceiveFailedEventArgs)
Public Delegate Sub OnTransmitFailedEventHandler(sender As Object, e As DataTransmitFailedEventArgs)
Public Delegate Sub OnTransmitSuccessEventHandler(sender As Object, e As EventArgs)
End Class
End Namespace 结束命名空间
All I have to do is to declare this in C# 我所要做的就是在C#中声明这一点
Public NotInheritable Class MainPage
Inherits Page
Public WithEvents MTPNordic As nRF24L01P
Public Sub New()
InitializeComponent()
Setup()
End Sub
Private Sub Setup()
Debug.WriteLine("Program Started")
Debug.WriteLine("Initialize MTPNordic")
MTPNordic = New nRF24L01P(New SpiConnectionSettings(0), 3000000, 12, 13)
End Sub
The command and variable in C# C#中的命令和变量
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Windows.Devices.Gpio;
using Windows.Devices.Spi;
using Windows.UI.Xaml;
namespace IS_nRF24L01p
{
public class nRF24L01P : IDisposable
{
public GpioPin NordicChipEnablePin;
public SpiDevice NordicSPI;
public nRF24L01P();
public virtual DispatcherTimer timer_SPI { get; set; }
public virtual GpioPin NordicInterruptPin { get; set; }
//
// Summary:
// Pipe 5 address. Takes only the LSB. Data pipes 1-5 share the most significant
// address bytes.
public byte Pipe_5_Address { get; set; }
//
// Summary:
// Pipe 4 address. Takes only the LSB. Data pipes 1-5 share the most significant
// address bytes.
public byte Pipe_4_Address { get; set; }
//
// Summary:
// Pipe 3 address. Takes only the LSB. Data pipes 1-5 share the most significant
// address bytes.
public byte Pipe_3_Address { get; set; }
//
// Summary:
// Pipe 2 address. Takes only the LSB. Data pipes 1-5 share the most significant
// address bytes.
public byte Pipe_2_Address { get; set; }
//
// Summary:
// Pipe 1 address. 5 bytes maximum.
public byte[] Pipe_1_Address { get; set; }
//
// Summary:
// Pipe 0 address. 5 bytes maximum.
public byte[] Pipe_0_Address { get; set; }
//
// Summary:
// RF Speed
public Common.RFSpeed Speed { get; set; }
//
// Summary:
// RF address width.
public Common.AddressWidth AddressWidth { get; set; }
//
// Summary:
// RF channel frequency. It determines the center of the channel used by the nRF24L01p.
// Number from 0 to 125 are allowed.
public byte ChannelFreq { get; set; }
//
// Summary:
// RF db Power
public Common.dbPower dbPower { get; set; }
//
// Summary:
// Occurs when data is successfully transmitted.
//
// Parameters:
// sender:
//
// e:
public event OnTransmitSuccessEventHandler OnTransmitSuccess;
//
// Summary:
// Occurs when data is received.
//
// Parameters:
// sender:
//
// e:
public event OnTransmitFailedEventHandler OnTransmitFailed;
//
// Summary:
// Occurs when data is received with bad payload.
//
// Parameters:
// sender:
//
// e:
public event OnDataReceiveFailedEventHandler OnDataReceiveFailed;
//
// Summary:
// Occurs when data is received.
//
// Parameters:
// sender:
//
// e:
public event OnDataReceivedEventHandler OnDataReceived;
public void Dispose();
//
public void FlushRXFIFO();
//
public byte[] FlushTXFIFO();
//
// Parameters:
// SPI:
//
// Speed:
//
// ChipEnablePin:
//
// InterruptPin:
//
// SPIDesc:
[AsyncStateMachine(typeof(VB$StateMachine_71_InitNordicSPI))]
[DebuggerStepThrough]
public Task InitNordicSPI(SpiConnectionSettings SPI, int Speed, int ChipEnablePin, int InterruptPin, string SPIDesc = "");
//
// Parameters:
// width:
public byte[] ReadFIFO(byte width);
//
// Parameters:
// register:
//
// size:
public byte[] ReadRegister(Common.Registers register, byte size = 1);
//
public byte ReadRXFIFOWidth();
//
// Summary:
// Used to send data to another nRF24L01p enabled module
//
// Parameters:
// Message:
// Bytes array containing the message to send
//
// TX_ADDR:
// Bytes array containing the address of destination device
public void SendPayload(byte[] Message, ref byte[] TX_ADDR);
//
// Summary:
// Set the nRF24L01p as a Receiver
public void SetAsPRX();
//
// Summary:
// Set the nRF24L01p as a Transmitter
//
// Parameters:
// TX_ADDR:
public void SetAsPTX(ref byte[] TX_ADDR);
//
// Parameters:
// value:
public void SetChipEnable(bool value);
//
// Parameters:
// registerByte:
//
// value:
//
// index:
public void SetRegisterBit(ref byte registerByte, bool value, int index);
//
// Parameters:
// data:
public void WritePayload(byte[] data);
//
// Parameters:
// register:
//
// data:
public void WriteRegister(Common.Registers register, byte[] data);
protected virtual void Dispose(bool disposing);
public class DataReceiveFailedEventArgs : EventArgs
{
public byte DataPipe;
public byte Status;
public DataReceiveFailedEventArgs(byte DataPipe, byte Status);
}
public class DataReceivedEventArgs : EventArgs
{
public byte DataPipe;
public byte[] Payload;
public DataReceivedEventArgs(byte DataPipe, byte[] Payload);
}
public class DataTransmitFailedEventArgs : EventArgs
{
public byte Status;
public DataTransmitFailedEventArgs(byte Status);
}
public delegate void OnDataReceivedEventHandler(object sender, DataReceivedEventArgs e);
public delegate void OnDataReceiveFailedEventHandler(object sender, DataReceiveFailedEventArgs e);
public delegate void OnTransmitFailedEventHandler(object sender, DataTransmitFailedEventArgs e);
public delegate void OnTransmitSuccessEventHandler(object sender, EventArgs e);
}
}
All I have to do is to declare this in C#
我所要做的就是在C#中声明这一点
Get started with UWP application template to create a simple UWP application . 开始使用UWP应用程序模板来创建一个简单的UWP应用程序 。
Add a Setup() method and instance a nRF24L01P object and configure some settings. 添加Setup()方法并实例化nRF24L01P对象并配置一些设置。
In MainPage.xaml.cs the code will like this: 在MainPage.xaml.cs中,代码将如下所示:
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
Setup();
}
public void Setup()
{
System.Diagnostics.Debug.WriteLine("Initialize MTPNordic");
IS_nRF24L01p.nRF24L01P nRf24 = new nRF24L01P();
// Use chip select line CS0; SPI speed set to 3 MHz; SPI0 CS0 is 8; Interrupt GPIO selected GPIO 5
nRf24.InitNordicSPI(new SpiConnectionSettings(0), 3000000, 8, 5);
}
}
Note: Above is answering your question simple because I don't know how InitNordicSPI implement (if it initialize the SPI and GPIO internally) so maybe you need initialize SPI and GPIO for interrupt by yourself. 注意:上面简单回答你的问题,因为我不知道InitNordicSPI是如何实现的(如果它在内部初始化SPI和GPIO),那么你可能需要自己初始化SPI和GPIO来进行中断。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.