Пример #1
0
        public static bool DLN2Write(string device, byte[] tbuffer, byte nMemoryAddrLength)
        {
            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);
            }
            DiolanU2C.DLN2_TRANSACTION Transaction = new DiolanU2C.DLN2_TRANSACTION();
            Transaction.Buffer = new byte[256];
            Transaction.nSlaveDeviceAddress  = DiolanU2C.addrSlave;
            Transaction.nMemoryAddressLength = nMemoryAddrLength;
            ushort num;

            for (int index = 0; index < tbuffer.Length; index += (int)num)
            {
                if (nMemoryAddrLength == (byte)1)
                {
                    byte[] bytes = BitConverter.GetBytes(index);
                    Transaction.nMemoryAddress = (uint)((int)bytes[3] << 24 | (int)bytes[2] << 16 | (int)bytes[1] << 8) | (uint)bytes[0];
                }
                num = DiolanU2C.sm_EepromTypes[DiolanU2C.m_Subtype].m_PageSize;
                if (index + (int)num > tbuffer.Length)
                {
                    num = (ushort)(tbuffer.Length - index);
                }
                Transaction.nBufferLength = (ushort)((uint)num & (uint)byte.MaxValue);
                DiolanU2C.prDLN2SetAddress(ref Transaction, index);
                if (index <= tbuffer.Length - (int)num)
                {
                    Array.Copy((Array)tbuffer, index, (Array)Transaction.Buffer, 0, (int)num);
                }
                else
                {
                    Array.Copy((Array)tbuffer, index, (Array)Transaction.Buffer, 0, tbuffer.Length - index);
                }
                DiolanU2C.DlnI2cMasterWrite(DiolanU2C.hDLN2, 0U, Transaction.nSlaveDeviceAddress, Transaction.nMemoryAddressLength, Transaction.nMemoryAddress, Transaction.nBufferLength, Transaction.Buffer);
                Thread.Sleep(30);
            }
            return(true);
        }