#include<Wire.h>
#define slaveAddress 0x20

//Read Output Current and Lens Temperature

byte dataArray_WriteVectorAddressIndex[12] = {0x28, 0x01, 0x00, 0x00, 0x20, 0x01, 0x28, 0x02, 0x00, 0x00, 0x00, 0x00};  // Vector adapter Address - Board SN 0x2001 (Device SN 0x2101) and index 0x2802 setting to 0.
byte dataArray_ReadVectorDataIndex[12] = {0x31, 0x00, 0x00, 0x00, 0x28, 0x00, 0x31, 0x01, 0x00, 0x00, 0x28, 0x02};   // Reply - First 6 bytes are associated with Vector data buffer (0x2800) and other 6 bytes to index count.
byte dataArray_ReadTrigger[12] = {0x28, 0x05, 0x00, 0x00, 0x00, 0x01, 0x31, 0x00, 0x00, 0x00, 0x28, 0x00};   // Writing a value to 0x2805 register triggers loading the data to Vector data buffer at 0x2800 address, other 6 bytes are just duplicated from previous send command. 

int start = 0;
void setup() {
Wire.begin(); //initialise I2C
Serial.begin(9600);
}
void loop() {

if (start == 0){ // only run once

delay (100);
Wire.beginTransmission(slaveAddress);
for (int i=0; i<12; i++)
{
Wire.write(dataArray_WriteVectorAddressIndex[i]);
} // end of for

Wire.endTransmission();

delay (100);
Wire.beginTransmission(slaveAddress);
for (int i=0; i<12; i++)
{
Wire.write(dataArray_ReadVectorDataIndex[i]);
} // end of for

Wire.endTransmission();

delay (100);
Wire.beginTransmission(slaveAddress);
for (int i=0; i<12; i++)
{
Wire.write(dataArray_ReadTrigger[i]); //triggers queing 4 bytes of SN to Vector data buffer
} // end of for

Wire.endTransmission();

delay (2);
Wire.requestFrom(slaveAddress, 12); // request 12 bytes from slave device
while(Wire.available()){ // slave may send less than requested
Serial.println(Wire.read(),HEX);
}

delay (100);
Wire.beginTransmission(slaveAddress);
for (int i=0; i<12; i++)
{
Wire.write(dataArray_ReadTrigger[i]); //data bytes are queued in Vector data buffer
} // end of for

Wire.endTransmission();

delay (2);
Wire.requestFrom(slaveAddress, 12); // request 12 bytes from slave device
while(Wire.available()){ // slave may send less than requested
Serial.println(Wire.read(),HEX);
}

start = 1;
} // end of if
} // end of loop