예제 #1
0
        public static bool DiolanWrite(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 (index <= tbuffer.Length - (int)num2)
                {
                    Array.Copy((Array)tbuffer, index, (Array)u2CTransaction.Buffer, 0, (int)num2);
                }
                else
                {
                    Array.Copy((Array)tbuffer, index, (Array)u2CTransaction.Buffer, 0, tbuffer.Length - index);
                }
                if (DiolanU2C.U2C_Write(DiolanU2C.hDiolan, ref u2CTransaction) != 0)
                {
                    return(false);
                }
                Thread.Sleep(30);
            }
            return(true);
        }