Reputation: 49
1.I try to use a Raspberry Pi as a master with a PIC16F1847 as a slave. The slave send 50 bytes to the master. However, I have a problem with the C # programming. Down the C # code is not accepted, the "y" -array. Can anyone help? 2.This is the code:
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] });
Upvotes: 0
Views: 310
Reputation: 799
It looks like y has been declared inside the initI2c method thus it can't be called from the LoadChartContents method.
Upvotes: 1