public void WriteProfile(int whichProfile, LightingProfile profile) { if (!connectionEstablished) { throw new NoKeypadConnectedException("Error: Trying to call serial interface method WriteProfile before connection is established"); } if ((whichProfile >= 1 && whichProfile <= 5) == false) { throw new ArgumentException("Profile must be in range [1,5]"); } if (profile == null) { throw new ArgumentException("Cannot write a null profile."); } #if KP keypadPort.WriteLine("write profile"); Ack(); keypadPort.WriteLine(whichProfile.ToString()); Ack(); keypadPort.Write(profile.Serialize(), 0, 192); Ack(); #else var profileData = profile.Serialize(); int row = whichProfile - 1; // -1 because 0 indexed Buffer.BlockCopy(profileData, 0, fakeEepromProfiles, row * 192, 192); #endif }
public LightingProfile ReadProfile(int whichProfile) { if (!connectionEstablished) { throw new NoKeypadConnectedException("Error: Trying to call serial interface method ReadProfile before connection is established"); } if ((whichProfile >= 1 && whichProfile <= 5) == false) { throw new ArgumentException("Profile must be in range [1,5]"); } #if KP keypadPort.WriteLine("read profile"); Ack(); keypadPort.WriteLine(whichProfile.ToString()); Ack(); var profileData = new byte[192]; keypadPort.Read(profileData, 0, 192); return(LightingProfile.Deserialize(profileData)); #else byte[] profileData = new byte[192]; int row = whichProfile - 1; // -1 because 0 indexed Buffer.BlockCopy(fakeEepromProfiles, row * 192, profileData, 0, 192); return(LightingProfile.Deserialize(profileData)); // -1 because 0 indexed #endif }