protected static int Set16(string i2Cbusid, string deviceaddress, string dataaddress, string datavalue, int force) { var value = (UInt16)Convert.ToInt16(datavalue, 16); var add1 = (UInt16)Convert.ToInt16(dataaddress, 16); var add2 = ++add1; var msb = GetAsHexString(value >> 8); var lsb = GetAsHexString(value & 0xFF); Console.WriteLine("16-bit: Writing 16-bit Value: {0} as 2 8-bit values {1} and {2}", GetAsHexString(value), msb, lsb); Console.WriteLine("16-bit: Writing {0} to address {1}", msb, GetAsHexString(add1)); var data = I2CNativeLib.Set(i2Cbusid, deviceaddress, GetAsHexString(add1), msb, force); //set msb byte/8 bits Console.WriteLine("16-bit: Response to msb: {0}", data); Console.WriteLine("16-bit: Writing {0} to address {1}", lsb, GetAsHexString(add2)); data |= I2CNativeLib.Set(i2Cbusid, deviceaddress, GetAsHexString(add2), lsb, force); //set lsb byte/8 bits Console.WriteLine("16-bit: Response to msb |= lsb: {0}", data); return(data); }
protected static byte Set8(string i2Cbusid, string deviceaddress, string dataaddress, string datavalue, int force) { Console.WriteLine("8-bit: Writing {0} to address {1}", datavalue, dataaddress); //8-bit return((byte)I2CNativeLib.Set(i2Cbusid, deviceaddress, dataaddress, datavalue, force)); }