示例#1
0
        public bool ReadPin(int number)
        {
            Write(I2CcommandBuilder.ReadGPIOCommand());
            byte[] rval = new byte[(int)I2CCommands.MAX];
            var    err  = reader.Read(rval, 0, rval.Length, I2CTimeout, out int transferLength);

            if (err != ErrorCode.Ok || transferLength != 1)
            {
                throw new ReadException(err);
            }
            return((rval[0] & (1 << number)) != 0);
        }
示例#2
0
        /// <summary>
        /// Read single byte from slave, send NAK
        /// </summary>
        /// <returns>Byte from slave</returns>
        public byte ReadByteNak()
        {
            byte[] r            = new byte[1];
            var    read_command = I2CcommandBuilder.ReadCommandNAK();

            Write(read_command);
            var err = reader.Read(r, 0, 1, I2CTimeout, out int transferLength);

            if (err != ErrorCode.Ok || transferLength != 1)
            {
                throw new ReadException(err);
            }
            return(r[0]);
        }
示例#3
0
 /// <summary>
 /// Use the single byte write style to get an ack bit from writing to an address with no commands.
 /// </summary>
 /// <returns></returns>
 public bool I2C_Detect(int i2c_addr)
 {
     Write(I2CcommandBuilder.DetectCommand(i2c_addr));
     return(IsAck());
 }
示例#4
0
 /// <summary>
 /// Write a byte and return the ack bit
 /// </summary>
 /// <param name="bb">byte to write</param>
 /// <returns>true for ack, false for nak</returns>
 public bool WriteByteCheckAck(byte bb)
 {
     Write(I2CcommandBuilder.WriteByteCommand(bb));
     return(IsAck());
 }
示例#5
0
        /// <summary>
        /// Set the i2c speed desired
        /// </summary>
        /// <param name="speed_khz">speed: in khz, will round down to 20, 100, 400, 750
        /// 750 is closer to 1000 for bytes, but slower around acks and each byte start.
        /// </param>
        public void SetSpeed(uint speed_khz = 100)
        {
            var command = I2CcommandBuilder.SetSpeedCommand(speed_khz);

            Write(command);
        }