function [Packet,Error] = i3dmgx2_WriteEEPROMValue(SerialLink,EEPROMAddress,EEPROMWord)
%Writes word to sensor's EEPROM
%
%Arguments: SerialLink - Handle of serial link
%           EEPROMAddress - Vector with address of EEPROM word
%           EEPROMWord - Vector with word to be written to EEPROM
%
%Returns:   Packet - The data packet
%           Error - Error number

Error = purgePort(SerialLink); %Clear buffer
if Error == 0
    Error = i3dmgx2_SendBuffData(SerialLink,'CMD_WRITE_WORD_EEPROM'); %Write command to device
    if Error == 0
        for ByteNum = 1:length(EEPROMAddress)
            fwrite(SerialLink,EEPROMAddress(ByteNum)) %Write EEPROM address to device
        end
        for ByteNum = 1:length(EEPROMWord)
            fwrite(SerialLink,EEPROMWord(ByteNum)) %Write EEPROM word to device
        end
        [Packet,Error] = i3dmgx2_ReceiveData(SerialLink,'CMD_WRITE_WORD_EEPROM'); %Read EEPROM word from device
        if Error ~= 0
            Packet = [];
        end
    end
else
    Packet = [];
end