Beispiel #1
0
        public static int PollModuleForResponse(int addr, ref byte[] bfrRecv)
        {
            var m = new I2CManager();

            bfrRecv[0] = 0xCC;
            int iCnt = 0;
            int fd   = GetFDFromAddress(addr);

            Console.WriteLine(string.Format("PollModuleForResponse : File descriptor : {0}", fd));
            while ((bfrRecv[0] == 0xCC) && iCnt < 80) // 80x50ms = 4s timeout
            {
                int retVal = m.I2CReadBlock(fd, ref bfrRecv);
                //int retVal = m.I2CReadBlockAddr(addr, ref bfrRecv);

                PrintBuffer(bfrRecv, "PollModuleForResponse");

                if (bfrRecv[0] == 0xCC)
                {
                    // No data, waiting 50ms to retry.
                    System.Threading.Thread.Sleep(50);
                }

                iCnt++;
            }

            if (bfrRecv[0] == 0xCC)
            {
                return(0);
            }
            else
            {
                return(-1);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Polls a module for response.
        /// </summary>
        /// <param name="addr">Address of the module.</param>
        /// <param name="bfrRecv">Buffer with received data after method returns.</param>
        /// <returns>Status of communication. True if response is valid, false otherwise.</returns>
        protected virtual bool PollModuleForResponse(int addr, ref byte[] bfrRecv)
        {
            var m = new I2CManager();

            bfrRecv[0] = 0xCC;
            int iCnt = 0;

            System.Threading.Thread.Sleep(10); // Needed on RPi3 because it was too fast
            int fd = GetFDFromAddress(addr);

            while ((bfrRecv[0] == 0xCC) && iCnt < 80) // 80x50ms = 4s timeout
            {
                int retVal = m.I2CReadBlock(fd, ref bfrRecv);

                if (bfrRecv[0] == 0xCC)
                {
                    // No data, waiting 50ms to retry.
                    System.Threading.Thread.Sleep(50);
                }

                iCnt++;
            }

            LogBuffer(bfrRecv, "I2C data recv");

            return(bfrRecv[0] != 0xCC);
        }