I tried to write 'native' VB code for my I²C connection, so not using any custom class or wrapper like the Toolbox. Here's what I came up with:
Dim outbytes() As Byte = New Byte() {} Dim inbytes(6) As Byte '= New Byte() {} Dim cfg As New I2CDevice.Configuration(80, 400) Dim iic As New I2CDevice(cfg) outbytes = New Byte() {160, 1, 1} Dim write_transaction As I2CDevice.I2CTransaction = I2CDevice.CreateWriteTransaction(outbytes) Dim read_transaction As I2CDevice.I2CTransaction = I2CDevice.CreateReadTransaction(inbytes) Dim transActionList As I2CDevice.I2CTransaction() = New I2CDevice.I2CTransaction() {write_transaction, read_transaction} Dim i As Integer = iic.Execute(transActionList, 5000)
The good thing is: this code does NOT result in an error. It seems the array that will contain the read bytes should have a fixed size. That makes sense, in retrospect. So after defining the size of this array, the exception was gone.
The bad thing is: the inbytes array is not filled with valid data but stays filled with zeroes.
FWIW, the device I'm trying to interface with is here (RFID reader).
EDIT after 2 hours of more testing and trying.
This line of code:
Dim i As Integer = iic.Execute(transActionList, 1000)[/code]
returns 1 WITH 10k or 2k2 pull ups
returns 3 WITHOUT these pull ups.
I'd say 3 is correct because of 3 items in outbytes. The inbytes array does not change, unfortunately.
Any clues?
- Franki