Windows iot (c#) - Raspberry PI - I2C
本文关键字:Raspberry I2C PI iot Windows | 更新日期: 2023-09-27 18:35:25
1.我尝试使用Raspberry Pi作为主节点,使用PIC16F1847作为从属。从站向主站发送 50 个字节。但是,我在 C# 编程方面遇到了问题。下来的C#代码不被接受,"y"数组。谁能帮忙?2.这是代码:
private I2cDevice PicDevice;
public class StartSpanning
{
public string Name { get; set; }
public int Amount { get; set; }
}
public MainPage()
{
this.InitializeComponent();
this.Loaded += MainPage_Loaded;
initI2c();
}
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
LoadChartContents();
}
async void initI2c()
{
string i2c1 = I2cDevice.GetDeviceSelector(); // Get a selector string that will return all I2C controllers on the system
var devices = await DeviceInformation.FindAllAsync(i2c1);
var I2Csettings = new I2cConnectionSettings(0x05); // Adrress PIC
I2Csettings.BusSpeed = I2cBusSpeed.StandardMode; // 100KHz bus speed
PicDevice = await I2cDevice.FromIdAsync(devices[0].Id, I2Csettings);
byte[] y = new byte[50];
var result = PicDevice.ReadPartial(y);
}
private void LoadChartContents()
{
List<StartSpanning> lijst_spanning = new List<StartSpanning>();
lijst_spanning.Add(new StartSpanning() { Name = "1", Amount = y[0] });
lijst_spanning.Add(new StartSpanning() { Name = "2", Amount = y[1] });
lijst_spanning.Add(new StartSpanning() { Name = "3", Amount = y[2] });
lijst_spanning.Add(new StartSpanning() { Name = "4", Amount = y[3] });
lijst_spanning.Add(new StartSpanning() { Name = "5", Amount = y[4] });
lijst_spanning.Add(new StartSpanning() { Name = "6", Amount = y[5] });
lijst_spanning.Add(new StartSpanning() { Name = "7", Amount = y[6] });
看起来 y 已在 initI2c 方法中声明,因此无法从 LoadChartContents 方法调用。