Hi, I’m awaiting the delivery of my panda, and in the meantime I’m getting the code ready.
Is it possible to test I2C code without the physical device?
And while I’m here, whats wrong with this? I really can’t work out why it’s complaining, it throws an System.ArgumentNullException.
I2CDevice.I2CTransaction[] xActions = new I2CDevice.I2CTransaction[7];
byte[] Cps_adr = new byte[1] { data_adr };
xActions[0] = I2CDevice.CreateWriteTransaction(Cps_adr);
byte[][] Cps_val = new byte[6][];
for (int i = 1; i <= 6; i++)
{
xActions[i] = I2CDevice.CreateReadTransaction(Cps_val[i-1]);
}
The exception is thrown on the first iteration of the for loop, so when i = 1.
Btw in case you’re wondering, the device increments the read address itself each time it is accessed, so hopefully if I send 6 reads, I should be able to read the 6 registers containing data.
I thought that’s it’s after, an empty byte array to use as a buffer?
CreateReadTransaction(byte[] buffer) - I assumed its asking for an empty byte to receive the data. What would be the correct way of making it do what I want? (I’m after an array containing the 6 registers, 3-8)
And thanks Ian, I’ll look into the sample one.
Edit: Sorry, where do I get the sample folder from?
You have allocated an array that has 6 null references.
byte[][] Cps_val = new byte[6][];
You have to do another loop to allocate actual byte arrays
CreatReadTransaction expects a buffer (doesn’t matter if it is empty or not),but you have to allocate it.
for( int i = 0; i < 6; i++)
{
//you need to allocate enough space here, make sure the buffer is big enough
//change 2 to whatever is expected
Cps_val[i] = new byte[2];
}
And thats rather cumbersome, that loop, but I guess thats typical for microsoft - Still, microsoft or not, Im suprised I can’t do byte[6][1], which is what i tried to start with.
According to the Wikipedia [url]http://en.wikipedia.org/wiki/.NET_Micro_Framework[/url] NETMF does not support multi-dimensional arrays at all. So I’m surprised the code even compiled/linked. Perhaps suitable error checking doesn’t exist to flag this at compile time.
Thanks for all the input guys, but since everyone is being rather sketchy about this, is it because everyone else does it a certain other way and I’m just going about this completely the wrong way? How would you guys do it? In general what do you use to store linked data in NETMF?
Xarren… On fezzer you’ll find loads of different drivers for compases, RTC’s Eeproms and loads more… This is the beauty of this forum… we’re all helping each other…
Write some code… Paste it here… and we’ll all help you…
There are a number of data storage options… bec_a_fuel (chris) has just finished an I2C eeprom driver… up to 2048 megabit (256k) data storage.
Wire up an SD card and you’ll find drivers all ready built in (several users have connected SD cards to panda )
NETMF does support ArrayList though. So you can create an ArrayList of any flavor of array (any object for that matter), Which gives you in effect a 2D array.