Example #1
0
        private int writeBytes(byte SlaveAddr, int writeSize, int startAddress, int ClkValue, byte[] writeBuffer)
        {
            int writeBufferLength = writeBuffer.Length;
            int writeTimes        = writeBufferLength / writeSize;

            int writeMod = writeBufferLength % writeSize;

            if (writeMod > 0)
            {
                writeTimes = writeTimes + 1;
            }

            int writeCount = 0;

            for (int i = 0; i < writeTimes; i++)
            {
                GYI2C_DATA_INFO pDataInfo = new GYI2C_DATA_INFO();
                pDataInfo.IoData     = IoData;
                pDataInfo.IoSel      = IoSel;
                pDataInfo.SlaveAddr  = SlaveAddr;
                pDataInfo.Databuffer = new byte[520];
                pDataInfo.Reserved   = new byte[4] {
                    0, 0, 0, 0
                };
                pDataInfo.Databuffer[0] = (byte)(i * writeSize + startAddress);

                int writeLength = (writeSize < writeBufferLength - i * writeSize) ? writeSize : writeBufferLength - i * writeSize;
                for (int j = 0; j < writeLength; j++)
                {
                    pDataInfo.Databuffer[j + 1] = writeBuffer[i * writeSize + j];
                }
                pDataInfo.ReadNum   = 0;
                pDataInfo.DlyMsRead = 10 * (writeSize + 20) / ClkValue;    //留一点余量
                pDataInfo.WriteNum  = writeLength + 1;
                int len = VCI_GYI2C.GYI2C_Write(deviceType, deviceInd, ref pDataInfo);
                writeCount = writeCount + len;
                if (len != 1)
                {
                    break;
                }
            }

            return(writeCount);
        }
Example #2
0
        private int readBytes(byte SlaveAddr, int readSize, int startAddress, int ClkValue, ref byte[] readBuffer)
        {
            GYI2C_DATA_INFO pDataInfo = new GYI2C_DATA_INFO();

            pDataInfo.IoData     = IoData;
            pDataInfo.IoSel      = IoSel;
            pDataInfo.SlaveAddr  = SlaveAddr;
            pDataInfo.Databuffer = new byte[520];

            pDataInfo.Databuffer[0] = (byte)startAddress;
            pDataInfo.ReadNum       = readSize;
            pDataInfo.DlyMsRead     = 10 / ClkValue * (pDataInfo.ReadNum + 20); //留一点余量
            pDataInfo.WriteNum      = 1;

            int len = VCI_GYI2C.GYI2C_Read(deviceType, deviceInd, ref pDataInfo);

            if (len > 0)
            {
                Array.Copy(pDataInfo.Databuffer, readBuffer, len);
            }
            return(len);
        }
Example #3
0
 private static extern int GYI2C_GetIO(int DeviceType, int DeviceInd, ref GYI2C_DATA_INFO pDataInfo);