Exemplo n.º 1
0
        public static bool DiolanRead(string device, byte[] tbuffer)
        {
            DiolanU2C.m_Subtype = -1;
            for (int index = 0; index < DiolanU2C.sm_EepromTypes.Length; ++index)
            {
                if (DiolanU2C.sm_EepromTypes[index].m_Name == device.ToUpper())
                {
                    DiolanU2C.m_Subtype = index;
                    break;
                }
            }
            if (DiolanU2C.m_Subtype == -1)
            {
                return(false);
            }
            int num1 = 0;

            num1 = DiolanU2C.U2C_SetI2cFreq(DiolanU2C.hDiolan, (byte)1);
            DiolanU2C.U2C_TRANSACTION u2CTransaction = new DiolanU2C.U2C_TRANSACTION();
            u2CTransaction.Buffer = new byte[256];
            u2CTransaction.nSlaveDeviceAddress  = DiolanU2C.addrSlave;
            u2CTransaction.nMemoryAddressLength = (byte)2;
            ushort num2;

            for (int index = 0; index < tbuffer.Length; index += (int)num2)
            {
                num2 = DiolanU2C.sm_EepromTypes[DiolanU2C.m_Subtype].m_PageSize;
                if (index + (int)num2 > tbuffer.Length)
                {
                    num2 = (ushort)(tbuffer.Length - index);
                }
                u2CTransaction.nBufferLength.bLo = (byte)num2;
                DiolanU2C.prSetAddress(ref u2CTransaction, index);
                if (DiolanU2C.U2C_Read(DiolanU2C.hDiolan, ref u2CTransaction) != 0)
                {
                    return(false);
                }
                if (index <= tbuffer.Length - (int)num2)
                {
                    Array.Copy((Array)u2CTransaction.Buffer, 0, (Array)tbuffer, index, (int)num2);
                }
                else
                {
                    Array.Copy((Array)u2CTransaction.Buffer, 0, (Array)tbuffer, index, tbuffer.Length - index);
                }
            }
            return(true);
        }