예제 #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);
        }
예제 #2
0
        public static bool DLN2WriteByte(byte slaveaddr, int addr, byte val, byte addrmode)
        {
            DiolanU2C.DLN2_TRANSACTION dlN2Transaction = new DiolanU2C.DLN2_TRANSACTION();
            dlN2Transaction.Buffer    = new byte[256];
            dlN2Transaction.Buffer[0] = val;
            ushort num = 1;

            dlN2Transaction.nBufferLength        = num;
            dlN2Transaction.nSlaveDeviceAddress  = slaveaddr;
            dlN2Transaction.nMemoryAddressLength = addrmode;
            byte[] bytes = BitConverter.GetBytes(addr);
            dlN2Transaction.nMemoryAddress = (uint)((int)bytes[3] << 24 | (int)bytes[2] << 16 | (int)bytes[1] << 8) | (uint)bytes[0];
            DiolanU2C.DlnI2cMasterWrite(DiolanU2C.hDLN2, 0U, dlN2Transaction.nSlaveDeviceAddress, dlN2Transaction.nMemoryAddressLength, dlN2Transaction.nMemoryAddress, dlN2Transaction.nBufferLength, dlN2Transaction.Buffer);
            Thread.Sleep(30);
            return(true);
        }
예제 #3
0
        private static bool prDLN2SetAddress(ref DiolanU2C.DLN2_TRANSACTION Transaction, int Addr)
        {
            if ((long)Addr > (long)DiolanU2C.sm_EepromTypes[DiolanU2C.m_Subtype].m_Size)
            {
                return(false);
            }
            Transaction.nMemoryAddressLength = DiolanU2C.sm_EepromTypes[DiolanU2C.m_Subtype].m_AddrByteNum;
            int num = (int)DiolanU2C.sm_EepromTypes[DiolanU2C.m_Subtype].m_AddrByteNum * 8;

            if ((int)DiolanU2C.sm_EepromTypes[DiolanU2C.m_Subtype].m_AddrBitNum <= num)
            {
                Transaction.nSlaveDeviceAddress = DiolanU2C.addrSlave;
                byte[] bytes = BitConverter.GetBytes(Addr);
                Transaction.nMemoryAddress = (uint)((int)bytes[3] << 24 | (int)bytes[2] << 16 | (int)bytes[1] << 8) | (uint)bytes[0];
            }
            return(true);
        }