I2C read in C#

All about Sub-20 Multi Interface USB Adapter USB to I2C, SPI, GPIO, RS232, RS485, Ir, LCD

Moderator: serg

Post Reply
pgans
Posts: 1
Joined: Fri Dec 11, 2009 11:00 pm

I2C read in C#

Post by pgans »

I'm having problems declaring the variable used in the I2C_read command.

I'm sure it is a simple fix, but I cannot quite get it figured out.

doesWork = i2cDevice.I2C_Read(device.SlaveAddress, memoryAddress, 0, ref theData)

how do I declare theData? The previous read is just trying to read from the default pointer.

Thanks!

serg
Posts: 143
Joined: Mon Aug 31, 2009 9:17 pm

Re: I2C read in C#

Post by serg »

You don't need the "ref" keyword and in case of MemoryAddressSize==0 you can pass 0 for the MemoryAddress parameter.

byte[] theData = new byte[32];
doesWork = i2cDevice.I2C_Read(device.SlaveAddress, 0, 0, theData);

For more information see .NET/SUB-20 documentation and C# sample application under SUB-20\sample\.NET\c#
Regards

Post Reply